public async Task <IActionResult> SignUp(SignUpViewModel model) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Logs", "Home")); } if (!ModelState.IsValid) { return(View(model)); } AppUser u = new() { Email = model.Email, UserName = model.UserName, DailyTarget = model.DailyTarget }; var res = await _appUsersService.CreateAsync(u, model.Password); if (res.Succeeded) { _signinService.SessionLogin(u); return(RedirectToAction("Logs", "Home")); } else { res.Errors.ForEach(e => ModelState.AddModelError("", e)); return(View(model)); } }
public async Task <IActionResult> CreateNewUser(NewUserModel userModel) { if (ModelState.IsValid == false) { return(ValidationProblem()); } string passwordSalt = _cryptoService.GenerateRandomSalt(); string hashedPassword = _cryptoService.SaltAndHashText(defaultPassword, passwordSalt); int userId = await _appUsersService.CreateAsync(userModel, passwordSalt, hashedPassword); return(Created("api/AppUser", userId)); }