public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Username, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email }; if (model.AvatarFile?.FileName != null) { user.AvatarPath = await _imageService.SaveAvatarImage(model.AvatarFile); } var result = await _service.CreateUser(user, model.Password); if (result.Succeeded) { await _service.Login(user.UserName, model.Password, false); _logger.LogInformation("User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> Register(RegisterUserRequest request) { var userProfile = request.ToUserProfile(); var result = await _authService.CreateUser(userProfile, request.Password); return(result.Succeeded ? StatusCode((int)HttpStatusCode.Created) : GetErrorResult(result)); }