private async Task SeedGlobalAdministrator( ICredentialRoleStore credentialRoleStore, ICredentialStore credentialStore) { bool isExistingAnyAdminCredentials = await credentialStore.IsExistingByCredentialRoleCode(SentinelCredentialRoleCodes.GlobalAdmin); if (!isExistingAnyAdminCredentials) { string adminCredentialId = SentinelCredentialIds.Admin; CredentialRole adminRole = await credentialRoleStore.Get(SentinelCredentialRoleCodes.GlobalAdmin); Credential admin = new Credential(); admin.BirthDate = new DateTime(2000, 1, 1); admin.CreationDate = DateTime.UtcNow; admin.DisplayName = adminCredentialId; admin.CredentialId = adminCredentialId; admin.Email = adminCredentialId + "@admin.com"; admin.PasswordSalt = HashingUtil.GenerateSalt(); admin.PasswordHash = HashingUtil.GenerateHash(adminCredentialId, admin.PasswordSalt); admin.Roles = new List <CredentialRole> { adminRole }; await credentialStore.Create(admin); } }
public async Task <IActionResult> Create(CredentialCreateForm form) { var validationResult = new CredentialCreateFormValidator( CredentialStore, DisplayNameRule) .Validate(form); validationResult.AddToModelState(this.ModelState, null); if (!validationResult.IsValid) { return(ValidationError()); } Credential credential = new Credential(); credential.BirthDate = form.Birthdate; credential.CreationDate = DateTime.UtcNow; credential.DisplayName = form.Username; credential.CredentialId = form.Username.ToLower(); credential.Email = form.Email; credential.PasswordSalt = HashingUtil.GenerateSalt(); credential.PasswordHash = HashingUtil.GenerateHash(form.Password, credential.PasswordSalt); CredentialRole defaultRole = await CredentialRoleStore.Get(SentinelCredentialRoleCodes.RegularUser); credential.Roles.Add(defaultRole); await this.CredentialStore.Create(credential); string url = Url.Action(nameof(GetByCredentialId), new { credential.CredentialId }); var view = await this.GetByCredentialId(credential.CredentialId); return(Created(url, view)); }