Beispiel #1
0
        public static async Task<bool> ChangePasswordAsync(AppUser current, ChangePassword model,
            RemoteUser user)
        {
            int userId = current.UserId;

            if (userId <= 0)
            {
                await Task.Delay(5000).ConfigureAwait(false);
                return false;
            }

            if (model.Password != model.ConfirmPassword)
            {
                return false;
            }

            string email = current.Email;
            var frapidUser = await Users.GetAsync(current.Tenant, email).ConfigureAwait(false);

            bool oldPasswordIsValid = PasswordManager.ValidateBcrypt(model.OldPassword, frapidUser.Password);
            if (!oldPasswordIsValid)
            {
                await Task.Delay(2000).ConfigureAwait(false);
                return false;
            }

            string newPassword = PasswordManager.GetHashedPassword(model.Password);
            await Users.ChangePasswordAsync(current.Tenant, userId, newPassword, user).ConfigureAwait(false);
            return true;
        }
        public async Task<ActionResult> PostAsync(ChangePassword model)
        {
            if (!ModelState.IsValid)
            {
                return this.InvalidModelState(this.ModelState);
            }

            bool result = await ChangePasswordModel.ChangePasswordAsync(this.AppUser, model, this.RemoteUser).ConfigureAwait(true);
            return this.Ok(result);
        }