public virtual ActionResult ShowSuspensionStatus() { var u = Membership.GetUser(); var db = Current.DB; if (!(AccountProfile.GetProfileOfUser(u.UserName).ReinstateDate < DateTime.Now)) { var suspension = db.UserSuspensions.Where(s => s.UserID == (Guid)u.ProviderUserKey).OrderByDescending(k => k.ReinstateDate).Take(1).ToList()[0]; return(View(suspension)); } return(RedirectToAction("Index", "Home")); }
public void FillProperties() { var profile = AccountProfile.GetProfileOfUser(this.aspnet_User.UserName); // the matched user FullName = profile.FullName; Grade = profile.Grade; // What sex is the current user? bool selectedSex = false; // male if (AccountProfile.CurrentUser.Sex == 2) { selectedSex = true; // female } // All school for whatever gender you are var allSchoolYourGender = this.aspnet_User.Matches1.Where(m => m.MatchedSex == selectedSex).OrderByDescending(m => m.CompatibilityIndex); // get their list // Figure out your position var result = allSchoolYourGender .Select((x, i) => new { Item = x, Index = i }) .Where(itemWithIndex => itemWithIndex.Item.MatchedUser == Current.UserID.Value) .FirstOrDefault(); int index = -1; if (result != null) { index = result.Index + 1; // index is zero-based, but we want to present list as starting with index 1. } PositionOnTheirListAllSchool = index; if (!this.AreSameGrade) { PositionOnTheirListYourGrade = -1; } else { // Your grade for whatever gender you are var yourGradeYourGender = this.aspnet_User.Matches1.Where(m => m.MatchedSex == selectedSex && m.AreSameGrade == true).OrderByDescending(m => m.CompatibilityIndex); // Figure out your position var resultG = allSchoolYourGender .Select((x, i) => new { Item = x, Index = i }) .Where(itemWithIndex => itemWithIndex.Item.MatchedUser == Current.UserID.Value) .FirstOrDefault(); int indexG = -1; if (resultG != null) { indexG = resultG.Index + 1; // index is zero-based, but we want to present list as starting with index 1. } PositionOnTheirListYourGrade = indexG; } }
public virtual ActionResult SuspendUser(SuspendUserViewModel model) { var sus = new UserSuspension(); var db = Current.DB; var username = Membership.GetUser(model.UserID, false).UserName; sus = new UserSuspension() { SuspensionDate = DateTime.Now, Reason = model.Reason, UserID = model.UserID }; if (model.ReinstateDate == null) { sus.ReinstateDate = DateTime.MaxValue; } db.UserSuspensions.InsertOnSubmit(sus); db.SubmitChanges(); AccountProfile.GetProfileOfUser(username).ReinstateDate = sus.ReinstateDate; AccountProfile.GetProfileOfUser(username).Save(); return(RedirectToAction("Index")); }
public virtual ActionResult Authenticate(string returnUrl) { var db = Current.DB; if (Request.Form["OneTimeSignupCode"].HasValue()) { Session["OneTimeSignupCode"] = Request.Form["OneTimeSignupCode"]; } IAuthenticationResponse response = openid.GetResponse(); OneTimeRegistrationCode recordcopy = null; if (response == null) { // Stage 2: user submitting Identifier Identifier id; if (Identifier.TryParse(Request.Form["openid_identifier"], out id)) { if (WhiteListEnabled) { if (Request.Form["OneTimeSignupCode"].HasValue()) { var record = db.OneTimeRegistrationCodes.Where(c => c.Id.ToString() == Request.Form["OneTimeSignupCode"]).SingleOrDefault(); if (record == null) { //not allowed in Current.Context.Response.StatusCode = (int)HttpStatusCode.Forbidden; return(View("WhiteListBlock")); } } } try { IAuthenticationRequest request = openid.CreateRequest(Request.Form["openid_identifier"]); request.AddExtension(new ClaimsRequest { Email = DemandLevel.Require, Nickname = DemandLevel.Request, FullName = DemandLevel.Request, BirthDate = DemandLevel.Request }); return(request.RedirectingResponse.AsActionResult()); } catch (ProtocolException ex) { ViewData["Message"] = ex.Message; if (Request.Form["OneTimeSignupCode"].HasValue()) { ViewData["OneTimeSignupCode"] = Request.Form["OneTimeSignupCode"]; } return(View("OpenidLogin")); } } else { ViewData["Message"] = "Invalid OpenID"; if (Request.Form["OneTimeSignupCode"].HasValue()) { ViewData["OneTimeSignupCode"] = Request.Form["OneTimeSignupCode"]; } return(View("OpenidLogin")); } } else { // Stage 3: OpenID Provider sending assertion response switch (response.Status) { case AuthenticationStatus.Authenticated: var sreg = response.GetExtension <ClaimsResponse>(); UserOpenId openId = null; openId = db.UserOpenIds.Where(o => o.OpenIdClaim == response.ClaimedIdentifier.OriginalString).FirstOrDefault(); object signupcode = null; if (Request.Form["OneTimeSignupCode"].HasValue()) { signupcode = Request.Form["OneTimeSignupCode"]; } else if (Session["OneTimeSignupCode"] != null) { signupcode = Session["OneTimeSignupCode"]; } if (WhiteListEnabled) { if (signupcode != null) { var record = db.OneTimeRegistrationCodes.Where(c => c.Id.ToString() == (string)signupcode).SingleOrDefault(); if (record == null) { //not allowed in try { Current.Context.Response.StatusCode = (int)HttpStatusCode.Forbidden; } catch { } return(View("WhiteListBlock")); } recordcopy = record; --record.UsesRemaining; if (record.UsesRemaining < 1) { db.OneTimeRegistrationCodes.DeleteOnSubmit(record); } db.SubmitChanges(); } //else if (db.OpenIDWhiteLists.Where(w => w.IsEnabled).Where(w => w.OpenID == response.ClaimedIdentifier.OriginalString).FirstOrDefault() == null && (sreg == null || !sreg.Email.Contains("APPROVEDOPENIDDOMAIN.com") && openId == null)) else if ((db.OpenIDWhiteLists.Where(w => w.IsEnabled).Where(w => w.OpenID == response.ClaimedIdentifier.OriginalString).FirstOrDefault() == null || sreg == null) && openId == null) // if (not-in-whitelisted-openids or no-openid-submitted) and doesn't-match-any-openid-in-the-system { //not allowed in try { Current.Context.Response.StatusCode = (int)HttpStatusCode.Forbidden; } catch { } return(View("WhiteListBlock")); } } if (openId == null) { // create new user string email = ""; string login = ""; if (sreg != null) { email = sreg.Email; var userNameAvailable = (db.aspnet_Users.Where(u => u.UserName == sreg.Nickname).FirstOrDefault()) == null; if (userNameAvailable) { login = sreg.Nickname; } } var model = new OpenIdRegistrationViewModel() { EmailAddress = email, Nickname = login, OpenIdClaim = Crypto.EncryptStringAES(response.ClaimedIdentifier.OriginalString, "OpenIDRegistrationFrenzy"), ReturnURL = Session["ReturnURL"] as string }; return(View("OpenidRegister", model)); } else { //check whether user is suspended and whether suspension has already ended var userName = openId.aspnet_User.UserName; if (!Roles.IsUserInRole(userName, RoleNames.ActiveUser)) { var currentProfile = AccountProfile.GetProfileOfUser(userName); if (DateTime.Now >= currentProfile.ReinstateDate) { Roles.AddUserToRole(userName, RoleNames.ActiveUser); currentProfile.ReinstateDate = DateTime.MinValue; currentProfile.Save(); } } FormsAuthentication.SetAuthCookie(userName, true); var URLreturn = Session["ReturnURL"]; if (URLreturn == null || !(URLreturn as string).HasValue()) { return(RedirectToAction("Index", "Home")); } return(Redirect(URLreturn as string)); } case AuthenticationStatus.Canceled: ViewData["Message"] = "Canceled at provider"; return(View("OpenidLogin")); case AuthenticationStatus.Failed: ViewData["Message"] = response.Exception.Message; return(View("OpenidLogin")); } } return(new EmptyResult()); }
public void MakeMatch(aspnet_User one, aspnet_User two) { // Compute var totalNumQuestions = db.Questions.Count(); int scoreSame = 0; foreach (var q in db.Questions) { try { var ansone = db.Responses.Where(u => u.UserId == one.UserId && u.QuestionId == q.Id).SingleOrDefault().AnswerId; var anstwo = db.Responses.Where(u => u.UserId == two.UserId && u.QuestionId == q.Id).SingleOrDefault().AnswerId; if (ansone == anstwo) { scoreSame++; } } catch (NullReferenceException e) { // If there was an error above, that means that one of them didn't answer the question because SingleOrDefault() returned null // They can't answer only some of the questions and not the rest, so we don't need to check other questions break; // keep scoreSame at 0, don't check other questions } catch { // Other exception... uh, idk. Let it continue. } } var ratio = ((double)scoreSame) / totalNumQuestions; // Add noise var noiseInt = new Random().Next(1, 10); // 1% to 10% noise if (new Random().Next(0, 1) == 1) { noiseInt *= -1; // add or subtract } double noise = (double)noiseInt / 100; if (ratio + noise > 1 || ratio + noise < 0) // we want to limit to between 0 and 1 { noise *= -1; } ratio += noise; // Get profiles var profile1 = AccountProfile.GetProfileOfUser(one.UserName); var profile2 = AccountProfile.GetProfileOfUser(two.UserName); // Write to DB var time = DateTime.Now; var m_one = new Match(); m_one.RequestUser = one.UserId; m_one.MatchedUser = two.UserId; m_one.MatchedSex = (profile2.Sex == 2); m_one.AreSameGrade = profile1.Grade == profile2.Grade; m_one.CompatibilityIndex = ratio; m_one.DateCalculated = time; db.Matches.InsertOnSubmit(m_one); var m_two = new Match(); m_two.RequestUser = two.UserId; m_two.MatchedUser = one.UserId; m_two.MatchedSex = (profile1.Sex == 2); m_two.AreSameGrade = profile1.Grade == profile2.Grade; m_two.CompatibilityIndex = ratio; m_two.DateCalculated = time; db.Matches.InsertOnSubmit(m_two); db.SubmitChanges(); }