Beispiel #1
0
        public async Task<IActionResult> ResetPassword(Person uEmail)
        {
            // sending person in as an object but all we need it the email
            // this is done so middleware doesn't try to url decode it for it to
            // handle + signs in email addresses correctly
            Console.WriteLine($"User Email {uEmail.Email}" );

            // Find user in database
            var user = await _personRepository.GetPersonByEmailAsync(uEmail.Email);
            if (user == null)
            {
                return Ok("User was not found");
            }

            user.ChangePassword = "******";
            user.PasswordExpiration = DateTime.UtcNow.ToString();

            // Generate and hash temp password, send plain text password
            var pwStr = _tokenClass.GetRandomStr();
            user.HashedPassword = _tokenClass.HashString(pwStr);

            var success = await _personRepository.UpdatePersonAsync(user);
            var passwordExpirationDate = _tokenClass.GetPasswordExpirationDate();

            if (success)
            {
                var resetPasswordBody = _emailHelper.ResetPasswordBody(user, pwStr, passwordExpirationDate);
                bool emailResponse = await _emailHelper.SendEmail(user.Name, user.Email, resetPasswordBody, 
                    _emailHelper.ResetPasswordSubject());
            }

            Console.WriteLine($"success {success}" );
            return Ok(success);
        }