public IActionResult Register() { UserRegistrationDto model = new UserRegistrationDto(); return(View(model)); }
public async Task <IActionResult> Post([FromBody] UserRegistrationDto userRegistrationDto) { var response = await _authServices.Register(userRegistrationDto); return(StatusCode(response.Status, response)); }
public async Task Register(UserRegistrationDto userRegistrationDto) { var user = User.CreateIdentity(userRegistrationDto.Email, userRegistrationDto.Email, userRegistrationDto.Phone); var identityResult = await _userManager.CreateAsync(user, userRegistrationDto.Password); if (identityResult.Succeeded) { await _userManager.AddToRoleAsync(user, ApplicationRoles.User); var profile = new Profile(); var country = GetCountry(userRegistrationDto.CountryName); var city = GetCity(country, userRegistrationDto.CityName, userRegistrationDto.CityId.Value); var ethnicity = GetEthnicity(userRegistrationDto.EthnicityId.Value); var occupation = GetOccupation(userRegistrationDto.OccupationId.Value); var interests = GetInterests(userRegistrationDto.Interests); profile.Identity = user; profile.Country = country; profile.City = city; profile.Occupation = occupation; profile.Ethnicity = ethnicity; profile.Interests = interests; profile.DateOfBirth = userRegistrationDto.DateOfBirth.Value; profile.Name = userRegistrationDto.Name; profile.Surname = userRegistrationDto.Surname; profile.Gender = (GenderEnum)userRegistrationDto.Gender.Value; _profileService.Insert(profile); try { await _unitOfWork.SaveChangesAsync(); OnUserRegistered(new UserRegisteredArgs(user, profile)); } catch (Exception e) { if (_profileService.ExistsAsync(profile.Id).Result) { _profileService.Delete(profile); await _unitOfWork.SaveChangesAsync(); await _userManager.DeleteAsync(user); } var error = new IdentityError { Code = "UserSave", Description = "Unable to register. Try again." }; OnRegistrationFailed(new RegistrationFailedArgs(new List <IdentityError> { error })); } } else { OnRegistrationFailed(new RegistrationFailedArgs(identityResult.Errors)); } }
public int RegisterUser(UserRegistrationDto userRegistrationDto) { UserLoginDto userLogin = userRegistrationDto.LoginInfo; UserInfoDto userInfo = userRegistrationDto.UserInfo; int userId; try { if (userLogin == null) { throw new ArgumentNullException("User Login Information cannot be null"); } if (userInfo == null) { throw new ArgumentNullException("User Information cannot be null"); } using (UserLoginRepository userLoginRepository = new UserLoginRepository()) { UserLogin userLoginEntity = userLoginRepository.Find(x => string.Equals(x.UserId, userLogin.UserId)); if (userLoginEntity != null) { throw new Exception("User with same user id already exists."); } else { userLoginEntity = new UserLogin() { UserId = userLogin.UserId, Password = userLogin.Password.Encrypt(), IsActive = true, IsLocked = false, RetryCount = 0 }; userId = userLoginRepository.Insert(userLoginEntity); } } if (userId != 0) { using (UserInfoRepository userInfoRepository = new UserInfoRepository()) { UserInfo userInfoEntity = new UserInfo() { UserId = userInfo.UserId, EMail = userInfo.Email, FirstName = userInfo.FirstName, LastName = userInfo.LastName, Gender = userInfo.Gender }; return(userInfoRepository.Insert(userInfoEntity)); } } else { throw new Exception("Failed to register user."); } } catch (Exception ex) { _logger.Error(ex); throw; } }
public async Task <IActionResult> Register([FromBody] UserRegistrationDto user) { if (ModelState.IsValid) { // We can utilise the model var existingUser = await _userManager.FindByEmailAsync(user.Email); if (existingUser != null) { var errorEmail = new UserRegistrationDto { Email = "Email 已使用過" }; string jsonString = JsonSerializer.Serialize(errorEmail); var errors = new List <string>() { }; errors.Add(jsonString); return(BadRequest(new RegistrationResponse() { Errors = errors, Success = false })); } var newUser = new IdentityUser { Email = user.Email, UserName = user.UserName }; var isCreated = await _userManager.CreateAsync(newUser, user.Password); if (isCreated.Succeeded) { user.UserId = newUser.Id; _ecDbContext.UserInfo.Add(user); await _ecDbContext.SaveChangesAsync(); var jwtToken = GenerateJwtToken(newUser); return(Ok(new RegistrationResponse() { Success = true, Token = jwtToken })); } else { return(BadRequest(new RegistrationResponse() { Errors = isCreated.Errors.Select(x => x.Description).ToList(), Success = false })); } } return(BadRequest(new RegistrationResponse() { Errors = new List <string>() { "Invalid payload" }, Success = false })); }
public async Task <IActionResult> SignUp([FromBody] UserRegistrationDto userRegistrationDto) { await _accountService.SignUp(userRegistrationDto.UserName, userRegistrationDto.Email, userRegistrationDto.Password); return(Ok()); }
public async Task <IActionResult> Register([FromBody] UserRegistrationDto user) { if (ModelState.IsValid) { // We can utilise the model var existingUser = await _userManager.FindByEmailAsync(user.Email); if (existingUser != null) { return(BadRequest(new RegistrationResponse() { Errors = new List <string>() { "Email already in use" }, Success = false })); } var newUser = new ApplicationUser() { Email = user.Email, UserName = user.Username, Wallet = new UserWallet() { Balance = 1000 } }; var isCreated = await _userManager.CreateAsync(newUser, user.Password); if (isCreated.Succeeded) { var(jwtAccessToken, jwtRefreshToken) = GenerateJwtTokenPair(newUser); _dbContext.RefreshTokens.Add(jwtRefreshToken); _dbContext.SaveChanges(); return(Ok(new RegistrationResponse() { Success = true, Token = jwtAccessToken, RefreshToken = jwtRefreshToken.Token })); } else { return(BadRequest(new RegistrationResponse() { Errors = isCreated.Errors.Select(x => x.Description).ToList(), Success = false })); } } return(BadRequest(new RegistrationResponse() { Errors = new List <string>() { "Invalid payload" }, Success = false })); }
public async Task <IActionResult> ResendConfirmationEmail([FromBody] UserRegistrationDto model) { await _accountService.ResendConfirmationEmail(model.Email); return(Ok()); }
public async Task <AuthenticationResponse> LoginAsync([FromBody] UserRegistrationDto model) { return(await _accountService.LoginWithPasswordAsync(model.Email, model.Password)); }
public async Task <IActionResult> ResetPassword([FromBody] UserRegistrationDto model) { await _accountService.ResetPassword(model.Email, model.Password, model.Token); return(Ok()); }
public async Task <IActionResult> RequestPasswordReset([FromBody] UserRegistrationDto model) { await _accountService.RequestPasswordReset(model.Email); return(Ok()); }
public async Task <IActionResult> PostUser([FromBody] UserRegistrationDto userDto) { var user = await _userService.CreateUser(userDto.UserName, userDto.Password, userDto.Email); return(Ok(user)); }