public async Task <IActionResult> Register(UsersRegisterInputModel inputModel) { if (ModelState.IsValid == false) { return(this.View(inputModel)); } var userByEmail = await userManager.FindByEmailAsync(inputModel.Email); var phoneAlreadyTaken = this.usersService.HasUserWithPhoneNumber(inputModel.PhoneNumber); if (userByEmail != null || phoneAlreadyTaken) { TempData[ErrorMessages.UserAlreadyExists] = ErrorMessages.UserAlreadyExists; return(this.View(inputModel)); } var newUser = new User { UserName = inputModel.Email, Email = inputModel.Email, PhoneNumber = inputModel.PhoneNumber, }; var result = await userManager.CreateAsync(newUser, inputModel.Password); if (result.Succeeded == false) { return(this.View(inputModel)); } return(this.RedirectToAction(nameof(Login))); }
public IActionResult Register(UsersRegisterInputModel inputModel) { if (inputModel.Password != inputModel.ConfirmPassword) { return(this.Redirect("/Users/Register")); } this.userService.AddNewUserToDb(inputModel.Username, inputModel.Password, inputModel.Email); return(this.Redirect("/Users/Login")); }
public void CreateUser(UsersRegisterInputModel input) { var user = new User { Username = input.Username, Email = input.Email, Password = this.Hash(input.Password), }; this.db.Add(user); this.db.SaveChanges(); }
public async Task <ActionResult <object> > Register(UsersRegisterInputModel inputModel) { var user = await this.usersService.RegisterAsync(inputModel.Email, inputModel.Password); var response = new { user.Id, user.Email, user.CreatedOn }; return(response); }
public IActionResult Register(UsersRegisterInputModel model) { if (!this.ModelState.IsValid) { return(this.Redirect("/Users/Register")); } if (model.Password != model.ConfirmPassword) { return(this.Redirect("/Users/Register")); } this.usersService.CreateUser(model.Username, model.Email, model.Password); return(this.Redirect("/Users/Login")); }
public IActionResult Register(UsersRegisterInputModel input) { if (!this.ModelState.IsValid) { return(this.Redirect("/Users/Register")); } if (input.Password != input.ConfirmPassword) { return(this.Redirect("/Users/Register")); } var userId = this.usersService.CreateNewUser(input.Username, input.Email, input.Password); this.SignIn(userId, input.Username, input.Email); return(this.Redirect("/")); }
public HttpResponse Register(UsersRegisterInputModel input) { if (this.IsUserLoggedIn()) { return(this.Error("You are already logged in!")); } if (input.Password != input.ConfirmPassword || input.Username.Length <= 4 || input.Username.Length >= 10 || input.Password.Length <= 6 || input.Password.Length >= 20 || this.usersService.IsUsernameUsed(input.Username) || this.usersService.IsEmailUsed(input.Email)) { return(this.Redirect("/Users/Register")); } this.usersService.CreateUser(input); return(this.Redirect("/")); }
public IActionResult Register(UsersRegisterInputModel model) { if (!ModelState.IsValid) { return(this.Redirect("/Users/Register")); } if (model.Password != model.ConfirmPassword) { return(this.Redirect("/Users/Register")); } User currentUser = ModelMapper.ProjectTo <User>(model); var id = this.usersService.Create(currentUser); if (id == null) { ModelState.Add("User", "User with this username already exists! Please choose another username."); return(this.Redirect("/Users/Register")); } return(this.Redirect("/Users/Login")); }