Ejemplo n.º 1
0
        public async Task ChangePassword(MemberChangePasswordView member)
        {
            var user = await _userManager.FindByIdAsync(Uow.MemberRepository.GetById(member.Id).UserId);

            if (user == null)
            {
                throw new CoralTimeEntityNotFoundException($"user with id {Uow.MemberRepository.GetById(member.Id).UserId} not found.");
            }

            if (!user.IsActive)
            {
                throw new CoralTimeEntityNotFoundException($"user with id {Uow.MemberRepository.GetById(member.Id).UserId} is not active.");
            }

            if (_isDemo)
            {
                throw new CoralTimeForbiddenException($"Password can't be changed on demo site");
            }

            var userUpdationResult = await _userManager.ChangePasswordAsync(user, member.OldPassword, member.NewPassword);

            if (!userUpdationResult.Succeeded)
            {
                CheckMembersErrors(userUpdationResult.Errors.Select(e => new IdentityErrorView
                {
                    Code        = e.Code,
                    Description = e.Description
                }));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ChangePasswordAsync(int id, [FromBody] MemberChangePasswordView member)
        {
            member.Id = id;
            await _service.ChangePassword(member);

            return(Ok());
        }
Ejemplo n.º 3
0
 [HttpPost]  //設定此Action接受頁面POST資料傳入
 public ActionResult ChangePassword(MemberChangePasswordView ChangeData)
 {
     //判斷頁面資料是否都經過驗證
     if (ModelState.IsValid)
     {
         ViewData["ChangeState"] = memberService.ChangePassword(User.Identity.Name
                                                                , ChangeData.Password, ChangeData.NewPassword);
     }
     return(View());
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> ChangePasswordAsync(int memberId, [FromBody] MemberChangePasswordView member)
        {
            member.Id = memberId;

            try
            {
                await _service.ChangePassword(member);

                return(Ok());
            }
            catch (Exception e)
            {
                _logger.LogWarning($"ChangePasswordAsync method with parameters ({memberId}, {JsonConvert.SerializeObject(member)});\n {e}");
                var errors = ExceptionsChecker.CheckMembersException(e);
                return(BadRequest(errors));
            }
        }