Exemple #1
0
        public void CreateRequest()
        {
            // test we can successfully create a request
            var user = new User {
                Email = Email
            };

            _userRepo.Create(user);

            var res = _passwordResetService.CreatePasswordReset(Email).Result;

            Assert.Contains(res, _passwordResets.GetResets());
        }
Exemple #2
0
        public async Task <IActionResult> ResetPasswordRequest([FromBody, BindRequired] PasswordResetRequestData data)
        {
            // Find user attached to email or username.
            var emailOrUsername = data.EmailOrUsername.ToLowerInvariant();
            var user            = (await _userRepo.GetAllUsers()).SingleOrDefault(u =>
                                                                                  u.Email.ToLowerInvariant().Equals(emailOrUsername) ||
                                                                                  u.Username.ToLowerInvariant().Equals(emailOrUsername));

            if (user is null)
            {
                return(NotFound(emailOrUsername));
            }

            // Create password reset.
            var resetRequest = await _passwordResetService.CreatePasswordReset(user.Email);

            // Create email.
            var message = new MimeMessage();

            message.To.Add(new MailboxAddress(user.Name, user.Email));
            message.Subject = "Combine password reset";
            message.Body    = new TextPart("plain")
            {
                Text = string.Format("A password reset has been requested for the user {0}. Follow the link to reset "
                                     + "{0}'s password. {1}/forgot/reset/{2} \n\n If you did not request a password reset please "
                                     + "ignore this email", user.Username, data.Domain, resetRequest.Token)
            };
            if (await _emailService.SendEmail(message))
            {
                return(Ok());
            }

            return(StatusCode(StatusCodes.Status500InternalServerError));
        }