public async Task <bool> VerifyResetPasswordPINCode([FromBody] PhoneNumberResetPassword model)
        {
            if (model == null)
            {
                throw new CustomException(Errors.REQUEST_NOT_NULL, Errors.REQUEST_NOT_NULL_MSG);
            }
            else if (string.IsNullOrEmpty(model.PhoneNumber))
            {
                throw new CustomException(Errors.INVALID_PHONE_NUMBER, Errors.INVALID_PHONE_NUMBER_MSG);
            }
            else if (string.IsNullOrEmpty(model.PIN))
            {
                throw new CustomException(Errors.PIN_NOT_NULL, Errors.PIN_NOT_NULL_MSG);
            }

            return(await _verificationService.VerifyPINCodeResetPassword(model.PhoneNumber, model.PIN));
        }
        public async Task ResetPasswordByPhoneNumber([FromBody] PhoneNumberResetPassword model)
        {
            if (model == null)
            {
                throw new CustomException(Errors.REQUEST_NOT_NULL, Errors.REQUEST_NOT_NULL_MSG);
            }
            else if (string.IsNullOrEmpty(model.PhoneNumber))
            {
                throw new CustomException(Errors.INVALID_PHONE_NUMBER, Errors.INVALID_PHONE_NUMBER_MSG);
            }
            else if (string.IsNullOrEmpty(model.PIN))
            {
                throw new CustomException(Errors.PIN_NOT_NULL, Errors.PIN_NOT_NULL_MSG);
            }
            else if (string.IsNullOrEmpty(model.NewPassword))
            {
                throw new CustomException(Errors.PASSWORD_NOT_NULL, Errors.PASSWORD_NOT_NULL_MSG);
            }

            await _accountService.ResetPasswordByPhoneNumber(model);
        }
Example #3
0
        public async Task ResetPasswordByPhoneNumber(PhoneNumberResetPassword model)
        {
            string formatedPhoneNumber = PhoneNumberHelpers.GetFormatedPhoneNumber(model.PhoneNumber);
            var    account             = await CheckExsitByPhoneNumberAsync(formatedPhoneNumber);

            if (account == null)
            {
                throw new CustomException(Errors.ACCOUNT_NOT_FOUND, Errors.ACCOUNT_NOT_FOUND_MSG);
            }

            var verification = account.VerificationCodes.FirstOrDefault(t => t.SetPhoneNumber == formatedPhoneNumber && t.Purpose == VerificationPurpose.Password && t.Checked);

            if (verification == null)
            {
                throw new CustomException(Errors.PIN_NOT_VERIFY, Errors.PIN_NOT_VERIFY_MSG);
            }

            account.Password      = _pwdHasher.HashPassword(account, model.NewPassword);
            account.SecurityStamp = GenerateSecurityStamp();
            account.ModifiedAt    = DateTime.Now;

            await _context.SaveChangesAsync();
        }