Initial commit: dating app backend (Go/Gin/GORM/Postgres)
Phone+OTP auth, staged onboarding, admin approval workflow, and a full discovery/swipe/match/chat system with photo upload and approximate distance (haversine) based on user location. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"dating-app/internal/models"
|
||||
"dating-app/internal/utils"
|
||||
)
|
||||
|
||||
// AdminRequired باید بعد از AuthRequired استفاده بشه. فقط کاربرانی که IsAdmin=true
|
||||
// دارن اجازهی عبور دارن.
|
||||
func AdminRequired() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
userVal, exists := c.Get(ContextUserKey)
|
||||
if !exists {
|
||||
utils.Fail(c, http.StatusUnauthorized, "احراز هویت لازم است", nil)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
user, ok := userVal.(*models.User)
|
||||
if !ok || !user.IsAdmin {
|
||||
utils.Fail(c, http.StatusForbidden, "دسترسی فقط برای ادمین است", nil)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user