forked from nixcn/nixcn-cms
Impl magic login logic && checkin logic
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"nixcn-cms/internal/crypto/jwt"
|
||||
"nixcn-cms/pkgs/magiclink"
|
||||
"nixcn-cms/pkgs/turnstile"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -35,7 +34,7 @@ func RequestMagicLink(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Generate magic token
|
||||
token, err := magiclink.NewMagicToken(req.Email, 15*time.Minute)
|
||||
token, err := magiclink.NewMagicToken(req.Email)
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{"error": "internal error"})
|
||||
return
|
||||
|
||||
24
service/checkin/checkin.go
Normal file
24
service/checkin/checkin.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package checkin
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"nixcn-cms/data"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func Checkin(ctx *gin.Context) {
|
||||
data := new(data.User)
|
||||
userId, ok := ctx.Get("user_id")
|
||||
if !ok {
|
||||
ctx.JSON(http.StatusUnauthorized, gin.H{
|
||||
"status": "unauthorized",
|
||||
})
|
||||
return
|
||||
}
|
||||
data.SetCheckinState(userId.(uuid.UUID), true)
|
||||
ctx.JSON(http.StatusOK, gin.H{
|
||||
"status": "success",
|
||||
})
|
||||
}
|
||||
11
service/info/handler.go
Normal file
11
service/info/handler.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package info
|
||||
|
||||
import (
|
||||
"nixcn-cms/internal/crypto/jwt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Handler(r *gin.RouterGroup) {
|
||||
r.Use(jwt.JWTAuth())
|
||||
}
|
||||
1
service/info/userinfo.go
Normal file
1
service/info/userinfo.go
Normal file
@@ -0,0 +1 @@
|
||||
package info
|
||||
Reference in New Issue
Block a user