File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed
Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ using Microsoft . AspNetCore . Mvc ;
2+ using OsmoDoc . API . Models ;
3+ using OsmoDoc . API . Helpers ;
4+ using Microsoft . AspNetCore . Authorization ;
5+
6+ namespace OsmoDoc . API . Controllers ;
7+
8+ [ Route ( "api" ) ]
9+ [ ApiController ]
10+ public class LoginController : ControllerBase
11+ {
12+ private readonly ILogger < LoginController > _logger ;
13+
14+ public LoginController ( ILogger < LoginController > logger )
15+ {
16+ this . _logger = logger ;
17+ }
18+
19+ [ HttpPost ]
20+ [ Route ( "login" ) ]
21+ [ AllowAnonymous ]
22+ public ActionResult < BaseResponse > Login ( [ FromBody ] LoginRequestDTO loginRequest )
23+ {
24+ BaseResponse response = new BaseResponse ( ResponseStatus . Fail ) ;
25+ try
26+ {
27+ string token = AuthenticationHelper . JwtTokenGenerator ( loginRequest . Email ) ;
28+
29+ response . Status = ResponseStatus . Success ;
30+ response . AuthToken = token ;
31+ response . Message = "Token generated successfully" ;
32+ return this . Ok ( response ) ;
33+ }
34+ catch ( Exception ex )
35+ {
36+ response . Status = ResponseStatus . Error ;
37+ response . Message = ex . Message ;
38+ this . _logger . LogError ( ex . Message ) ;
39+ this . _logger . LogError ( ex . StackTrace ) ;
40+ return this . StatusCode ( StatusCodes . Status500InternalServerError , response ) ;
41+ }
42+ }
43+ }
Original file line number Diff line number Diff line change 1+ using System . ComponentModel . DataAnnotations ;
2+
3+ namespace OsmoDoc . API . Models ;
4+
5+ public class LoginRequestDTO
6+ {
7+ [ Required ( ErrorMessage = "Email is required" ) ]
8+ [ EmailAddress ( ErrorMessage = "Invalid email format" ) ]
9+ public string Email { get ; set ; } = string . Empty ;
10+ }
You can’t perform that action at this time.
0 commit comments