Added some routes for users
And some fixes
This commit is contained in:
@@ -61,12 +61,18 @@ func HandleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var user core.User
|
||||
err = core.DB.NewSelect().
|
||||
count, err := core.DB.NewSelect().
|
||||
Model(&user).
|
||||
Where("email = ? AND password = ?", login.Email, login.Password).
|
||||
Limit(1).
|
||||
Scan(context.Background())
|
||||
|
||||
ScanAndCount(context.Background())
|
||||
if count == 0 {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
Message: "User not found.",
|
||||
}.Respond(w, http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
@@ -86,7 +92,7 @@ func HandleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
signed, err := token.SignedString([]byte("hello"))
|
||||
signed, err := token.SignedString(MySigningKey)
|
||||
if err != nil {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
@@ -98,14 +104,13 @@ func HandleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
core.JSONSuccess{
|
||||
Status: core.Success,
|
||||
Message: "JWT Created",
|
||||
Data: map[string]string{"jwt": signed},
|
||||
Data: signed,
|
||||
}.Respond(w, http.StatusCreated)
|
||||
}
|
||||
|
||||
func AuthJWT(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// Check if the Authorization header is provided
|
||||
fmt.Println("Coucou")
|
||||
authHeader := r.Header.Get("Authorization")
|
||||
if authHeader == "" {
|
||||
core.JSONError{
|
||||
|
||||
Reference in New Issue
Block a user