public async Task <LoginAuthResponseView> Register(RegisterAuthView model) { User user = new User { UserName = model.Email, Email = model.Email, Age = model.Age, FirstName = model.FirstName, LastName = model.LastName }; if (model.Photo != null) { user.Photo = _imageProvider.ResizeAndSave(model.Photo, Constants.FilePaths.UserAvatarImages, $"{user.Id}.png", Constants.DefaultIconSizes.MaxWidthOriginalImage, Constants.DefaultIconSizes.MaxHeightOriginalImage); } IdentityResult result = await _userManager.CreateAsync(user, model.Password); if (!result.Succeeded) { throw new Exception("Registration is not complete"); } string encodedJwt = await _jwtProvider.GenerateJwtToken(user); LoginAuthResponseView response = new LoginAuthResponseView { Token = encodedJwt }; return(response); }
public async Task <LoginAuthResponseView> Login(LoginAuthView model) { SignInResult result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, false, false); if (!result.Succeeded) { throw new Exception("Invalid Login or password"); } var user = await _userManager.FindByEmailAsync(model.Email); var encodedJwt = await _jwtProvider.GenerateJwtToken(user); var response = new LoginAuthResponseView() { Token = encodedJwt }; return(response); }