Beispiel #1
0
        public async Task <IActionResult> ForgotPassword(EmailAdressViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _usermanager.FindByEmailAsync(model.Email);

                //如果找到了用户并确认了电子邮箱
                if (user != null && await _usermanager.IsEmailConfirmedAsync(user))
                {
                    //生成电子令牌
                    var token = await _usermanager.GeneratePasswordResetTokenAsync(user);

                    var passwordResetLink = Url.Action("ResetPassword", "Account", new { email = model.Email, token = token }, Request.Scheme);

                    _logger.Log(LogLevel.Warning, passwordResetLink);

                    return(View("ForgotPasswordConfirmation"));
                }
            }
            return(View(model));
        }
Beispiel #2
0
        public async Task <IActionResult> ActivateUserEmail(EmailAdressViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _usermanager.FindByEmailAsync(model.Email);

                if (user != null)
                {
                    if (!await _usermanager.IsEmailConfirmedAsync(user))
                    {
                        var token = await _usermanager.GenerateEmailConfirmationTokenAsync(user);

                        var confirmationLink = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, token = token }, Request.Scheme);
                        _logger.Log(LogLevel.Warning, confirmationLink);


                        ViewBag.Message = "如果您在我们系统有注册账户,我们已经发了邮件到您的邮箱中,请前往邮箱激活您的账户!";
                        return(View("ActivateUserEmailConfirmation", ViewBag.Message));
                    }
                }
            }
            ViewBag.Message = "请确认邮箱是否存在异常,现在我们无法给您发送激活链接。";
            return(View("ActivateUserEmailConfirmation", ViewBag.Message));
        }