public ActionResult Register(RegisteredUser newUser) { CaptchaHelper captchaHelper = new CaptchaHelper(); string captchaResponse = captchaHelper.CheckRecaptcha(); if (captchaResponse != "Valid") { ViewBag.ErrorResponse = "The captcha must be valid"; return View(); } var userStore = new UserStore<IdentityUser>(); UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore) { UserLockoutEnabledByDefault = true, DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0), MaxFailedAccessAttemptsBeforeLockout = 3 }; var identityUser = new IdentityUser() { UserName = newUser.UserName, Email = newUser.Email }; IdentityResult result = manager.Create(identityUser, newUser.Password); if (result.Succeeded) { if (newUser.UserRole.Equals("Buyer") || newUser.UserRole.Equals("Farm")) { //Taking the username on the account successful creation and applying it to the //Farm database to create a Farm table with that username under the 'farmName' field. AccountRepo accountRepo = new AccountRepo(); accountRepo.InitializeUserAccount(newUser); } var authenticationManager = HttpContext.Request.GetOwinContext().Authentication; var userIdentity = manager.CreateIdentity(identityUser, DefaultAuthenticationTypes.ApplicationCookie); authenticationManager.SignIn(new AuthenticationProperties() { }, userIdentity); string testVariable = newUser.UserRole; AddUserToRole(newUser.UserName, newUser.UserRole); CreateTokenProvider(manager, EMAIL_CONFIRMATION); var code = manager.GenerateEmailConfirmationToken(identityUser.Id); var callbackUrl = Url.Action("ConfirmEmail", "Home", new { userId = identityUser.Id, code = code }, protocol: Request.Url.Scheme); string emailMessage = "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">Confirm Registration</a>"; string response = new MailHelper().EmailFromArvixe(new ViewModels.Message(newUser.Email, emailMessage)); ViewBag.ConfirmationResponse = response; TempData["ConfirmationResponse"] = "You have successfully registered for an account. Please verify your account by clicking on the link sent to you in your e-mail."; return RedirectToAction("Login"); } ViewBag.ErrorResponse = "There was an error with the input provided"; return View(); }
public ActionResult ForgotPassword(string email) { var userStore = new UserStore<IdentityUser>(); UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore); var user = manager.FindByEmail(email); CreateTokenProvider(manager, PASSWORD_RESET); if (user != null) { var code = manager.GeneratePasswordResetToken(user.Id); string callbackUrl = Url.Action("ResetPassword", "Home", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); string emailMessage = "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"; string response = new MailHelper().EmailFromArvixe(new ViewModels.Message(email, emailMessage)); ViewBag.FakeEmailMessage = "Email successfully sent. Please check your email to reset your password"; return View(); } ViewBag.Error = "There wasn't an account for that email"; return View(); }