예제 #1
0
        public async Task<ActionResult> ChangePasswordAsync(ChangePasswordInfo model)
        {
            var user = await AppUsers.GetCurrentAsync(this.Tenant).ConfigureAwait(true);

            if (!user.IsAdministrator)
            {
                return this.AccessDenied();
            }

            if (!this.ModelState.IsValid)
            {
                return this.InvalidModelState(this.ModelState);
            }


            if (model.Password != model.ConfirmPassword)
            {
                return this.Failed("Confirm password does not match with the supplied password", HttpStatusCode.BadRequest);
            }

            try
            {
                await Users.ChangePasswordAsync(this.Tenant, user.UserId, model).ConfigureAwait(true);
                return this.Ok("OK");
            }
            catch (Exception ex)
            {
                return this.Failed(ex.Message, HttpStatusCode.InternalServerError);
            }
        }
예제 #2
0
파일: Users.cs 프로젝트: frapid/frapid
 public static async Task ChangePasswordAsync(string tenant, int userId, ChangePasswordInfo model)
 {
     using (var db = DbProvider.Get(FrapidDbServer.GetSuperUserConnectionString(tenant), tenant).GetDatabase())
     {
         string encryptedPassword = EncryptPassword(model.Password);
         await db.NonQueryAsync("UPDATE account.users SET password = @0 WHERE user_id=@1;", encryptedPassword, model.UserId, encryptedPassword).ConfigureAwait(false);
     }
 }