public async Task <UserDeleteResponse> DeleteOne(ApplicationUser currentUser, UserTypeVM userType, long id) { var response = new UserDeleteResponse(); var applicationUserType = GetApplicationUserType(currentUser); if (applicationUserType != UserType.Admin && applicationUserType != UserType.Manager) // удалить может только админ или менеджер { response.AddError(_stringLocalizer[CustomStringLocalizer.NO_RIGHTS_TO_DELETE_USER]); return(response); } if (applicationUserType == UserType.Manager && userType == UserTypeVM.Admin) // менеджер хочет удалить админа { response.AddError(_stringLocalizer[CustomStringLocalizer.NO_RIGHTS_TO_DELETE_USER]); return(response); } var applicationUserValue = await ApplicationUserFactory.GetApplicationUserAsync(_fuelContext, userType, id); if (applicationUserValue == null) { response.AddError(_stringLocalizer[CustomStringLocalizer.USER_NOT_FOUND]); return(response); } var result = await _userManager.DeleteAsync(applicationUserValue); response.IsSuccess = result.Succeeded; return(response); }
public void HasRole_Ok(Role roleToCheck, bool expected) { ApplicationUser target = new ApplicationUserFactory(Role.HRManager).Build(); Assert.Equal(Role.HRManager, target.Role); Assert.Equal(expected, target.HasRole(roleToCheck)); }
public HeadlessOktaIdentityProvider( FederatedAuthenticationConfiguration federatedAuthenticationConfiguration, ICookieManager cookieManager, BaseSettings settings, ApplicationUserFactory applicationUserFactory) : base(federatedAuthenticationConfiguration, cookieManager, settings) { this.ApplicationUserFactory = applicationUserFactory; _isDevelopment = Sitecore.Configuration.Settings.GetBoolSetting("Okta_DevelopmentMode", false);; }
public string LoadUsersFromRandomuser() { string json = RandomUserGeneratorHelper.GetMultiple(PhoneBookConfig.NumberOfUsers); var users = json.AsDynamic().results; for (int i = 0; i < users.Count; i++) { ApplicationUser user = ApplicationUserFactory.Create(users[i]); UserManager.Create(user, PhoneBookConfig.DefaultPassword); } return("success"); }
public async Task <RegisterResponse> AddUser([FromBody] RegisterViewModel viewModel) { if (!ModelState.IsValid) { return(_userModel.CreateBadResponse <RegisterResponse>(ModelState)); } var currentUser = await _userManager.GetUserAsync(User); var applicationUser = ApplicationUserFactory.CreateApplicationUser(viewModel); return(await _userModel.SaveUserAccountAsync(applicationUser, currentUser, viewModel)); }
public void NotToThrow_AndReturnNewApplicationUser() { var parents = this.GetParents(); var userFactory = new ApplicationUserFactory(); foreach (var parent in parents) { var user = userFactory.CreateParent(parent); Assert.AreEqual(parent.Age, user.Age); Assert.AreEqual(parent.LastName, user.LastName); Assert.AreEqual(parent.FirstName, user.FirstName); Assert.IsTrue(user.UserType == UserTypes.Parent); } }
public void NotToThrow_AndReturnNewApplicationUser() { var teachers = this.GetTeachers(); var userFactory = new ApplicationUserFactory(); foreach (var teacher in teachers) { var user = userFactory.CreateTeacher(teacher); Assert.AreEqual(teacher.Age, user.Age); Assert.AreEqual(teacher.LastName, user.LastName); Assert.AreEqual(teacher.FirstName, user.FirstName); Assert.IsTrue(user.UserType == UserTypes.Teacher); } }
public async Task <UserUpdateResponse> PostOne(ApplicationUser currentUser, UserTypeVM userType, ApplicationUserVM applicationUserVM) { var response = new UserUpdateResponse(); var applicationUserType = GetApplicationUserType(currentUser); if (applicationUserType != UserType.Admin && applicationUserType != UserType.Manager) // редактировать может только админ или менеджер { response.AddError(_stringLocalizer[CustomStringLocalizer.NO_RIGHTS_TO_ADD_OR_UPDATE_USER]); return(response); } if (applicationUserType == UserType.Manager && userType == UserTypeVM.Admin) // менеджер хочет редактировать админа { response.AddError(_stringLocalizer[CustomStringLocalizer.NO_RIGHTS_TO_ADD_OR_UPDATE_USER]); return(response); } ApplicationUser applicationUserValue = null; if (applicationUserVM.Id.HasValue) { applicationUserValue = await ApplicationUserFactory.GetApplicationUserAsync(_fuelContext, userType, applicationUserVM.Id.Value); } if (applicationUserValue == null) { response.AddError(_stringLocalizer[CustomStringLocalizer.USER_NOT_FOUND]); return(response); } applicationUserValue.Email = applicationUserVM.Email; applicationUserValue.UserName = applicationUserVM.Email; var result = await _userManager.UpdateAsync(applicationUserValue); if (!result.Succeeded) { response.AddError(_stringLocalizer[CustomStringLocalizer.USER_NOT_FOUND]); return(response); } await UpdateUserClaimsAsync(applicationUserVM, applicationUserValue).ConfigureAwait(false); response.Id = applicationUserValue.Id; return(response); }
public void GenerateUserIdentityAsync877() { using (PexDisposableContext disposables = PexDisposableContext.Create()) { ApplicationUser applicationUser; Task <ClaimsIdentity> task; applicationUser = ApplicationUserFactory.Create ((string)null, false, (string)null, (string)null, (string)null, false, false, default(DateTime?), false, 0, (string)null, (string)null); task = this.GenerateUserIdentityAsync (applicationUser, (UserManager <ApplicationUser>)null); disposables.Add((IDisposable)task); disposables.Dispose(); Assert.IsNotNull((object)task); Assert.AreEqual <TaskStatus>(TaskStatus.Faulted, ((Task)task).Status); Assert.AreEqual <bool>(false, ((Task)task).IsCanceled); Assert.IsNull(((Task)task).AsyncState); Assert.AreEqual <bool>(true, ((Task)task).IsFaulted); Assert.IsNotNull((object)applicationUser); Assert.AreEqual <string>((string)null, ((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>) applicationUser).Email); Assert.AreEqual <bool>(false, ((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>) applicationUser).EmailConfirmed); Assert.AreEqual <string>((string)null, ((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>) applicationUser).PasswordHash); Assert.AreEqual <string>((string)null, ((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>) applicationUser).SecurityStamp); Assert.AreEqual <string>((string)null, ((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>) applicationUser).PhoneNumber); Assert.AreEqual <bool>(false, ((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>) applicationUser).PhoneNumberConfirmed); Assert.AreEqual <bool>(false, ((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>) applicationUser).TwoFactorEnabled); Assert.IsNull((object)(((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>) applicationUser).LockoutEndDateUtc)); Assert.AreEqual <bool>(false, ((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>) applicationUser).LockoutEnabled); Assert.AreEqual <int>(0, ((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>) applicationUser).AccessFailedCount); Assert.IsNotNull(((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>) applicationUser).Roles); Assert.IsNotNull(((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>) applicationUser).Claims); Assert.IsNotNull(((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>) applicationUser).Logins); Assert.AreEqual <string>((string)null, ((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>) applicationUser).Id); Assert.AreEqual <string>((string)null, ((IdentityUser <string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>) applicationUser).UserName); } }
public UserBuilderOkta(ApplicationUserFactory applicationUserFactory, IHashEncryption hashEncryption) : base(applicationUserFactory, hashEncryption) { }
public AdfsExternalUserBuilder(ApplicationUserFactory applicationUserFactory, IHashEncryption hashEncryption) : base(applicationUserFactory, hashEncryption) { }