public ActionResult VerifyEmail() { try { int uid = 0; Int32.TryParse(TempData["ActivationEmailUserId"]?.ToString(), out uid); if (uid == 0) { return(HttpNotFound()); } RequiredActionModel _raModel = new RequiredActionModel { Title = "Email pending verification", Controller = "Account", Action = "VerifyEmail", Content = "Your email has not been verified yet, please check your registered email to verify.", FormMethod = FormMethod.Post, SubmitButtonDescription = "Resend email verification", Data = uid, DataName = "uid" }; return(View("RequiredAction", _raModel)); } catch (Exception ex) { Log.Error(ex.Message, ex); return(View("Error")); } }
public ActionResult Activation(string token) { try { if (!token.IsNullOrEmpty()) { //check if activation is exist if (_userService.IsValidToken(token, EAccessTokenPurpose.VerifyEmail) != null) { _userService.ActivateUserAccount(token); RequiredActionModel _raModel = new RequiredActionModel { Controller = "Account", Action = "Login", FormMethod = FormMethod.Get, SubmitButtonDescription = "Login to your account", }; _raModel.Title = "Email successfully verified."; return(View("RequiredAction", _raModel)); } else { //RequiredActionModel _raModel = new RequiredActionModel //{ // Controller = "Account", // Action = "Login", // FormMethod = FormMethod.Get, // SubmitButtonDescription = "Login", //}; //_raModel.Title = "Invalid Verification Request"; //_raModel.Content = "Verification link or code is not valid, either has been removed or expired. Please log in to your account to request another email verification code."; //return View("RequiredAction", _raModel); } } } catch (Exception ex) { Log.Error(ex.Message, ex); return(new HttpStatusCodeResult(500)); } return(new HttpNotFoundResult()); }
public ActionResult ResetPassword(ResetPasswordViewModel model) { //add password reset model here. add password field for new password. try { if (ModelState.IsValid) { if (!model.Token.IsNullOrEmpty()) { //check if activation is exist if (_userService.IsValidToken(model.Token, EAccessTokenPurpose.ResetPassword) != null) { _userService.ResetPassword(model.Token, model.Password); RequiredActionModel _raModel = new RequiredActionModel { Controller = "Account", Action = "Login", FormMethod = FormMethod.Get, SubmitButtonDescription = "Login to your account", }; _raModel.Title = "Your password has been reset."; return(RedirectToAction("ResetPasswordConfirmation")); } } } else { return(View("ResetPassword", new { id = model.Token })); } } catch (Exception ex) { Log.Error(ex.Message, ex); return(new HttpStatusCodeResult(500)); } return(new HttpNotFoundResult()); }
public ActionResult VerifyEmail(int uid) { var reqUser = _userService.GetUserBy(uid); //Check once more if account is verified //Probably someone abused here. [Check Target: User without verified yet] if (reqUser.HasEmailVerified) { RequiredActionModel _raModel2 = new RequiredActionModel { Title = "This user's email has already verified.", Controller = "Account", Action = "Login", Content = "", FormMethod = FormMethod.Get, SubmitButtonDescription = "Back", }; return(View("RequiredAction", _raModel2)); } SendActivationEmail(uid, Request); /* For registration through logged in user portal */ if (User.Identity.IsAuthenticated) { Success("Successfully registered user " + reqUser.Username + ". Verification email has been sent to account email address (" + reqUser.Email + ").", false); return(RedirectToAction("Index", "Home")); } RequiredActionModel _raModel = new RequiredActionModel { Title = "Email verification sent", Controller = "Account", Action = "Login", Content = "Email verification sent, Please check your email '" + reqUser.Email + "' to verify your email address.", FormMethod = FormMethod.Get, SubmitButtonDescription = "Login", }; return(View("RequiredAction", _raModel)); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl, bool rememberMe) { try { #if !DEBUG if (!IsRecapchaValidate()) { ModelState.AddModelError("", "Captcha is not valid. Please try again."); return(View(model)); } #endif if (await _userService.IsValid(model.Username, model.Password)) { var currentUser = _userService.GetUserBy(model.Username); var userRole = _userService.GetUserRoleBy(currentUser.UserProfile); //Verify email if (!currentUser.HasEmailVerified) { TempData["ActivationEmailUserId"] = currentUser.UserId; return(RedirectToAction("VerifyEmail")); } //Add Claims var ident = new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, currentUser.UserId.ToString()), new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity", "http://www.w3.org/2001/XMLSchema#string"), new Claim(ClaimTypes.Name, model.Username), new Claim("TimeZone", currentUser.TimeZoneId), new Claim("AcceptedTC", currentUser.HasAcceptedTerms.ToString()), new Claim("IsFirstTimeLogin", currentUser.IsFirstTimeLogIn.ToString()), new Claim(ClaimTypes.Role, userRole.Description) }, DefaultAuthenticationTypes.ApplicationCookie); HttpContext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties { IsPersistent = model.RememberMe }, ident); var isFirstTimeLogin = (currentUser.IsFirstTimeLogIn != null) ? currentUser.IsFirstTimeLogIn.Value : false; //Verify is new user if (isFirstTimeLogin) { return(RedirectToAction("Setup")); } //Verify if has pending application if (currentUser.StatusId == (int)EStatus.Pending) { RequiredActionModel _raModel = new RequiredActionModel { Title = "Account pending review", Controller = "Account", Action = "Login", Content = "Seems like your application has been submitted or existed in our system and is pending to review. Please wait while we confirm your application.", FormMethod = FormMethod.Get, SubmitButtonDescription = "Back To Login", }; return(View("RequiredAction", _raModel)); } return((userRole.Description == DBConstant.DBCRole.Admin) ? RedirectToAction("Index", "User") : RedirectToAction("Index", "Home")); } // invalid username or password ModelState.AddModelError("", "Invalid username or password"); } catch (Exception ex) { Log.Error(ex.Message, ex); } return(View()); }