mirror of
https://github.com/KaySar12/NextZen-UserService.git
synced 2025-10-06 19:59:42 +07:00
feature: add nextWeb Service
This commit is contained in:
@@ -43,6 +43,8 @@ func InitRouter() *gin.Engine {
|
||||
r.GET("/v1/users/oidc/health", v1.OIDCHealthCheck)
|
||||
r.GET("/v1/users/oidc/settings", v1.GetOIDCSettings)
|
||||
r.POST("/v1/users/oidc/saveSettings", v1.SaveOIDCSettings)
|
||||
r.GET("/v1/users/1panel/health", v1.OnePanelHealthCheck)
|
||||
r.POST("/v1/users/1panel/login", v1.OnePanelLogin)
|
||||
v1Group := r.Group("/v1")
|
||||
|
||||
v1Group.Use(jwt.JWT(
|
||||
|
||||
@@ -53,6 +53,9 @@ var (
|
||||
//authURL = "http://10.0.0.26:9000/application/o/nextzenos-oidc/"
|
||||
callbackURL = "http://nextzenos.local/v1/users/oidc/callback"
|
||||
//callbackURL = "http://172.20.60.244:8080/v1/users/oidc/callback"
|
||||
onePanelServer = "http://172.20.60.244:13000"
|
||||
onePanelName = "nextzen"
|
||||
onePanelPassword = "Smartyourlife123@*"
|
||||
)
|
||||
|
||||
type OIDCSetting struct {
|
||||
@@ -122,6 +125,34 @@ var limiter = rate.NewLimiter(rate.Every(time.Minute), 5)
|
||||
// @Param pwd query string true "password"
|
||||
// @Success 200 {string} string "ok"
|
||||
// @Router /user/login [post]
|
||||
func OnePanelLogin(c *gin.Context) {
|
||||
var cred = model2.OnePanelCredentials{
|
||||
Name: onePanelName,
|
||||
Password: onePanelPassword,
|
||||
IgnoreCaptcha: true,
|
||||
Captcha: "",
|
||||
CaptchaID: "",
|
||||
AuthMethod: "session",
|
||||
Language: "en",
|
||||
}
|
||||
response, cookies, err := service.MyService.OnePanel().Login(cred, "http://172.20.60.244:13000")
|
||||
if err != nil {
|
||||
c.JSON(common_err.SERVICE_ERROR,
|
||||
model.Result{
|
||||
Success: common_err.SERVICE_ERROR,
|
||||
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||
})
|
||||
}
|
||||
for _, cookie := range cookies {
|
||||
c.SetCookie(cookie.Name, cookie.Value, 3600, "/", "", false, true)
|
||||
}
|
||||
c.JSON(common_err.SUCCESS,
|
||||
model.Result{
|
||||
Success: common_err.SUCCESS,
|
||||
Message: common_err.GetMsg(common_err.SUCCESS),
|
||||
Data: response,
|
||||
})
|
||||
}
|
||||
func PostUserLogin(c *gin.Context) {
|
||||
if !limiter.Allow() {
|
||||
c.JSON(common_err.TOO_MANY_REQUEST,
|
||||
@@ -502,6 +533,14 @@ func determineUserRole(isSuperuser bool) string {
|
||||
}
|
||||
return "user"
|
||||
}
|
||||
func OnePanelHealthCheck(c *gin.Context) {
|
||||
status, err := service.MyService.OnePanel().HealthCheck(onePanelServer)
|
||||
if err != nil || status == "Offline" {
|
||||
c.JSON(http.StatusOK, model.Result{Success: common_err.OIDC_OFFLINE, Message: common_err.GetMsg(common_err.OIDC_OFFLINE), Data: "Offline"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, model.Result{Success: common_err.OIDC_LIVE, Message: common_err.GetMsg(common_err.OIDC_LIVE), Data: "Live"})
|
||||
}
|
||||
|
||||
func hashPassword() string {
|
||||
generatePassword, err := randString(16)
|
||||
|
||||
Reference in New Issue
Block a user