Example #1
0
        public IActionResult ResetPasswordRequest([FromBody] PasswordResetRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Valid email address is required"));
            }

            ActionResponse response  = new ActionResponse();
            var            foundUser = userService.GetUserByEmail(model.Email);

            if (foundUser != null)
            {
                string adminEmail = HttpContext.RequestServices.GetRequiredService <IConfiguration>()
                                    .GetValue <String>("Email:Smtp:AdminEmail");
                string             resetPasswordUrl = configuration["ResetPasswordUrl"];
                DateTime           datedTime        = DateTime.Now;
                PasswordTokenModel tModel           = new PasswordTokenModel()
                {
                    Email     = foundUser.Email,
                    TokenDate = datedTime
                };

                TokenUtility            utility    = new TokenUtility();
                string                  token      = utility.GeneratePasswordResetToken(tModel);
                PasswordResetEmailModel resetModel = new PasswordResetEmailModel()
                {
                    Email = foundUser.Email,
                    Token = token,
                    Url   = resetPasswordUrl
                };

                response = userService.ResetPasswordRequest(resetModel, datedTime, adminEmail);
            }
            return(Ok(response));
        }