protected virtual async Task <IdentityResult> ValidateTenancyNameAsync(string tenancyName) { if (!Regex.IsMatch(tenancyName, HozaruTenant <TTenant, TUser> .TenancyNameRegex)) { return(HozaruIdentityResult.Failed(MessagesCoreIdentity.InvalidTenancyName)); } return(IdentityResult.Success); }
/// <summary> /// Deletes a role. /// </summary> /// <param name="role">Role</param> public async override Task <IdentityResult> DeleteAsync(TRole role) { if (role.IsStatic) { return(HozaruIdentityResult.Failed(string.Format("CanNotDeleteStaticRole", role.Name))); } return(await base.DeleteAsync(role)); }
public async override Task <IdentityResult> DeleteAsync(TUser user) { if (user.UserName == HozaruUser <TTenant, TUser> .AdminUserName) { //return HozaruIdentityResult.Failed(string.Format(L("CanNotDeleteAdminUser"), HozaruUser<TTenant, TUser>.AdminUserName)); return(HozaruIdentityResult.Failed(string.Format("CanNotDeleteAdminUser"), HozaruUser <TTenant, TUser> .AdminUserName)); } return(await base.DeleteAsync(user)); }
public async Task <IdentityResult> UpdateAsync(TTenant tenant) { if (await TenantRepository.FirstOrDefaultAsync(t => t.TenancyName == tenant.TenancyName && t.Id != tenant.Id) != null) { return(HozaruIdentityResult.Failed(string.Format(MessagesCoreIdentity.TenancyNameIsAlreadyTaken, tenant.TenancyName))); } await TenantRepository.UpdateAsync(tenant); return(IdentityResult.Success); }
public virtual async Task <IdentityResult> CheckDuplicateUsernameOrEmailAddressAsync(long?expectedUserId, string userName, string emailAddress) { var user = (await FindByNameAsync(userName)); if (user != null && user.Id != expectedUserId) { return(HozaruIdentityResult.Failed(string.Format("Identity.DuplicateName"), userName)); } user = (await FindByEmailAsync(emailAddress)); if (user != null && user.Id != expectedUserId) { return(HozaruIdentityResult.Failed(string.Format("Identity.DuplicateEmail"), emailAddress)); } return(IdentityResult.Success); }
public virtual async Task <IdentityResult> CreateAsync(TTenant tenant) { if (await TenantRepository.FirstOrDefaultAsync(t => t.TenancyName == tenant.TenancyName) != null) { return(HozaruIdentityResult.Failed(string.Format(MessagesCoreIdentity.TenancyNameIsAlreadyTaken, tenant.TenancyName))); } var validationResult = await ValidateTenantAsync(tenant); if (!validationResult.Succeeded) { return(validationResult); } await TenantRepository.InsertAsync(tenant); return(IdentityResult.Success); }
public async override Task <IdentityResult> UpdateAsync(TUser user) { var result = await CheckDuplicateUsernameOrEmailAddressAsync(user.Id, user.UserName, user.EmailAddress); if (!result.Succeeded) { return(result); } var oldUserName = (await GetUserByIdAsync(user.Id)).UserName; if (oldUserName == HozaruUser <TTenant, TUser> .AdminUserName && user.UserName != HozaruUser <TTenant, TUser> .AdminUserName) { return(HozaruIdentityResult.Failed(string.Format("CanNotRenameAdminUser"), HozaruUser <TTenant, TUser> .AdminUserName)); } return(await base.UpdateAsync(user)); }
public virtual async Task <IdentityResult> CheckDuplicateRoleNameAsync(int?expectedRoleId, string name, string displayName) { var role = await FindByNameAsync(name); if (role != null && role.Id != expectedRoleId) { return(HozaruIdentityResult.Failed(string.Format("RoleNameIsAlreadyTaken"), name)); } role = await FindByDisplayNameAsync(displayName); if (role != null && role.Id != expectedRoleId) { return(HozaruIdentityResult.Failed(string.Format("RoleDisplayNameIsAlreadyTaken"), displayName)); } return(IdentityResult.Success); }