forked from nixcn/nixcn-cms
Checkin time data column, checkin module
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"nixcn-cms/data"
|
||||
"nixcn-cms/internal/crypto/jwt"
|
||||
"nixcn-cms/pkgs/magiclink"
|
||||
"nixcn-cms/pkgs/turnstile"
|
||||
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -68,8 +69,12 @@ func VerifyMagicLink(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Generate jwt
|
||||
uuid, _ := uuid.NewUUID()
|
||||
jwtToken, _ := jwt.GenerateToken(uuid, "application")
|
||||
userInfo := new(data.User)
|
||||
err := userInfo.GetByEmail(email)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"status": "user not found"})
|
||||
}
|
||||
jwtToken, _ := jwt.GenerateToken(userInfo.UserId, "application")
|
||||
|
||||
c.JSON(200, gin.H{
|
||||
"jwt_token": jwtToken,
|
||||
|
||||
@@ -3,6 +3,7 @@ package checkin
|
||||
import (
|
||||
"net/http"
|
||||
"nixcn-cms/data"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
@@ -17,7 +18,7 @@ func Checkin(ctx *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
data.SetCheckinState(userId.(uuid.UUID), true)
|
||||
data.SetCheckinState(userId.(uuid.UUID), time.Now())
|
||||
ctx.JSON(http.StatusOK, gin.H{
|
||||
"status": "success",
|
||||
})
|
||||
|
||||
@@ -8,4 +8,5 @@ import (
|
||||
|
||||
func Handler(r *gin.RouterGroup) {
|
||||
r.Use(jwt.JWTAuth())
|
||||
r.POST("", Checkin)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user