mirror of
https://github.com/ordinary-dev/phoenix
synced 2024-09-19 19:30:28 +05:00
Move the cookie creation function to the correct module
This commit is contained in:
parent
bf4c52e68b
commit
7b34b597c8
|
@ -4,7 +4,6 @@ import (
|
|||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
|
@ -87,11 +86,6 @@ func CreateAccessToken(db *gorm.DB, adminID uint64) (AccessToken, error) {
|
|||
return accessToken, nil
|
||||
}
|
||||
|
||||
// Save token for 29 days in cookies
|
||||
func SetTokenCookie(c *gin.Context, token AccessToken) {
|
||||
c.SetCookie("phoenix-token", token.Value, 60*60*24*29, "/", "", false, true)
|
||||
}
|
||||
|
||||
func ValidateToken(db *gorm.DB, value string) error {
|
||||
var token AccessToken
|
||||
result := db.Where("value = ?", value).First(&token)
|
||||
|
|
|
@ -43,7 +43,7 @@ func CreateUser(c *gin.Context, db *gorm.DB) {
|
|||
ShowError(c, err)
|
||||
return
|
||||
}
|
||||
backend.SetTokenCookie(c, token)
|
||||
SetTokenCookie(c, token)
|
||||
|
||||
// Redirect to homepage.
|
||||
c.Redirect(http.StatusFound, "/")
|
||||
|
@ -65,8 +65,13 @@ func AuthorizeUser(c *gin.Context, db *gorm.DB) {
|
|||
ShowError(c, err)
|
||||
return
|
||||
}
|
||||
backend.SetTokenCookie(c, token)
|
||||
SetTokenCookie(c, token)
|
||||
|
||||
// Redirect to homepage.
|
||||
c.Redirect(http.StatusFound, "/")
|
||||
}
|
||||
|
||||
// Save token for 29 days in cookies
|
||||
func SetTokenCookie(c *gin.Context, token backend.AccessToken) {
|
||||
c.SetCookie("phoenix-token", token.Value, 60*60*24*29, "/", "", false, true)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue