-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
35 lines (29 loc) · 844 Bytes
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package auth
import (
"encoding/json"
db "github.com/alexperezortuno/go-auth-with-jwt-redis-postgres/internal/platform/storage/data_base"
"github.com/alexperezortuno/go-auth-with-jwt-redis-postgres/internal/platform/storage/data_base/model"
"log"
)
func UnmarshalAuthRequest(data []byte) (AuthRequest, error) {
var r AuthRequest
err := json.Unmarshal(data, &r)
return r, err
}
func (r *AuthRequest) Marshal() ([]byte, error) {
return json.Marshal(r)
}
type AuthRequest struct {
Email string `json:"email"`
Password string `json:"password"`
}
func ValidateUser(ar AuthRequest) (bool, string) {
user := model.User{}
verifyUser, err := user.ValidUser(db.Connection, ar.Email, ar.Password)
if err != nil {
log.Printf("[ERROR] %s", err.Error())
return false, err.Error()
}
log.Printf("%s", verifyUser)
return true, ""
}