public async Task <string> Create(CreateUserInput input) { input.CheckDataAnnotations().CheckValidResult(); var existUser = await _userRepository.FirstOrDefaultAsync(p => p.UserName == input.UserName); if (existUser != null) { throw new UserFriendlyException($"已经存在用户名为{input.UserName}的用户"); } existUser = await _userRepository.FirstOrDefaultAsync(p => p.Phone == input.Phone); if (existUser != null) { throw new UserFriendlyException($"已经存在手机号码为{input.Phone}的用户"); } existUser = await _userRepository.FirstOrDefaultAsync(p => p.Email == input.Email); if (existUser != null) { throw new UserFriendlyException($"已经存在Email为{input.Email}的用户"); } await _userDomainService.Create(input); return("新增员工成功"); }
public async Task <IActionResult> SignUp([FromBody] SignUpViewModel value) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var success = await _domainService.Create(new User { DisplayName = value.DisplayName, Email = value.Email, UserName = value.UserName, Password = value.Password }); if (success) { return(Ok("User created.")); } else { return(BadRequest("Unable to create the user.")); } } catch (Exception ex) { return(BadRequest("Unable to create the user. " + ex.Message)); } }
private async Task CreateAdminAndRole(long tenantId, CreateTenantInput input, DbConnection conn, DbTransaction trans) { var tenantConfig = _tenantConfigProvider.Get(); if (tenantConfig == null || tenantConfig.SuperUserPassword.IsNullOrWhiteSpace() || tenantConfig.SuperUserPassword.IsNullOrWhiteSpace()) { throw new BusinessException("获取租户默认管理员账号和密码失败"); } var permissions = await _permissionRepository.GetAllAsync(); var createRole = new CreateRoleInput() { Identification = input.Identification + "_admin", Name = "管理员", PermissionIds = permissions.Select(p => p.Id).ToArray(), DataPermissionType = DataPermissionType.AllOrg, IsAllOrg = true, Memo = "创建租户时,初始化的角色", }; var roleId = await _roleDomainService.Create(createRole, conn, trans, tenantId); var createUser = new CreateUserInput() { OrgId = null, UserName = tenantConfig.SuperUserAccount, Password = tenantConfig.SuperUserPassword, ChineseName = tenantConfig.ChineseName ?? "管理员", Memo = "创建租户时,初始化的用户", RoleIds = new[] { roleId }, Status = Common.Status.Valid }; await _userDomainService.Create(createUser, conn, trans, tenantId); }