public UserOutput Create(CreateUserInput input) { var user = new User { Email = input.Email, Gender = input.Gender, FirstName = input.FirstName, LastName = input.LastName, Telephone = input.Telephone, Mobile = input.Mobile, Company = input.Company, Roles = input.Roles.Select(r => new UserRole { Role = r }).ToList(), Deliveries = input.Deliveries.Select(d => new Delivery { Address = d.Address, PostCode = d.PostCode, Receiver = d.Receiver, Phone = d.Phone }).ToList(), Status = UserStatus.Unactivated }; using (var dbContext = new AllureContext()) { dbContext.Set <User>().Add(user); dbContext.SaveChanges(); } return(Id(user.Id)); }
private async Task <UserInfo> CheckUserInfo(CreateUserInput input, long?tenanId) { var userInfo = input.MapTo <UserInfo>(); if (tenanId.HasValue) { userInfo.TenantId = tenanId.Value; } var departAppServiceProxy = GetService <IDepartmentAppService>(); if (userInfo.OrgId.HasValue) { if (!await departAppServiceProxy.Check(userInfo.OrgId.Value)) { throw new BusinessException($"不存在Id为{userInfo.OrgId}的部门信息"); } } var positionAppServiceProxy = GetService <IPositionAppService>(); if (userInfo.PositionId.HasValue) { if (!await positionAppServiceProxy.CheckExsit(userInfo.PositionId.Value)) { throw new BusinessException($"不存在Id为{userInfo.PositionId}的职位信息"); } } return(userInfo); }
public async Task <User> UserCreateAsync([Service] UserRepository userRepo, CreateUserInput createUserInput) { User user = new User(); user.Name = createUserInput.Name; return(await userRepo.CreateAsync(user)); }
public async Task <IActionResult> Create([FromBody] CreateUserInput userParam) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var entity = userParam.MapTo <User>(); if (UsuarioExists(entity.Username)) { return(Conflict("The informed username already exists.")); } var user = await _userRepository.Create(entity); if (user != null) { await _userRepository.Commit(); return(Ok(user)); } return(Conflict("Something went wrong while creating the user.")); } catch (Exception ex) { throw ex; } }
public async Task CreateUser(CreateUserInput input) { var user = input.MapTo <User>(); user.TenantId = AbpSession.TenantId; user.Password = new PasswordHasher().HashPassword(input.Password); user.IsEmailConfirmed = true; // todo: надо добавлять новые разрешения в AuthorizationProvider //// по умолчанию всегда добавляется разрешение Users //var p = _permissionManager.GetPermission("Users"); //await _userManager.GrantPermissionAsync(user, p); var result = await UserManager.CreateAsync(user); CheckErrors(result); if (result.Succeeded) { await CurrentUnitOfWork.SaveChangesAsync(); // подписка на изменение баланса await _notificationSubscriptionManager.SubscribeAsync(new UserIdentifier(null, user.Id), "BalanceChanged"); // добавление начального баланса EventBus.Trigger(new UserCreatedEventData { UserId = user.Id }); } }
/// <summary> /// 创建用户 /// </summary> public async Task CreateUser(CreateUserInput input, int tenantId) { using (CurrentUnitOfWork.SetTenantId(tenantId)) { await _userAppService.CreateUser(input); } }
public async Task <BlogResponse> CreateUserAsync(CreateUserInput input) { var response = new BlogResponse(); var user = await _users.FindAsync(x => x.Username == input.Username); if (user is not null) { response.IsFailed("The username already exists."); return(response); } input.Password = input.Password.ToMd5(); await _users.InsertAsync(new User { Username = input.Username, Password = input.Password, Type = input.Type, Identity = input.Identity, Name = input.Name, Avatar = input.Avatar, Email = input.Email }); return(response); }
public void CreateUser(CreateUserInput input) { Logger.Info("Creating a user for input: " + input); User existing = _userRepository.GetAll() .FirstOrDefault(u => u.DisplayName.Equals(input.DisplayName, StringComparison.CurrentCultureIgnoreCase)); if (existing != null) { throw new UserFriendlyException(L("UserWithDisplayNameAlreadyExists")); // TODO: Replace this with a CreateUserOutput } var user = new User { DisplayName = input.DisplayName, Email = input.Email }; var account = new Account { IterationCount = input.IterationCount, PasswordHash = input.PasswordHash, Salt = input.Salt }; user.Account = account; _userRepository.Insert(user); }
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> CreateUser(CreateUserInput input) { if (ModelState.IsValid) { var isExistUser = await userManager.FindByNameAsync(input.UserName); if (isExistUser != null) { ModelState.AddModelError("Exist", "User already exist"); } else { AppUser user = new AppUser { UserName = input.UserName, Pass = input.Password }; var result = await userManager.CreateAsync(user, input.Password); if (result.Succeeded) { var addeduser = await userManager.FindByNameAsync(input.UserName); var addedRoles = input.Roles.Where(i => i.IsSelected == true).Select(i => i.Name).ToList(); await userManager.AddToRolesAsync(addeduser, addedRoles); return(RedirectToAction("GetUserList")); } } } return(View(input)); }
public async Task <IActionResult> Post([FromForm][Required] CreateUserRequest request) { var input = new CreateUserInput(request.Name, request.Email); await _mediator.PublishAsync(input); return(this._CreateUserPresenter.ViewModel); }
public async Task <Result <string> > CreateUserAsync(CreateUserInput input) { PHOTOnlineUser user = new PHOTOnlineUser() { FirstName = input.FirstName, LastName = input.LastName, Address = input.Address, Email = input.Email, UserName = input.Username, PhoneNumber = input.PhoneNumber, UserType = input.UserType }; Result <string> result = await _authService.CreateUserAsync(user, input.Password); if (input.UserType != UserType.Photograph) { await _authService.SignInAsync(input.Email, input.Password); } await _authService.AddUserToRoleByEmail( input.Email, input.UserType.ToString()); return(result); }
public async Task <long> Create(CreateUserInput input, DbConnection conn, DbTransaction trans, long?tenanId = null) { var userInfo = await CheckUserInfo(input, tenanId); userInfo.Password = _passwordHelper.EncryptPassword(userInfo.UserName, userInfo.Password); using (var locker = await _lockerProvider.CreateLockAsync("CreateUser")) { return(await locker.Lock(async() => { var userId = await _userRepository.InsertAndGetIdAsync(userInfo, conn, trans); foreach (var roleId in input.RoleIds) { await _userRoleRepository.InsertAsync(new UserRole { UserId = userId, RoleId = roleId, TenantId = userInfo.TenantId }, conn, trans); } foreach (var userGroupId in input.UserGroupIds) { await _userUserGroupRelationRepository.InsertAsync( new UserUserGroupRelation { UserId = userId, UserGroupId = userGroupId, TenantId = userInfo.TenantId }, conn, trans); } return userInfo.Id; })); } }
public async Task CreateUser(CreateUserInput input) { var user = input.MapTo <User>(); if (user.Id != 0) { var userFound = _userRepository.Get(user.Id); var modified = input.MapTo(userFound); await UserManager.SetTwoFactorEnabledAsync(input.Id, input.IsTwoFactorEnabled); await UserManager.UpdateAsync(modified); } else { user.TenantId = AbpSession.TenantId; user.Password = new PasswordHasher().HashPassword(input.Password); CheckErrors(await UserManager.CreateAsync(user)); if (bool.Parse(await SettingManager.GetSettingValueAsync("Abp.Zero.UserManagement.IsEmailConfirmationRequiredForLogin")) && input.SendNotificationMail) { var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var serverUrl = ServerHelpers.GetServerUrl(HttpContext.Current.Request.RequestContext.HttpContext.Request); var url = serverUrl + "/Account/EmailConfirmation/?userId=" + user.Id + "&token=" + code; await SendEmailConfirmationCode(url, user.EmailAddress); } await CurrentUnitOfWork.SaveChangesAsync(); await UserManager.SetTwoFactorEnabledAsync(user.Id, input.IsTwoFactorEnabled); await SetDefaultRoles(user); await _usersAppNotificationsSender.SendUserCreatedNotification((await GetCurrentUserAsync()), user); } }
public async Task <ResponseBase <bool> > Create([FromBody] CreateUserInput input) { var re = this.Request; var result = await _userService.Create(input); return(result); }
public async Task <IActionResult> Post([FromBody][Required] CreateUserRequest request) { var input = new CreateUserInput(new ShortName(request.Name), new Email(request.Email), new Password(request.Password)); await _mediator.PublishAsync(input); return(_presenter.ViewModel); }
public async Task Execute(CreateUserInput input) { if (input.Name.Length <= 2 || input.Name.Length >= 40) { outputPort.WriteError("Name must be between 2 and 40 characters"); return; } if (input.Password.Length < 6) { outputPort.WriteError("Password must be more than 6 characters"); return; } var success = await identityService.CreateUserAsync(new Domain.Entities.User { Name = input.Name, Surname = input.Surname, Email = input.Email, Password = input.Password }); if (!success) { outputPort.WriteError("Error message"); return; } var accessToken = await authService.GenerateAccessToken(input.Name, input.Password); outputPort.Standart(new CreateUserOutput(accessToken)); }
public async Task <CreateUserOutput> Create([FromBody] CreateUserInput input) { CreateUserOutput output = new CreateUserOutput(); if (string.IsNullOrEmpty(input.Email)) { output.Status = "EMAIL_IS_NULL"; } else if (string.IsNullOrEmpty(input.Password)) { output.Status = "PASSWORD_IS_NULL"; } else if (input.Password.Length < 6) { output.Status = "PASSWORD_LENGTH_TOO_SHORT"; } else if (!input.Password.Equals(input.ConfirmPassword)) { output.Status = "PASSWORD_NOT_MATCH"; } else { User user = _db._Users.Where(e => e.Email.ToUpper().Equals(input.Email.ToUpper())).FirstOrDefault(); if (user != null) { output.Status = "EMAIL_IN_USE"; } else { IdentityUser newAspUser = new IdentityUser() { UserName = input.Email, Email = input.Email }; var status = await _userManager.CreateAsync(newAspUser, input.Password); if (status.Succeeded) { User newUser = new User() { FName = input.FName, LName = input.LName, Email = input.Email, AspNetUser = newAspUser, Status = 1 }; _db._Users.Add(newUser); _db.SaveChanges(); output.Status = "OK"; } else { output.Status = "INTERNAL_ERROR"; } } } return(output); }
/// <summary> /// Allows creating a new user in nebulon ON /// </summary> /// <param name="input"> /// The configuration for the new user /// </param> /// <returns>The new user</returns> public User CreateUser(CreateUserInput input) { GraphQLParameters parameters = new GraphQLParameters(); parameters.Add(@"input", input, false); return(RunMutation <User>(@"createOrgUser", parameters)); }
public async Task CreateUser(CreateUserInput input) { await _userInfoRepository.InsertAsync(new UserInfo() { Code = input.Code, Name = input.Name }); }
public CreateUserOutput CreateUser(CreateUserInput input) { input.Validate();//It could be better to call the validation method in an interceptor or on action executing. _userService.CreateUser(input.User); return(new CreateUserOutput()); }
[AbpAuthorize("CanCreateUsers")] //An example of permission checking public async Task CreateUser(CreateUserInput input) { if (AbpSession.MultiTenancySide == MultiTenancySides.Host) { CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, input.TenantId); await _userRepository.InsertAsync(new User(input.Name, input.UserName, input.Surname, input.EmailAddress, input.TenantId)); } }
public async Task <CreateUserPayloadInternal> CreateUserAsync(CreateUserInput input, CancellationToken cancellationToken) { var entity = this.mapper.Map <CreateUserInput, UserAccountEntity>(input); return(new CreateUserPayloadInternal( User: entity, Password: null )); }
public async Task <User> CreateUser( [Service] IAsyncCreateStrategy <User, CreateUserInput> strategy, CreateUserInput user ) { var result = await strategy.CreateAsync(user); return(result); }
public async Task CreateUser(CreateUserInput input) { var user = input.MapTo <User>(); user.TenantId = AbpSession.TenantId; user.Password = new PasswordHasher().HashPassword(input.Password); user.IsEmailConfirmed = true; CheckErrors(await UserManager.CreateAsync(user)); }
public JsonResult Edit(CreateUserInput model) { if (ModelState.IsValid) { _userAppService.Edit(model); return(Json(new { result = true, errors = "" })); } return(Json(new { result = false, errors = ModelState.AllModelStateErrors() })); }
public async Task CreateAdmin([NotNull] CreateUserInput createAdminInput) { if (!createAdminInput.IsPasswordValid()) { throw new ApplicationException("Password and confirm password mismatch!"); } await userService.Create(createAdminInput.Username, createAdminInput.Password, UserRole.Admin); await Repository.SaveChangesAsync(); }
/// <summary> /// 修改记录 /// </summary> /// <param name="model"></param> public void Edit(CreateUserInput model) { _userRepository.Update(model.Id, (a) => { a.Mobile = model.Mobile; a.EmailAddress = model.EmailAddress; a.Name = model.Name; a.UserName = model.UserName; }); }
public async Task CreateUser(CreateUserInput input) { var user = ObjectMapper.Map <User>(input); user.TenantId = AbpSession.TenantId; user.Password = _passwordHasher.HashPassword(user, input.Password); user.IsEmailConfirmed = true; CheckErrors(await UserManager.CreateAsync(user)); }
public ActionResult <User> Post([FromBody] CreateUserInput user) { try { return(_userService.CreateNewUser(user)); } catch (Exception) { return(BadRequest("Failed to create user.")); } }