Example #1
0
 public async Task<UpdateUserOutput> UpdateCurrentUser(UpdateUserInput input)
 {
     input.Id = User.Identity.GetUserId<int>();
     input.Password = null;
     input.ConfirmPassword = null;
     input.UserGroups = null;
     UpdateUserOutput result = await _userBll.UpdateUser(input);
     return result;
 }
Example #2
0
 public async Task<UpdateUserOutput> UpdateUser(UpdateUserInput input, bool updateGroups)
 {
     UpdateUserOutput result = new UpdateUserOutput()
     {
         Status = 1
     };
     ApplicationUser user = await this.UserManager.FindByIdAsync(input.Id);
     if (user != null)
     {
         bool canUpdate = true;
         if (user.UserName != input.UserName)
         {
             ApplicationUser currentUser = await this.UserManager.FindByNameAsync(input.UserName);
             if (currentUser != null && currentUser.Id > 0 && currentUser.Id != user.Id)
                 canUpdate = false;
         }
         if (canUpdate)
         {
             user.UserName = input.UserName;
             user.Email = input.Email;
             user.PhoneNumber = input.PhoneNumber;
             IdentityResult validateResult = await this.UserManager.UserValidator.ValidateAsync(user);
             if (validateResult.Succeeded && !string.IsNullOrEmpty(input.Password))
                 validateResult = await this.UserManager.PasswordValidator.ValidateAsync(input.Password);
             if (validateResult.Succeeded)
             {
                 if (!string.IsNullOrEmpty(input.Password))
                     user.PasswordHash = this.UserManager.PasswordHasher.HashPassword(input.Password);
                 IdentityResult res = await this.UserManager.UpdateAsync(user);
                 if (res.Succeeded)
                 {
                     string[] scopeClaims = new string[1]
                     {
         "displayName"
                     };
                     IList<Claim> claims = await this.UserManager.GetClaimsAsync(user.Id);
                     foreach (Claim claim in Enumerable.Where<Claim>((IEnumerable<Claim>)claims, (Func<Claim, bool>)(m => Enumerable.Contains<string>((IEnumerable<string>)scopeClaims, m.Type))))
                         res = await this.UserManager.RemoveClaimAsync(user.Id, claim);
                     res = await this.UserManager.AddClaimAsync(user.Id, new Claim("displayName", input.DisplayName));
                     if (updateGroups)
                     {
                         int[] currentGroups = Enumerable.ToArray<int>(Enumerable.Select<Quang.Auth.Entities.Group, int>(this._userTable.GetGroupsByUser(user.Id), (Func<Quang.Auth.Entities.Group, int>)(m => m.Id)));
                         if (input.UserGroups != null)
                         {
                             foreach (Quang.Auth.Entities.Group group in Enumerable.Where<Quang.Auth.Entities.Group>(input.UserGroups, (Func<Quang.Auth.Entities.Group, bool>)(m => !Enumerable.Contains<int>((IEnumerable<int>)currentGroups, m.Id))))
                                 this._userTable.addUserToGroup(group.Id, user.Id);
                             foreach (int groupId in Enumerable.Where<int>((IEnumerable<int>)currentGroups, (Func<int, bool>)(m => !Enumerable.Contains<int>(Enumerable.Select<Quang.Auth.Entities.Group, int>(input.UserGroups, (Func<Quang.Auth.Entities.Group, int>)(n => n.Id)), m))))
                                 this._userTable.removeUserFromGroup(groupId, user.Id);
                         }
                     }
                     result.Status = 0;
                 }
             }
         }
     }
     return result;
 }
Example #3
0
 public async Task<UpdateUserOutput> UpdateUser(UpdateUserInput input)
 {
     try
     {
         var result = await _userBll.UpdateUser(input, true);
         if (result.Status == 0)
         {
             await _permissionBll.GenerateRolesForUser(input.Id);
             if (!string.IsNullOrEmpty(input.Password))
                 await LogHistory(LoginType.ChangePassword, LoginStatus.Success, User.Identity.GetUserName(), input.UserName, null, null);
         }
         else if (result.Status != 0 && !string.IsNullOrEmpty(input.Password))
             await LogHistory(LoginType.ChangePassword, LoginStatus.InvalidOldPassword, User.Identity.GetUserName(), input.UserName, null, null);
         return result;
     }
     catch (Exception ex)
     {
         ErrorStore.LogExceptionWithoutContext(ex);
     }
     return new UpdateUserOutput();
 }
Example #4
0
 public async Task<UpdateUserOutput> UpdateUser(UpdateUserInput input)
 {
     return await this.UpdateUser(input, false);
 }