public async Task <CreateUserVm> Handle(CreateUserCommand request, CancellationToken cancellationToken) { var vm = new CreateUserVm(); var user = await _userManager.FindByNameAsync(request.UserName); if (user == null) { var created = await _userManager.CreateUserAsync(request.UserName, request.Password, request.Email); if (created) { var addedUser = await _userManager.FindByNameAsync(request.UserName); vm.Token = _jwtGenerator.CreateToken(addedUser); vm.Username = addedUser.UserName; return(vm); } vm.Error = "Passwords did not match!"; return(vm); } vm.Error = "The user already exists!"; return(vm); }
public async Task <Unit> Handle(SeedSampleDataCommand request, CancellationToken cancellationToken) { var names = Enum.GetNames(typeof(ApplicationUserType)); foreach (var roleName in names) { var roleExist = await _userRoleManagerService.RoleExistsAsync(roleName); if (!roleExist) { await _userRoleManagerService.CreateUserRoleAsync(roleName); } } var entity = new ApplicationUser( "demouser@demo", "Demo", "Spa", "1234567890" ); var userExist = await _userManagerService.UserExistsAsync(entity.Email); if (!userExist) { await _userManagerService.CreateUserAsync(entity, ApplicationUserType.Admin, "Pass@word1"); } return(Unit.Value); }
public async Task <IActionResult> Register([Bind("FirstName,LastName,Email,Password")] RegisterViewModel model) { if (ModelState.IsValid) { var registerResult = await userManagerService.CreateUserAsync(model.Email, model.Password); if (registerResult.RegisterResult.Succeeded && registerResult.ConfirmEmailResult.Succeeded) { var signinResult = await signinManagerService.SigninAsync(model.Email, model.Password); if (signinResult.Succeeded) { return(RedirectToAction("Index", "Home")); } } } return(View()); }
public async Task <IActionResult> Register([FromBody] RegisterViewModel model) { var result = new ApiResponse <Empty>(); if (!ModelState.IsValid) { result.AddError(ModelState); return(Ok(result)); } var createResult = await userManagerService.CreateUserAsync(model.Email, model.Password); if (createResult.RegisterResult.Succeeded) { return(Ok(result)); } result.AddError(createResult.RegisterResult.Errors); return(Ok(result)); }
public async Task <IServiceReponse <bool> > Register(UserDto registration, UserType userType = UserType.Employee) { return(await HandleApiOperationAsync(async() => { if (await _userManager.UserExistsAsync(registration.Email)) { throw await _helper.GetExceptionAsync(ErrorConstants.UserAccountExists); } if (!await _userManager.RolesExistAsync(registration.Roles ?? new List <string>())) { throw await _helper.GetExceptionAsync(ErrorConstants.RoleNotExist); } var user = registration.MapTo <User>(); user.UserType = userType; user.IsActive = true; var password = _passwordGenerator.Generate(); if (!await _userManager.CreateUserAsync(user, password, registration.Roles ?? new List <string>())) { throw await _helper.GetExceptionAsync(ErrorConstants.UserAccountRegistrationFailed); } await _messagingFactory.GetEmailManager().SendAsync( "Business Mobility", user.Email, "Welcome to Business!", $"<div> username: {user.Email } </div> <div> password: {password} </div>", true ); return new ServiceResponse <bool>(true); })); }
public async Task <Unit> Handle(CreateCustomerCommand request, CancellationToken cancellationToken) { var applicationUser = new ApplicationUser( request.Email, request.FirstName, request.LastName, request.PersonalId ); var userExist = await _userManagerService.UserExistsAsync(applicationUser.Email); if (userExist) { throw new DomainException("Customer exists"); } var identityResult = await _userManagerService.CreateUserAsync(applicationUser, ApplicationUserType.Admin, request.Password); if (!identityResult.Result.Succeeded) { throw new DomainException(string.Join(", ", identityResult.Result.Errors)); } var customer = new Customer( Guid.NewGuid(), request.gender, request.birthDate, applicationUser.Id ); _context.Add(customer); await SaveAndPublish(customer, cancellationToken); return(Unit.Value); }
public async Task <Result> Handle(RegistrationCommand request, CancellationToken cancellationToken) { return(await _userManagerService.CreateUserAsync(request.Name, request.Email, request.Password)); }
public async Task <UserRegisterResult> Register(UserInfo userInfo) { var userRegisterResult = await _userManagerService.CreateUserAsync(userInfo); return(userRegisterResult); }