@@ -78,49 +78,49 @@ func AdminCookieValue(user core.User) (string, error) {
7878// AdminAuthHandler Authorization for /admin
7979func AdminAuthHandler () gin.HandlerFunc {
8080 return func (c * gin.Context ) {
81+
8182 user , err := c .Cookie ("ohUrlShortenerAdmin" )
8283 if err != nil {
83- c .AbortWithStatus (http .StatusUnauthorized )
84- // c.AbortWithError(http.StatusFound, err)
85- return
84+ c .Redirect (http .StatusFound , "/login" )
85+ c .Next ()
8686 }
8787
8888 cookie , err := c .Cookie ("ohUrlShortenerCookie" )
8989 if err != nil {
90- c .AbortWithStatus (http .StatusUnauthorized )
91- // c.Redirect(http.StatusFound, "/login" )
90+ c .Redirect (http .StatusFound , "/login" )
91+ c . Next ( )
9292 return
9393 }
9494
9595 if len (user ) <= 0 || len (cookie ) <= 0 {
96- c .AbortWithStatus (http .StatusUnauthorized )
97- // c.Redirect(http.StatusFound, "/login" )
96+ c .Redirect (http .StatusFound , "/login" )
97+ c . Next ( )
9898 return
9999 }
100100
101101 found , err := service .GetUserByAccountFromRedis (user )
102102 if err != nil {
103- c .AbortWithStatus (http .StatusUnauthorized )
104- // c.Redirect(http.StatusFound, "/login" )
103+ c .Redirect (http .StatusFound , "/login" )
104+ c . Next ( )
105105 return
106106 }
107107
108108 if found .IsEmpty () {
109- c .AbortWithStatus (http .StatusUnauthorized )
110- // c.Redirect(http.StatusFound, "/login" )
109+ c .Redirect (http .StatusFound , "/login" )
110+ c . Next ( )
111111 return
112112 }
113113
114114 cValue , err := AdminCookieValue (found )
115115 if err != nil {
116- c .AbortWithStatus (http .StatusUnauthorized )
117- // c.Redirect(http.StatusFound, "/login" )
116+ c .Redirect (http .StatusFound , "/login" )
117+ c . Next ( )
118118 return
119119 }
120120
121121 if ! strings .EqualFold (cValue , cookie ) {
122- c .AbortWithStatus (http .StatusUnauthorized )
123- // c.Redirect(http.StatusFound, "/login" )
122+ c .Redirect (http .StatusFound , "/login" )
123+ c . Next ( )
124124 return
125125 }
126126
0 commit comments