private void SignIn(UserEditDto user, ClaimsIdentity identity = null, bool rememberMe = false) { if (identity == null) { identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie); identity.AddClaim(new Claim(AbpClaimTypes.UserNameClaimType, user.UserName)); identity.AddClaim(new Claim(AbpClaimTypes.UserIdClaimType, user.Id.ToString())); } AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = rememberMe }, identity); }
public LoginResultDto(UserEditDto user, ClaimsIdentity identity) : this(LoginResultType.Success) { User = user; Identity = identity; }
public async Task UpdateUser(UserEditDto input) { var user = await _repository.FirstOrDefaultAsync(x => x.Id == input.Id); if (user == null) { throw new AbpException("There is no user with id: " + input.Id); } input.MapTo(user); if (!input.Password.IsNullOrEmpty()) { var rs = await new PasswordValidator().ValidateAsync(input.Password); rs.CheckErrors(); user.Password = new PasswordHasher().HashPassword(input.Password); } var usr = await _repository.FirstOrDefaultAsync(x => x.UserName == user.UserName); if (usr != null && usr.Id != input.Id) { throw new UserFriendlyException(string.Format(L("Identity.DuplicateName"), user.UserName)); } usr = await _repository.FirstOrDefaultAsync(x => x.Email == user.Email); if (usr != null && usr.Id != input.Id) { throw new UserFriendlyException(string.Format(L("Identity.DuplicateEmail"), user.Email)); } var oldUserName = user.UserName; if (oldUserName == "admin" && input.UserName != "admin") { throw new UserFriendlyException(string.Format(L("CanNotRenameAdminUser"), "admin")); } await _repository.UpdateAsync(user); }
public async Task<ActionResult> Edit(UserEditDto model, FormCollection collection) { if (ModelState.IsValid) { try { using (var uow = _unitOfWorkManager.Begin()) { model.IsActive = true; await _userAppService.UpdateUser(model); var roles = await _roleAppService.GetRoles(new GetRolesInput()); var list = new List<UserRoleDto>(); foreach (var item in roles.Items) { var info = new UserRoleDto(); var chkName = "Role_" + item.Id; var chkVal = collection[chkName]; var userRole = "UserRole_" + item.Id; Guid userRoleId; var status = Guid.TryParse(collection[userRole], out userRoleId); if (status) info.Id = userRoleId; if (chkVal == "on") { info.RoleId = item.Id; info.UserId = model.Id; info.Status = true; list.Add(info); } else { info.RoleId = item.Id; info.UserId = model.Id; info.Status = false; if (status) list.Add(info); } } await _userAppService.CreateOrUpdate(list); await uow.CompleteAsync(); } var lang = string.Format(L("Updated.RecordSucceed").Localize(), model.UserName); this.AddModelMessage("", lang, MessageTypes.Information); } catch (Exception ex) { this.AddModelMessage("exception", ex.Message); } } return RedirectToAction("Index"); }