@@ -3,6 +3,7 @@ package controllers
3
3
import (
4
4
"api.jwt.auth/api/parameters"
5
5
"api.jwt.auth/core/authentication"
6
+ "api.jwt.auth/services"
6
7
"api.jwt.auth/services/models"
7
8
"encoding/json"
8
9
"fmt"
@@ -11,24 +12,14 @@ import (
11
12
)
12
13
13
14
func Login (w http.ResponseWriter , r * http.Request ) {
14
- request_user := new (models.User )
15
+ requestUser := new (models.User )
15
16
decoder := json .NewDecoder (r .Body )
16
- decoder .Decode (& request_user )
17
+ decoder .Decode (& requestUser )
17
18
18
- authBackend := authentication .InitJWTAuthenticationBackend ()
19
-
20
- if authBackend .Authenticate (request_user ) {
21
- token := parameters.TokenAuthentication {authBackend .GenerateToken ()}
22
- response , _ := json .Marshal (token )
23
- w .Header ().Set ("Content-Type" , "application/json" )
24
- w .WriteHeader (http .StatusOK )
25
- w .Write (response )
26
-
27
- } else {
28
- w .Header ().Set ("Content-Type" , "application/json" )
29
- w .WriteHeader (http .StatusUnauthorized )
30
- w .Write ([]byte ("Unauthorized" ))
31
- }
19
+ responseStatus , token := services .Login (requestUser )
20
+ w .Header ().Set ("Content-Type" , "application/json" )
21
+ w .WriteHeader (responseStatus )
22
+ w .Write (token )
32
23
}
33
24
34
25
func RefresfhToken (w http.ResponseWriter , r * http.Request , next http.HandlerFunc ) {
0 commit comments