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