fix view
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"database/sql"
|
||||
"encoding/base64"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -84,7 +85,17 @@ func (s *Server) CSRFRequire() gin.HandlerFunc {
|
||||
func (s *Server) RequireAuth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if _, exists := c.Get("user_id"); !exists {
|
||||
c.Redirect(http.StatusFound, s.config.URLPrefix+"/editor/login")
|
||||
// Attach return_to so user can be redirected back after login
|
||||
requested := c.Request.URL.RequestURI()
|
||||
q := url.Values{}
|
||||
if requested != "" {
|
||||
q.Set("return_to", requested)
|
||||
}
|
||||
loginURL := s.config.URLPrefix + "/editor/login"
|
||||
if qs := q.Encode(); qs != "" {
|
||||
loginURL = loginURL + "?" + qs
|
||||
}
|
||||
c.Redirect(http.StatusFound, loginURL)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@@ -96,7 +107,16 @@ func (s *Server) RequireAuth() gin.HandlerFunc {
|
||||
func (s *Server) RequireAdmin() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if _, exists := c.Get("user_id"); !exists {
|
||||
c.Redirect(http.StatusFound, s.config.URLPrefix+"/editor/login")
|
||||
requested := c.Request.URL.RequestURI()
|
||||
q := url.Values{}
|
||||
if requested != "" {
|
||||
q.Set("return_to", requested)
|
||||
}
|
||||
loginURL := s.config.URLPrefix + "/editor/login"
|
||||
if qs := q.Encode(); qs != "" {
|
||||
loginURL = loginURL + "?" + qs
|
||||
}
|
||||
c.Redirect(http.StatusFound, loginURL)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user