示例#1
0
 public void SaveUserSecQuestions(int userid, SecurityQuestionViewModel securityQuesionModel)
 {
     userSecQuestionRepository.SaveUserSecQuestions(userid, securityQuesionModel);
     unitOfWork.Save();
 }
 public ActionResult RegisterConfirm(SecurityQuestionViewModel model)
 {
     lookupMgr.GetAllSecurityQuestions().ToList()
         .ForEach(p => model.QuestionList.Add(new SelectListItem() { Text = p.SecurityQuestionDescription, Value = p.SecurityQuestionID.ToString() }));
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     else
     {
         string userToken = Url.RequestContext.RouteData.Values["id"].ToString();
         // get user name from user token
         var userId = accountMgr.GetUserIdByToken(userToken);
         if (!userId.HasValue)
             return RedirectToAction("SingleMessage", new { message = "Your url is wrong." });
         var user = accountMgr.GetUserById(userId.Value);
         if (webSecurity.IsConfirmed(user.UserName))
             return RedirectToAction("SingleMessage", new { message = "You finished registration confirmation already." });
         // model.Username = user.UserName;
         if (webSecurity.ConfirmAccount(userToken))
         {
             // save security question answers
             accountMgr.SaveUserSecQuestions(userId.Value, model);
             //return RedirectToAction("SingleMessage", new { message = "Registration complete!" });
             return RedirectToAction("SingleMessageWithButton", new
             {
                 message = "Registration complete!",
                 strController = "Account",
                 strAction = "Login",
                 strButton = "Go to login"
             });
         }
         else
         {
             //return RedirectToAction("SingleMessage", new { message = "Registration failed." });
             return RedirectToAction("SingleMessageWithButton", new
             {
                 message = "Registration failed.",
                 strController = "Account",
                 strAction = "Login",
                 strButton = "Go to login"
             });
         }
     }
 }
 public ActionResult RetrievePassword(SecurityQuestionViewModel model)
 {
     model.IsAnswerStep = false;
     lookupMgr.GetAllSecurityQuestions().ToList()
         .ForEach(p => model.QuestionList.Add(new SelectListItem() { Text = p.SecurityQuestionDescription, Value = p.SecurityQuestionID.ToString() }));
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     else
     {
         if (model.FirstAnswer.Equals(model.UserAnswer1)
              && model.SecondAnswer.Equals(model.UserAnswer2)
              && model.ThirdAnswer.Equals(model.UserAnswer3))
         {
             // reset password token expires in 2 days
             string resetPasswordToken = webSecurity.GeneratePasswordResetToken(model.UserName, 2880);
             string resetLink = this.Url.RouteUrl("ResetPwdRoute", new { controller = "Account", action = "ResetPassword", id = resetPasswordToken, usr = model.UserName }, this.Request.Url.Scheme);
             var emailMgr = new EmailManager();
             emailMgr.SendResetPasswordEmail(model.UserName, resetLink);
             //return RedirectToAction("SingleMessage", new { message = "An Email is sent to your account to reset your password." });
             return RedirectToAction("SingleMessageWithButton", new
             {
                 message = "An Email is sent to your account to reset your password.",
                 strController = "Account",
                 strAction = "Login",
                 strButton = "Go to login"
             });
         }
         else
         {
             ViewBag.Message = "One or more answers are incorrect."; 
             return View(model);
         }
     }
 }
 public ActionResult RegisterConfirm()
 {
     if(!Url.RequestContext.RouteData.Values.ContainsKey("id"))
         return RedirectToAction("SingleMessage", new { message = "Your are not allowed to access this page." });
     string userToken = Url.RequestContext.RouteData.Values["id"].ToString();
     var model = new SecurityQuestionViewModel();
     lookupMgr.GetAllSecurityQuestions().ToList()
         .ForEach(p => model.QuestionList.Add(new SelectListItem() { Text = p.SecurityQuestionDescription, Value = p.SecurityQuestionID.ToString() }));
     // if user token empty, then it is from first register confirm when user hasn't entered answers yet
     if (string.IsNullOrEmpty(userToken))
     {            
         ModelState.AddModelError("", "User tried to access register confirmation page without token");
         return RedirectToAction("SingleMessage", new { message = "Your are not allowed to access this page." });
     }            
     return View(model);
 }