public HttpResponse Register(InputRegisterViewModel input) { if (this.IsUserSignedIn()) { return(this.Redirect("/")); } if (string.IsNullOrWhiteSpace(input.Username) || input.Username.Length < 5 || input.Username.Length > 20) { return(this.Error("Invalid username.")); } if (string.IsNullOrWhiteSpace(input.Password) || input.Password.Length < 6 || input.Password.Length > 20) { return(this.Error("Invalid password")); } if (input.Password != input.ConfirmPassword) { return(this.Error("No match passwords.")); } this.usersService.CreateUser(input.Username, input.Email, input.Password); return(this.Redirect("/Users/Login")); }
public async Task <IActionResult> Register(InputRegisterViewModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } await this._usersService.CreateUser(model); return(this.RedirectToAction("Index", "Home", new { area = "" })); }
public async Task <IdentityResult> CreateUser(InputRegisterViewModel model) { var user = this._autoMapper.Map <User>(model); var result = await this.UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await this.UserManager.AddToRoleAsync(user, GlobalConstants.UserRoleText); await this.SignInManager.PasswordSignInAsync(user, model.Password, model.RememberMe, false); return(result); } return(result); }