feat: добавил отправку уведомлений по почте
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 10s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 1m17s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 12s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 6s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 10s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 1m17s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 12s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 6s
This commit is contained in:
@@ -40,7 +40,7 @@ public class AuthController : ControllerBase
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<ActionResult<AuthResponse>> LoginMicrosoft([FromBody] LoginMicrosoftRequest request)
|
||||
{
|
||||
var result = await _auth.LoginWithMicrosoftAsync(request.AuthorizationCode, request.RedirectUri);
|
||||
var result = await _auth.LoginWithMicrosoftAsync(request.AuthorizationCode, request.RedirectUri, GetClientIpAddress());
|
||||
SetRefreshTokenCookie(result.RefreshToken);
|
||||
return Ok(result.Response);
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public class AuthController : ControllerBase
|
||||
|
||||
var redirectUri = _config["AzureAd:RedirectUri"] ?? BuildAbsoluteUrl("/api/v1/auth/callback/microsoft");
|
||||
|
||||
var result = await _auth.LoginWithMicrosoftAsync(code, redirectUri);
|
||||
var result = await _auth.LoginWithMicrosoftAsync(code, redirectUri, GetClientIpAddress());
|
||||
SetRefreshTokenCookie(result.RefreshToken);
|
||||
|
||||
var returnUrl = Request.Cookies[MicrosoftReturnUrlCookieName] ?? _config["AzureAd:PostLoginRedirectUri"];
|
||||
@@ -184,7 +184,7 @@ public class AuthController : ControllerBase
|
||||
{
|
||||
if (!HttpContext.RequestServices.GetRequiredService<IWebHostEnvironment>().IsDevelopment())
|
||||
return NotFound();
|
||||
var result = await _auth.DevLoginAsync(request.Email, request.DisplayName, request.Role);
|
||||
var result = await _auth.DevLoginAsync(request.Email, request.DisplayName, request.Role, GetClientIpAddress());
|
||||
SetRefreshTokenCookie(result.RefreshToken);
|
||||
return Ok(result.Response);
|
||||
}
|
||||
@@ -245,6 +245,21 @@ public class AuthController : ControllerBase
|
||||
return Ok(user);
|
||||
}
|
||||
|
||||
private string? GetClientIpAddress()
|
||||
{
|
||||
if (Request.Headers.TryGetValue("X-Forwarded-For", out var forwardedFor))
|
||||
{
|
||||
var firstForwardedAddress = forwardedFor.ToString().Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
|
||||
if (!string.IsNullOrWhiteSpace(firstForwardedAddress))
|
||||
return firstForwardedAddress;
|
||||
}
|
||||
|
||||
if (Request.Headers.TryGetValue("X-Real-IP", out var realIp) && !string.IsNullOrWhiteSpace(realIp))
|
||||
return realIp;
|
||||
|
||||
return HttpContext.Connection.RemoteIpAddress?.ToString();
|
||||
}
|
||||
|
||||
private void SetRefreshTokenCookie(string token)
|
||||
{
|
||||
Response.Cookies.Append("refreshToken", token, new CookieOptions
|
||||
|
||||
Reference in New Issue
Block a user