public async Task <IActionResult> SendResetPasswordLink([FromBody] ResetPasswordLinkModel model)
        {
            try
            {
                var resetPasswordToken = await _authenticateService.CreateResetPasswordTokenAsync(model.Email);

                var token = new Token {
                    Email = model.Email, Hash = resetPasswordToken
                };
                var tokenJson       = JsonConvert.SerializeObject(token);
                var tokenJsonBytes  = Encoding.UTF8.GetBytes(tokenJson);
                var tokenJsonBase64 = Base64UrlTextEncoder.Encode(tokenJsonBytes);

                var resetPasswordLink = $"{model.RedirectUrl}?token={tokenJsonBase64}";
                _backgroundJobClient.Enqueue <SendEmailJob>(x => x.SendResetPasswordLinkEmail(model.Email, resetPasswordLink));

                var response = new Response {
                    Status = 200, Message = "Account password reset link was sent to you email address."
                };
                return(Ok(response));
            }
            catch (InvalidUserException e)
            {
                return(Ok(new Response {
                    Status = 403, Message = e.Message
                }));
            }
            catch
            {
                return(Ok(new Response {
                    Status = 500, Message = "Internal Server Error."
                }));
            }
        }
示例#2
0
        public Response <ResetPasswordCheckerModel> CheckRestPasswordLink(ResetPasswordLinkModel _)
        {
            var user = _repository.GetUsersWithCriteria(u => u.ResetPasswordToken == _.Identifier).FirstOrDefault();

            if (user != null)
            {
                var hash = HashHelper.GetSha256FromString(user.ID + " " + user.Account);

                if (!hash.Equals(_.Hash))
                {
                    return(new Response <ResetPasswordCheckerModel>(PublicResultStatusCodes.Done, new ResetPasswordCheckerModel()));
                }

                var result = new ResetPasswordCheckerModel();
                result.IsValid = true;
                result.Id      = user.ID;

                var returnHash = HashHelper.GetSha256FromString(user.Account + " " + user.ID + "$aa$" + user.EntryDate);
                result.Hash = returnHash;

                return(new Response <ResetPasswordCheckerModel>(PublicResultStatusCodes.Done, result));
            }
            return(new Response <ResetPasswordCheckerModel>(PublicResultStatusCodes.Done, new ResetPasswordCheckerModel()));
        }
示例#3
0
 public IActionResult ResetPasswordLinkCheck([FromBody] ResetPasswordLinkModel _) => Ok(_userService.CheckRestPasswordLink(_));