"github.com/dchest/passwordreset"
"github.com/gin-gonic/gin"
- "immae.eu/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front/db"
+ "git.immae.eu/Cryptoportfolio/Front.git/db"
)
const (
return nil
}
+func UserIsAdmin(c *gin.Context) *Error {
+ user, exists := c.Get("user")
+
+ if !exists {
+ return &Error{NotAuthorized, "not authorized", fmt.Errorf("no user key in context")}
+ }
+
+ if user.(db.User).Role != db.RoleAdmin {
+ return &Error{NotAuthorized, "not authorized", fmt.Errorf("user '%v' is not admin", user)}
+ }
+
+ return nil
+}
+
func GetUser(c *gin.Context) db.User {
user, _ := c.Get("user")
}
type SignResult struct {
- Token string `json:"token"`
+ Token string `json:"token"`
+ IsAdmin bool `json:"isAdmin"`
}
func (s SignParams) Validate() *Error {
if CONFIG.FreeSMSUser != "" {
err := SendSMS(CONFIG.FreeSMSUser, CONFIG.FreeSMSPass, fmt.Sprintf("New user signup '%v'", q.In.Email))
if err != nil {
- return nil, NewInternalError(err)
+ log.Error(err)
}
}
}
}
- if CONFIG.FreeSMSUser != "" {
- err := SendSMS(CONFIG.FreeSMSUser, CONFIG.FreeSMSPass, fmt.Sprintf("'%v' request a password reset. Token '/change-password?token=%v'", q.In.Email, token))
- if err != nil {
- return nil, NewInternalError(err)
- }
- }
-
- return SignResult{token}, nil
+ return SignResult{token, newUser.Role == db.RoleAdmin}, nil
}
type SigninQuery struct {
return nil, NewInternalError(err)
}
- return SignResult{token}, nil
+ return SignResult{token, user.Role == db.RoleAdmin}, nil
}
type ConfirmEmailQuery struct {