refactored
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
module git.acooldomain.co/server-manager/backend-kubernetes-go/users
|
||||
module git.acooldomain.co/server-manager/backend/users
|
||||
|
||||
go 1.22.0
|
||||
|
||||
|
@@ -4,15 +4,15 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"git.acooldomain.co/server-manager/backend-kubernetes-go/auth"
|
||||
"git.acooldomain.co/server-manager/backend-kubernetes-go/db_handler/mongo"
|
||||
"git.acooldomain.co/server-manager/backend-kubernetes-go/dbhandler"
|
||||
"git.acooldomain.co/server-manager/backend-kubernetes-go/mail"
|
||||
"git.acooldomain.co/server-manager/backend-kubernetes-go/models"
|
||||
"git.acooldomain.co/server-manager/backend/auth"
|
||||
"git.acooldomain.co/server-manager/backend/dbhandler"
|
||||
"git.acooldomain.co/server-manager/backend/factories"
|
||||
"git.acooldomain.co/server-manager/backend/mail"
|
||||
"git.acooldomain.co/server-manager/backend/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Connection struct {
|
||||
type UsersApi struct {
|
||||
userPassAuthHandler dbhandler.UserPassAuthanticationDbHandler
|
||||
tokenHandler dbhandler.InviteTokenDbHandler
|
||||
mailClient mail.MailClient
|
||||
@@ -25,7 +25,7 @@ type UserResponse struct {
|
||||
Permissions models.Permission `json:"Permissions"`
|
||||
}
|
||||
|
||||
func (con Connection) GetUsers(ctx *gin.Context) {
|
||||
func (con UsersApi) GetUsers(ctx *gin.Context) {
|
||||
users, err := con.userPassAuthHandler.ListUsers(ctx)
|
||||
|
||||
if err != nil {
|
||||
@@ -36,7 +36,7 @@ func (con Connection) GetUsers(ctx *gin.Context) {
|
||||
ctx.JSON(http.StatusOK, users)
|
||||
}
|
||||
|
||||
func (con Connection) GetUser(ctx *gin.Context) {
|
||||
func (con UsersApi) GetUser(ctx *gin.Context) {
|
||||
claims, exists := ctx.Get("claims")
|
||||
if !exists {
|
||||
ctx.AbortWithStatus(403)
|
||||
@@ -54,7 +54,7 @@ type InviteUser struct {
|
||||
Permissions models.Permission `json:"Permissions"`
|
||||
}
|
||||
|
||||
func (con Connection) InviteUser(ctx *gin.Context) {
|
||||
func (con UsersApi) InviteUser(ctx *gin.Context) {
|
||||
var request InviteUser
|
||||
json.NewDecoder(ctx.Request.Body).Decode(&request)
|
||||
|
||||
@@ -78,7 +78,7 @@ type SetUserPermissionsRequest struct {
|
||||
Permissions models.Permission `json:"Permissions"`
|
||||
}
|
||||
|
||||
func (con Connection) SetUserPermissions(ctx *gin.Context) {
|
||||
func (con UsersApi) SetUserPermissions(ctx *gin.Context) {
|
||||
var request SetUserPermissionsRequest
|
||||
json.NewDecoder(ctx.Request.Body).Decode(&request)
|
||||
username := ctx.Param("user_id")
|
||||
@@ -92,7 +92,7 @@ func (con Connection) SetUserPermissions(ctx *gin.Context) {
|
||||
ctx.JSON(200, "OK")
|
||||
}
|
||||
|
||||
func (con Connection) DeleteUser(ctx *gin.Context) {
|
||||
func (con UsersApi) DeleteUser(ctx *gin.Context) {
|
||||
username := ctx.Param("user_id")
|
||||
|
||||
err := con.userPassAuthHandler.RemoveUser(ctx, username)
|
||||
@@ -106,29 +106,16 @@ func (con Connection) DeleteUser(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
func LoadGroup(group *gin.RouterGroup, config models.GlobalConfig) {
|
||||
var userAuthHandler dbhandler.UserPassAuthanticationDbHandler
|
||||
var inviteHandler dbhandler.InviteTokenDbHandler
|
||||
var mailClient mail.MailClient
|
||||
|
||||
var err error
|
||||
|
||||
if config.Authentication.UserPass.Type == models.MONGO {
|
||||
userAuthHandler, err = mongo.NewUserPassAuthHandler(*config.Authentication.UserPass.Mongo)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
userAuthHandler, err := factories.GetUserPassAuthDbHandler(config.Authentication.UserPass)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if config.Authentication.UserPass.InviteTokenDatabase.Type == models.MONGO {
|
||||
inviteHandler, err = mongo.NewInviteTokenDbHandler(*config.Authentication.UserPass.Mongo)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
inviteHandler, err := factories.GetInviteTokenDbHandler(config.Authentication.UserPass.InviteTokenDatabase)
|
||||
|
||||
mailClient = *mail.NewMailClient(config.Email)
|
||||
mailClient := *mail.NewMailClient(config.Email)
|
||||
|
||||
connection := Connection{
|
||||
connection := UsersApi{
|
||||
userPassAuthHandler: userAuthHandler,
|
||||
tokenHandler: inviteHandler,
|
||||
mailClient: mailClient,
|
||||
|
Reference in New Issue
Block a user