Example #1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (!_authRepository.AlreadyExists(model.Email))
                {
                    // Try and send the confirmation email first. If that works, and the email is valid, then add it here.

                    var result = _authRepository.Register(model.Email, model.Password);
                    if (result.Success)
                    {
                        // Generate an email confirmation token for this account
                        var token = AuthEncryption.RandomSalt(6);
                        result = _authRepository.SetEmailConfirmationToken(model.Email, token);
                        var secureUrl = Url.Action("ConfirmEmail", "Account", new { e = model.Email, c = token }, "https");

                        string mailBody = MailCommonStrings.RegisteredBody(secureUrl);
                        Mailer.SendEmail_NoWait(model.Email, MailCommonStrings.RegisteredSubject, mailBody);
                        _logger.Debug($"{model.Email} has successfully registered an account from {ClientIpAddress.GetIPAddress(Request)}");

                        MvcCaptcha.ResetCaptcha("regoCaptcha");
                        return(RedirectToAction("ConfirmationRequired"));
                    }

                    ModelState.AddModelError("", result.Message);
                }
                else
                {
                    ModelState.AddModelError("", "An account with this email address already exists!");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Example #2
0
        public ActionResult Reverify(ReverifyViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (_authRepository.AlreadyExists(model.Email))
                {
                    var token     = AuthEncryption.RandomSalt(6);
                    var result    = _authRepository.SetEmailConfirmationToken(model.Email, token);
                    var secureUrl = Url.Action("ConfirmEmail", "Account", new { e = model.Email, c = token }, "https");
                    //var linkUrl = Url.AbsoluteAction("ConfirmEmail", "Account", new { e = model.Email, c = token });
                    string mailBody = MailCommonStrings.RegisteredBody(secureUrl);
                    Mailer.SendEmail_NoWait(model.Email, MailCommonStrings.RegisteredSubject, mailBody);
                    _logger.Debug(string.Format("{0} has requested another verification email from {1}", model.Email, ClientIpAddress.GetIPAddress(Request)));
                }
                MvcCaptcha.ResetCaptcha("ReverifyCaptcha");
                return(RedirectToAction("ReverificationSent"));
            }

            return(View());
        }
Example #3
0
        public ActionResult ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (_authRepository.AlreadyExists(model.Email))
                {
                    var token     = AuthEncryption.RandomSalt(6);
                    var result    = _authRepository.SetPasswordResetToken(model.Email, token);
                    var userIp    = ClientIpAddress.GetIPAddress(Request);
                    var secureUrl = Url.Action("TryResetPassword", "Account", new { e = model.Email, c = token }, "https");
                    //var linkUrl = Url.AbsoluteAction("TryResetPassword", "Account", new { e = model.Email, c = token });
                    string mailBody = MailCommonStrings.PasswordResetBody(userIp, secureUrl);
                    Mailer.SendEmail_NoWait(model.Email, MailCommonStrings.ResetPasswordSubject, mailBody);
                    _logger.Debug(string.Format("{0} has requested to reset their password from {1}", model.Email, ClientIpAddress.GetIPAddress(Request)));
                }
                MvcCaptcha.ResetCaptcha("ResetPasswordCaptcha");
                return(RedirectToAction("PasswordResetSent"));
            }

            return(View());
        }