31 lines
555 B
Go
31 lines
555 B
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"xboard-go/internal/database"
|
|
"xboard-go/internal/model"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func Subscribe(c *gin.Context) {
|
|
token := c.Param("token")
|
|
if token == "" {
|
|
Fail(c, http.StatusForbidden, "token is required")
|
|
return
|
|
}
|
|
|
|
var user model.User
|
|
if err := database.DB.Where("token = ?", token).First(&user).Error; err != nil {
|
|
Fail(c, http.StatusForbidden, "invalid token")
|
|
return
|
|
}
|
|
|
|
if user.Banned {
|
|
Fail(c, http.StatusForbidden, "account is banned")
|
|
return
|
|
}
|
|
|
|
FulfillSubscription(c, &user)
|
|
}
|