feat: login service and implement database storage

This commit is contained in:
ericprd
2025-02-23 22:34:26 +08:00
parent a95a5ca521
commit 5fcb5c2cd5
24 changed files with 576 additions and 8 deletions
+21
View File
@@ -0,0 +1,21 @@
package utils
import (
"encoding/json"
"io"
"net/http"
)
func UnmarshalBody(r *http.Request, v any) error {
body, err := io.ReadAll(r.Body)
if err != nil {
return err
}
err = json.Unmarshal(body, v)
if err != nil {
return err
}
return nil
}
+3 -3
View File
@@ -28,11 +28,11 @@ func GenerateToken(options ...ClaimOption) (string, error) {
return token.SignedString(jwtSecret)
}
func GenerateToken2(username string) (string, error) {
func GenerateToken2(email string) (string, error) {
now := timeutils.Now()
token := jwt.New(jwt.SigningMethodES256)
token := jwt.New(jwt.SigningMethodHS256)
claims := token.Claims.(jwt.MapClaims)
claims["username"] = username
claims["email"] = email
claims["exp"] = now.Add(time.Hour).Unix()
return token.SignedString(jwtSecret)