auth wip
This commit is contained in:
No files matched your search
@@ -9,19 +9,19 @@ import (
|
|||||||
|
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
dg "github.com/karincake/apem/db-gorm-pg"
|
|
||||||
d "github.com/karincake/dodol"
|
|
||||||
l "github.com/karincake/lepet"
|
|
||||||
|
|
||||||
a "github.com/karincake/apem"
|
eu "simrs-vx/internal/domain/main-entities/user"
|
||||||
ms "github.com/karincake/apem/ms-redis"
|
erc "simrs-vx/internal/domain/references/common"
|
||||||
|
|
||||||
pa "simrs-vx/pkg/auth-helper"
|
pa "simrs-vx/pkg/auth-helper"
|
||||||
el "simrs-vx/pkg/logger"
|
el "simrs-vx/pkg/logger"
|
||||||
p "simrs-vx/pkg/password"
|
p "simrs-vx/pkg/password"
|
||||||
|
|
||||||
eu "simrs-vx/internal/domain/main-entities/user"
|
a "github.com/karincake/apem"
|
||||||
erc "simrs-vx/internal/domain/references/common"
|
dg "github.com/karincake/apem/db-gorm-pg"
|
||||||
|
ms "github.com/karincake/apem/ms-redis"
|
||||||
|
d "github.com/karincake/dodol"
|
||||||
|
l "github.com/karincake/lepet"
|
||||||
)
|
)
|
||||||
|
|
||||||
var authCfg AuthCfg
|
var authCfg AuthCfg
|
||||||
@@ -38,7 +38,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
|||||||
// if input.Position_Code != "" {
|
// if input.Position_Code != "" {
|
||||||
// user.Position_Code = input.Position_Code
|
// user.Position_Code = input.Position_Code
|
||||||
// }
|
// }
|
||||||
if errCode := GetAndCheck(user, user); errCode != "" {
|
if errCode := getAndCheck(user, user); errCode != "" {
|
||||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: errCode, Message: el.GenMessage(errCode)}}
|
return nil, d.FieldErrors{"authentication": d.FieldError{Code: errCode, Message: el.GenMessage(errCode)}}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,11 +85,6 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
|||||||
atExpires := time.Now().Add(duration).Unix()
|
atExpires := time.Now().Add(duration).Unix()
|
||||||
atSecretKey := authCfg.AtSecretKey
|
atSecretKey := authCfg.AtSecretKey
|
||||||
|
|
||||||
// extra
|
|
||||||
// if input.Position_Code == "doc" {
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Creating Access Token
|
// Creating Access Token
|
||||||
atClaims := jwt.MapClaims{}
|
atClaims := jwt.MapClaims{}
|
||||||
atClaims["user_id"] = user.Id
|
atClaims["user_id"] = user.Id
|
||||||
@@ -127,12 +122,10 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
|||||||
"status": "verified",
|
"status": "verified",
|
||||||
},
|
},
|
||||||
Data: d.II{
|
Data: d.II{
|
||||||
"user_id": strconv.Itoa(int(user.Id)),
|
"user_id": strconv.Itoa(int(user.Id)),
|
||||||
"user_name": user.Name,
|
"user_name": user.Name,
|
||||||
// "user_email": user.Email,
|
|
||||||
"user_position_code": user.Position_Code,
|
"user_position_code": user.Position_Code,
|
||||||
// "user_ref_id": user.Ref_Id,
|
"accessToken": ats,
|
||||||
"accessToken": ats,
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -202,11 +195,9 @@ func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err
|
|||||||
position_code = v.(string)
|
position_code = v.(string)
|
||||||
}
|
}
|
||||||
data = &pa.AuthInfo{
|
data = &pa.AuthInfo{
|
||||||
Uuid: accessUuid,
|
Uuid: accessUuid,
|
||||||
User_Id: uint(user_id),
|
User_Id: uint(user_id),
|
||||||
User_Name: user_name,
|
User_Name: user_name,
|
||||||
// User_Email: user_email,
|
|
||||||
// User_Ref_Id: ref_id,
|
|
||||||
User_Position_Code: position_code,
|
User_Position_Code: position_code,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
package authentication
|
package authentication
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
||||||
|
// edp "simrs-vx/internal/domain/main-entities/division-position"
|
||||||
|
|
||||||
dg "github.com/karincake/apem/db-gorm-pg"
|
dg "github.com/karincake/apem/db-gorm-pg"
|
||||||
|
// pa "simrs-vx/pkg/auth-helper"
|
||||||
)
|
)
|
||||||
|
|
||||||
// just return the error code
|
// just return the error code
|
||||||
func GetAndCheck(input, condition any) (eCode string) {
|
func getAndCheck(input, condition any) (eCode string) {
|
||||||
result := dg.I.Where(condition).Find(&input)
|
result := dg.I.Where(condition).Find(&input)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return "fetch-fail"
|
return "fetch-fail"
|
||||||
@@ -16,6 +20,11 @@ func GetAndCheck(input, condition any) (eCode string) {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDocName(id uint) string {
|
func getDocName(id uint) string {
|
||||||
return "authentication"
|
return "authentication"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// func getDivisionPosition(user_id uint) []pa.DivisionPosition {
|
||||||
|
// var divisionPosition []pa.DivisionPosition
|
||||||
|
// var divisionPositionList []edp.DivisionPosition
|
||||||
|
// }
|
||||||
@@ -7,12 +7,16 @@ import (
|
|||||||
type AuthKey struct{}
|
type AuthKey struct{}
|
||||||
|
|
||||||
type AuthInfo struct {
|
type AuthInfo struct {
|
||||||
Uuid string
|
Uuid string
|
||||||
User_Id uint
|
User_Id uint
|
||||||
User_Name string
|
User_Name string
|
||||||
// User_Email string
|
User_DivisionPosition []DivisionPosition
|
||||||
// User_Ref_Id int
|
User_Position_Code string
|
||||||
User_Position_Code string
|
}
|
||||||
|
|
||||||
|
type DivisionPosition struct {
|
||||||
|
Division_Code string
|
||||||
|
DivisionPosition_Code string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AuthInfo) IsDoctor() bool {
|
func (a AuthInfo) IsDoctor() bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user