chore: formating
This commit is contained in:
parent
6d532aed85
commit
6da1f91c2f
24
handlers.go
24
handlers.go
@ -15,7 +15,7 @@ func user_has_role(usr *User, c *gin.Context, rtenv *RouteEnv, role string) (*Us
|
|||||||
var okusr bool
|
var okusr bool
|
||||||
if usr == nil {
|
if usr == nil {
|
||||||
idusr := rtenv.AuthMiddleware.IdentityHandler(c)
|
idusr := rtenv.AuthMiddleware.IdentityHandler(c)
|
||||||
user, okusr = idusr.(*User)
|
user, okusr = idusr.(*User)
|
||||||
if !okusr || len(user.UserName) == 0 {
|
if !okusr || len(user.UserName) == 0 {
|
||||||
return nil,false
|
return nil,false
|
||||||
}
|
}
|
||||||
@ -36,17 +36,17 @@ func user_has_role(usr *User, c *gin.Context, rtenv *RouteEnv, role string) (*Us
|
|||||||
return user,hasRole
|
return user,hasRole
|
||||||
}
|
}
|
||||||
func get_page_handle(c *gin.Context, rtenv *RouteEnv) {
|
func get_page_handle(c *gin.Context, rtenv *RouteEnv) {
|
||||||
tkn := ""
|
tkn := ""
|
||||||
id := c.Params.ByName(rtenv.Cfg.Routes["page"].Param)
|
id := c.Params.ByName(rtenv.Cfg.Routes["page"].Param)
|
||||||
role := rtenv.Cfg.AdminRole
|
role := rtenv.Cfg.AdminRole
|
||||||
hasRole := false
|
hasRole := false
|
||||||
mdlUsr, okmdl := rtenv.MdlsUsrs[id]
|
mdlUsr, okmdl := rtenv.MdlsUsrs[id]
|
||||||
if okmdl {
|
if okmdl {
|
||||||
if rtenv.Cfg.UseAuthz {
|
if rtenv.Cfg.UseAuthz {
|
||||||
hasRole,_ = rtenv.Enforcer.HasRoleForUser(mdlUsr.User, role)
|
hasRole,_ = rtenv.Enforcer.HasRoleForUser(mdlUsr.User, role)
|
||||||
}
|
}
|
||||||
logRoute(c,rtenv,"page",fmt.Sprintf("get /page/%s", id),fmt.Sprintf("get %s (%s %v) %s",mdlUsr.User,role,hasRole,tkn))
|
logRoute(c,rtenv,"page",fmt.Sprintf("get /page/%s", id),fmt.Sprintf("get %s (%s %v) %s",mdlUsr.User,role,hasRole,tkn))
|
||||||
if rtenv.Cfg.UseJWT {
|
if rtenv.Cfg.UseJWT {
|
||||||
c.HTML(http.StatusOK, "welcome", gin.H{
|
c.HTML(http.StatusOK, "welcome", gin.H{
|
||||||
"title": fmt.Sprintf("Main website %s for %s (%v)",id,mdlUsr.User,hasRole),
|
"title": fmt.Sprintf("Main website %s for %s (%v)",id,mdlUsr.User,hasRole),
|
||||||
"token": tkn,
|
"token": tkn,
|
||||||
|
24
jwt.go
24
jwt.go
@ -33,7 +33,7 @@ import (
|
|||||||
// func makeTokenString(mw *jwt.GinJWTMiddleware,data interface{}) (string,error) {
|
// func makeTokenString(mw *jwt.GinJWTMiddleware,data interface{}) (string,error) {
|
||||||
func makeTokenString(rtenv *RouteEnv,data interface{}) (string,error) {
|
func makeTokenString(rtenv *RouteEnv,data interface{}) (string,error) {
|
||||||
if rtenv.AuthMiddleware == nil {
|
if rtenv.AuthMiddleware == nil {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
token := gojwt.New(gojwt.GetSigningMethod(rtenv.AuthMiddleware.SigningAlgorithm))
|
token := gojwt.New(gojwt.GetSigningMethod(rtenv.AuthMiddleware.SigningAlgorithm))
|
||||||
claims := token.Claims.(gojwt.MapClaims)
|
claims := token.Claims.(gojwt.MapClaims)
|
||||||
@ -47,13 +47,13 @@ func makeTokenString(rtenv *RouteEnv,data interface{}) (string,error) {
|
|||||||
claims["orig_iat"] = rtenv.AuthMiddleware.TimeFunc().Unix()
|
claims["orig_iat"] = rtenv.AuthMiddleware.TimeFunc().Unix()
|
||||||
var tokenString string
|
var tokenString string
|
||||||
var err error
|
var err error
|
||||||
if rtenv.Cfg.SigningAlgorithm == "RS256" {
|
if rtenv.Cfg.SigningAlgorithm == "RS256" {
|
||||||
// if mw.usingPublicKeyAlgo() {
|
// if mw.usingPublicKeyAlgo() {
|
||||||
keyData, _ := ioutil.ReadFile(rtenv.Cfg.JwtKeyPem)
|
keyData, _ := ioutil.ReadFile(rtenv.Cfg.JwtKeyPem)
|
||||||
signKey, _ := gojwt.ParseRSAPrivateKeyFromPEM(keyData)
|
signKey, _ := gojwt.ParseRSAPrivateKeyFromPEM(keyData)
|
||||||
tokenString, err = token.SignedString(signKey)
|
tokenString, err = token.SignedString(signKey)
|
||||||
} else {
|
} else {
|
||||||
tokenString, err = token.SignedString(rtenv.AuthMiddleware.Key)
|
tokenString, err = token.SignedString(rtenv.AuthMiddleware.Key)
|
||||||
}
|
}
|
||||||
return tokenString, err
|
return tokenString, err
|
||||||
}
|
}
|
||||||
@ -95,9 +95,9 @@ func getJwt(rtenv *RouteEnv)*jwt.GinJWTMiddleware {
|
|||||||
password := loginVals.Password
|
password := loginVals.Password
|
||||||
if val, ok := rtenv.Users.Accounts[userID]; ok {
|
if val, ok := rtenv.Users.Accounts[userID]; ok {
|
||||||
pasw,_ := b64.StdEncoding.DecodeString(password)
|
pasw,_ := b64.StdEncoding.DecodeString(password)
|
||||||
pass := string(pasw)
|
pass := string(pasw)
|
||||||
txtdata,err := decrypt(val.Passwd, string(CRYPTKEY))
|
txtdata,err := decrypt(val.Passwd, string(CRYPTKEY))
|
||||||
if err == nil && txtdata == pass {
|
if err == nil && txtdata == pass {
|
||||||
return &User{
|
return &User{
|
||||||
UserName: val.Id,
|
UserName: val.Id,
|
||||||
LastName: "",
|
LastName: "",
|
||||||
@ -110,12 +110,12 @@ func getJwt(rtenv *RouteEnv)*jwt.GinJWTMiddleware {
|
|||||||
Authorizator: func(data interface{}, c *gin.Context) bool {
|
Authorizator: func(data interface{}, c *gin.Context) bool {
|
||||||
if v, ok := data.(*User); ok {
|
if v, ok := data.(*User); ok {
|
||||||
if v.UserName == rtenv.Cfg.PubUser {
|
if v.UserName == rtenv.Cfg.PubUser {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if _, ok := rtenv.Users.Accounts[v.UserName]; ok {
|
if _, ok := rtenv.Users.Accounts[v.UserName]; ok {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
Loading…
Reference in New Issue
Block a user