コード例 #1
0
        public async ValueTask <IActionResult> Put(string code, [FromBody] PatchUnknownPasswordDTO model)
        {
            if (ModelState.IsValid)
            {
                var user = await _repo.Item().Where(u => u.Email.Equals(model.Email)).FirstOrDefaultAsync();

                if (user != null)
                {
                    if (code == user.Code && user.CodeIssued <= user.CodeWillExpire)
                    {
                        bool succeeded = await _acc.ForgotPassword(model);

                        if (succeeded)
                        {
                            return(Ok(new { succeeded }));
                        }
                    }
                    return(BadRequest(new ErrorDTO {
                        Message = "code is invalid or has expired"
                    }));
                }
                return(BadRequest(new ErrorDTO {
                    Message = "user not found"
                }));
            }
            return(BadRequest(new ErrorDTO {
                Errors = ModelState.Values.SelectMany(e => e.Errors).ToList()
            }));
        }
コード例 #2
0
        public async ValueTask <bool> ForgotPassword(PatchUnknownPasswordDTO patch)
        {
            ApplicationUser user = await GetUserByEmail(patch.Email);

            if (user != null)
            {
                if (patch.NewPassword == patch.ConfirmNewPassword)
                {
                    string passwordHash = Hash.GetHashedValue(patch.NewPassword);
                    user.PasswordHash = passwordHash;
                    return(await UpdateUser(user));
                }
            }
            return(false);
        }
コード例 #3
0
        public async ValueTask <(bool, ApplicationUser, string)> ForgotPassword(PatchUnknownPasswordDTO patch, string code)
        {
            var user = await Item().Where(u => u.Email.Equals(patch.Email)).FirstOrDefaultAsync();

            if (user != null)
            {
                if (code == user.Code && user.CodeIssued <= user.CodeWillExpire)
                {
                    string passwordHash = Hash.GetHashedValue(patch.NewPassword);
                    user.PasswordHash = passwordHash;
                    return(await Update(user));
                }
            }
            return(false, null, "user not found");;
        }
コード例 #4
0
ファイル: UserManager.cs プロジェクト: PySom/afrostock
        public async ValueTask <(bool, ApplicationUser, string)> ForgotPassword(PatchUnknownPasswordDTO patch, string code)
        {
            ApplicationUser user = await FindOne(u => u.Email.ToLower() == patch.Email.ToLower());

            if (user != null)
            {
                if (code == user.Code && user.CodeIssued <= user.CodeWillExpire)
                {
                }
                if (patch.NewPassword == patch.ConfirmNewPassword)
                {
                    string passwordHash = Hash.GetHashedValue(patch.NewPassword);
                    user.PasswordHash = passwordHash;
                    return(await Update(user));
                }
            }
            return(false, null, "user not found");;
        }
コード例 #5
0
        public async ValueTask <IActionResult> Put(string code, [FromBody] PatchUnknownPasswordDTO model)
        {
            if (ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(code))
                {
                    return(BadRequest(new { Message = "Are you normal? Code kwanu?" }));
                }
                var(succeeded, _, error) = await _acc.ForgotPassword(model, code);

                if (succeeded)
                {
                    return(Ok(new { succeeded }));
                }
                return(BadRequest(new { Message = error }));
            }
            return(BadRequest(new { Errors = ModelState.Values.SelectMany(e => e.Errors).ToList() }));
        }