Skip to content

Commit

Permalink
updated auth endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
BK1031 committed Aug 30, 2024
1 parent 9fdc543 commit 6a1e4c1
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions controller/auth_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func GetJWKS(c *gin.Context) {
}

func RegisterAccountPassword(c *gin.Context) {
RequireAny(c, RequestTokenHasScope(c, "sentinel:all"))
Require(c, RequestTokenHasScope(c, "sentinel:all"))

var input model.UserAuth
if err := c.ShouldBindJSON(&input); err != nil {
Expand All @@ -27,7 +27,8 @@ func RegisterAccountPassword(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"message": "No account with this email exists. Make sure to verify your account on the discord server first!"})
return
}
RequireAny(c, RequestUserHasID(c, user.ID), RequestUserHasRole(c, "d_admin"))

Require(c, Any(RequestUserHasID(c, user.ID), RequestUserHasRole(c, "d_admin")))

token, err := service.RegisterEmailPassword(input.Email, input.Password)
if err != nil {
Expand Down Expand Up @@ -55,7 +56,7 @@ func RegisterAccountPassword(c *gin.Context) {
}

func ResetAccountPassword(c *gin.Context) {
RequireAny(c, RequestTokenHasScope(c, "sentinel:all"))
Require(c, RequestTokenHasScope(c, "sentinel:all"))

userID := c.Param("userID")
user := service.GetUserByID(userID)
Expand All @@ -64,7 +65,7 @@ func ResetAccountPassword(c *gin.Context) {
return
}

RequireAny(c, RequestUserHasID(c, user.ID), RequestUserHasRole(c, "d_admin"))
Require(c, Any(RequestUserHasID(c, user.ID), RequestUserHasRole(c, "d_admin")))

auth := service.GetUserAuthByID(userID)
if auth.ID == "" {
Expand Down Expand Up @@ -154,8 +155,10 @@ func LoginDiscord(c *gin.Context) {
}

func GetAuthForUser(c *gin.Context) {
RequireAny(c, RequestTokenHasScope(c, "sentinel:all"))
RequireAny(c, RequestUserHasID(c, c.Param("userID")), RequestUserHasRole(c, "d_admin"))
Require(c, All(
RequestTokenHasScope(c, "sentinel:all"),
Any(RequestUserHasID(c, c.Param("userID")), RequestUserHasRole(c, "d_admin")),
))

userID := c.Param("userID")
user := service.GetUserByID(userID)
Expand Down

0 comments on commit 6a1e4c1

Please sign in to comment.