Kaynağa Gözat

Added endpoint for gmail login

feature/added_google_login
Safet Purkovic 3 yıl önce
ebeveyn
işleme
6819f79b4e

+ 1
- 0
Diligent.WebAPI.Business/Services/Interfaces/IUserService.cs Dosyayı Görüntüle

@@ -3,6 +3,7 @@
public interface IUserService
{
Task<ServiceResponseDTO<AuthenticateResponseDto>> Authenticate(AuthenticateRequestDto model);
Task<ServiceResponseDTO<AuthenticateResponseDto>> Authenticate(string email);

Task<RefreshTokenResultDto> RefreshTokenAsync(RefreshTokenRequestDto model);


+ 33
- 18
Diligent.WebAPI.Business/Services/UserService.cs Dosyayı Görüntüle

@@ -44,30 +44,12 @@ namespace Diligent.WebAPI.Business.Services
};
}

var isLocked = await _userManager.IsLockedOutAsync(user);

if (isLocked)
return new ServiceResponseDTO<AuthenticateResponseDto>
{
IsError = true,
ErrorMessage = "The account is locked out"
};

var result = await _userManager.CheckPasswordAsync(user, model.Password);

// password is not correct
if (!result)
{
await _userManager.AccessFailedAsync(user);
isLocked = await _userManager.IsLockedOutAsync(user);
if(isLocked)
return new ServiceResponseDTO<AuthenticateResponseDto>
{
IsError = true,
ErrorMessage = "The account is locked out"
};

return new ServiceResponseDTO<AuthenticateResponseDto>
{
@@ -76,6 +58,39 @@ namespace Diligent.WebAPI.Business.Services
};
}

return await GenerateToken(user);
}
public async Task<ServiceResponseDTO<AuthenticateResponseDto>> Authenticate(string email)
{
var user = await _userManager.FindByEmailAsync(email);

// return null if user not found
if (user == null)
{
return new ServiceResponseDTO<AuthenticateResponseDto>
{
IsError = true,
ErrorMessage = $"User with email {email} does not exist in database"
};
}

return await GenerateToken(user);
}

private async Task<ServiceResponseDTO<AuthenticateResponseDto>> GenerateToken(User user)
{
var isLocked = await _userManager.IsLockedOutAsync(user);

if (isLocked)
return new ServiceResponseDTO<AuthenticateResponseDto>
{
IsError = true,
ErrorMessage = "The account is locked out"
};



// authentication successful so generate jwt token
var token = await GenerateJwtToken(user, true);


+ 10
- 0
Diligent.WebAPI.Host/Controllers/V1/UsersController.cs Dosyayı Görüntüle

@@ -63,5 +63,15 @@

return Ok();
}
[HttpGet("authenticateGoogle")]
public async Task<IActionResult> GoogleLogin(string email)
{
var response = await _userService.Authenticate(email);

if (response.IsError is true)
return BadRequest(new { message = response.ErrorMessage });

return Ok(response.Data);
}
}
}

Loading…
İptal
Kaydet