IdentityServiceResult.cs
1,917 bytes
| 1 | namespace App.BLL.Services.Identity; |
|---|---|
| 2 | |
| 3 | public class IdentityServiceResult |
| 4 | { |
| 5 | public bool Success { get; init; } |
| 6 | public string? Error { get; init; } |
| 7 | public IdentityServiceErrorKind ErrorKind { get; init; } = IdentityServiceErrorKind.None; |
| 8 | public IdentityJwtPayload? Payload { get; init; } |
| 9 | public int? TokensDeleted { get; init; } |
| 10 | |
| 11 | public static IdentityServiceResult Ok(IdentityJwtPayload payload) => |
| 12 | new() { Success = true, Payload = payload }; |
| 13 | |
| 14 | public static IdentityServiceResult Logout(int tokensDeleted) => |
| 15 | new() { Success = true, TokensDeleted = tokensDeleted }; |
| 16 | |
| 17 | public static IdentityServiceResult Fail(string error, IdentityServiceErrorKind kind) => |
| 18 | new() { Success = false, Error = error, ErrorKind = kind }; |
| 19 | } |
| 20 | |
| 21 | public enum IdentityServiceErrorKind |
| 22 | { |
| 23 | None = 0, |
| 24 | BadRequest = 400, |
| 25 | NotFound = 404 |
| 26 | } |
| 27 | |
| 28 | public class IdentityJwtPayload |
| 29 | { |
| 30 | public string Jwt { get; init; } = default!; |
| 31 | public string RefreshToken { get; init; } = default!; |
| 32 | public string FirstName { get; init; } = default!; |
| 33 | public string LastName { get; init; } = default!; |
| 34 | } |
| 35 | |
| 36 | public class RegisterRequest |
| 37 | { |
| 38 | public string Email { get; init; } = default!; |
| 39 | public string Password { get; init; } = default!; |
| 40 | public string FirstName { get; init; } = default!; |
| 41 | public string LastName { get; init; } = default!; |
| 42 | public int ExpiresInSeconds { get; init; } |
| 43 | } |
| 44 | |
| 45 | public class LoginRequest |
| 46 | { |
| 47 | public string Email { get; init; } = default!; |
| 48 | public string Password { get; init; } = default!; |
| 49 | public int ExpiresInSeconds { get; init; } |
| 50 | } |
| 51 | |
| 52 | public class RefreshRequest |
| 53 | { |
| 54 | public string Jwt { get; init; } = default!; |
| 55 | public string RefreshToken { get; init; } = default!; |
| 56 | public int ExpiresInSeconds { get; init; } |
| 57 | } |
| 58 | |
| 59 | public class LogoutRequest |
| 60 | { |
| 61 | public Guid UserId { get; init; } |
| 62 | public string RefreshToken { get; init; } = default!; |
| 63 | } |
| 64 | |