public async Task <IActionResult> RegisterAsync([FromBody] AccountRequest accountRequest) { AccountBl accountBl = _mapper.Map <AccountBl>(accountRequest); AccountBl registerAccountBl = await _accountService.RegisterAsync(accountBl); if (registerAccountBl == null) { return(BadRequest()); } Account registerAccount = _mapper.Map <Account>(registerAccountBl); string token = _jwtService.CreateTokenAsync(registerAccount); AccountResponse accountResponse = new AccountResponse( registerAccount.Id, registerAccount.FirstName, registerAccount.SecondName, registerAccount.Email, registerAccount.Password, (int)registerAccount.Role, token ); return(Ok(accountResponse)); }
public async Task <IActionResult> LoginUsingGoogleAsync(string tokenId) { if (string.IsNullOrEmpty(tokenId)) { return(BadRequest()); } GoogleJsonWebSignature.Payload payload; try { payload = await GoogleJsonWebSignature.ValidateAsync(tokenId); } catch { return(BadRequest()); } AccountRequest authAccount = new AccountRequest() { Email = payload.Email }; AccountBl authAccountBl = _mapper.Map <AccountBl>(authAccount); AccountBl accountBl = await _accountService.ExternalLoginAsync(authAccountBl); if (accountBl == null) { return(BadRequest()); } Account account = _mapper.Map <Account>(accountBl); string token = _jwtService.CreateTokenAsync(account); AccountResponse accountResponse = new AccountResponse( account.Id, account.FirstName, account.SecondName, account.Email, account.Password, (int)account.Role, token ); return(Ok(accountResponse)); }
public async Task <IActionResult> RegisterWithGoogleAsync(string tokenId) { if (string.IsNullOrEmpty(tokenId)) { return(BadRequest()); } GoogleJsonWebSignature.Payload payload; try { payload = await GoogleJsonWebSignature.ValidateAsync(tokenId); } catch { return(BadRequest()); } AccountBl accountBl = new AccountBl() { FirstName = payload.GivenName, SecondName = payload.FamilyName, Email = payload.Email }; AccountBl registerAccountBl = await _accountService.RegisterAsync(accountBl); if (registerAccountBl == null) { return(BadRequest()); } Account registerAccount = _mapper.Map <Account>(registerAccountBl); string token = _jwtService.CreateTokenAsync(registerAccount); AccountResponse accountResponse = new AccountResponse( registerAccount.Id, registerAccount.FirstName, registerAccount.SecondName, registerAccount.Email, registerAccount.Password, (int)registerAccount.Role, token ); return(Ok(accountResponse)); }