public async Task <IActionResult> Register(UserRegisterViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } // Verify not logged in GetPrivateUserModel privateUser = await new GetAuthenticatedUserQuery().DefaultIfExceptionAsync(Mediator); if (privateUser != null && privateUser.Id > 0) { return(RedirectToAction("Login")); } // Regiser User registeredUser = await Mediator.Send(new RegisterUserCommand(viewModel.RegisterModel)); // Login var loginModel = new LoginModel { UserName = registeredUser.UserName, Password = viewModel.RegisterModel.Password }; await _userAuthService.LogInAsync(loginModel); // Attatch image if present var file = Request.Form.Files.FirstOrDefault(); if (file != null) { PostImageModel imageModel = _imageFileReader.ConvertImageFileToImageModel(file); await Mediator.Send(new AddUserImageCommand(imageModel, registeredUser.Id)); } return(RedirectToAction("Me")); }
public async Task <IActionResult> Login([FromBody] UserSignInDto userDto) { var result = await _userAuthService.LogInAsync(userDto); return(Json(result)); }