// AdminOnly rejects user with invalid loginToken
// Stores username in context

AdminOnly rejects user with invalid loginToken
Stores username in context
// AdminOnly rejects user with invalid loginToken // Stores username in context
func AdminOnly(s sessions.Store, loggedDB db.LoggedDB) func(h http.Handler) http.Handler {
	return func(h http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			session, err := sess.GetSessionFromStore(s, r)
			if err != nil {
				httputil.WriteSessionError(w)
				return
			}
			username, err := sess.GetUserName(session)
			if err != nil {
				httputil.WriteSessionError(w)
				return
			}
			loggedU, err := loggedDB.Get(username)
			if err != nil {
				httputil.WriteError(w, er.ErrNotLogged, http.StatusBadRequest)
				return
			}
			if loggedU.Verified && loggedU.Admin {
				r = r.WithContext(sess.SetUserNameIntoCtx(r.Context(), username))
				h.ServeHTTP(w, r)
			}
		})
	}
}
func AdminOnly ( s sessions . Store , loggedDB db . LoggedDB ) func ( h http . Handler ) http . Handler { return func ( h http . Handler ) http . Handler { return http . HandlerFunc ( func ( w http . ResponseWriter , r * http . Request ) { session , err := sess . GetSessionFromStore ( s , r ) if err != nil { httputil . WriteSessionError ( w ) return } username , err := sess . GetUserName ( session ) if err != nil { httputil . WriteSessionError ( w ) return } loggedU , err := loggedDB . Get ( username ) if err != nil { httputil . WriteError ( w , er . ErrNotLogged , http . StatusBadRequest ) return } if loggedU . Verified && loggedU . Admin { r = r . WithContext ( sess . SetUserNameIntoCtx ( r . Context ( ) , username ) ) h . ServeHTTP ( w , r ) } } ) } }
AdminOnly rejects user with invalid loginToken
Stores username in context
AdminOnly rejects user with invalid loginToken Stores username in context