nezha/cmd/dashboard/controller/guest_page.go

62 lines
1.7 KiB
Go
Raw Normal View History

2019-12-08 03:59:58 -05:00
package controller
import (
"fmt"
2019-12-08 03:59:58 -05:00
"net/http"
"github.com/gin-gonic/gin"
"github.com/nicksnyder/go-i18n/v2/i18n"
2022-01-08 22:54:14 -05:00
"github.com/naiba/nezha/model"
2020-11-10 21:07:45 -05:00
"github.com/naiba/nezha/pkg/mygin"
2022-01-08 22:54:14 -05:00
"github.com/naiba/nezha/service/singleton"
2019-12-08 03:59:58 -05:00
)
type guestPage struct {
r *gin.Engine
}
func (gp *guestPage) serve() {
gr := gp.r.Group("")
gr.Use(mygin.Authorize(mygin.AuthorizeOption{
2024-02-24 10:21:33 -05:00
GuestOnly: true,
IsPage: true,
Msg: "您已登录",
Btn: "返回首页",
Redirect: "/",
2019-12-08 03:59:58 -05:00
}))
gr.GET("/login", gp.login)
oauth := &oauth2controller{
r: gr,
}
oauth.serve()
}
func (gp *guestPage) login(c *gin.Context) {
LoginType := "GitHub"
RegistrationLink := "https://github.com/join"
2022-01-08 22:54:14 -05:00
if singleton.Conf.Oauth2.Type == model.ConfigTypeGitee {
LoginType = "Gitee"
RegistrationLink = "https://gitee.com/signup"
} else if singleton.Conf.Oauth2.Type == model.ConfigTypeGitlab {
LoginType = "Gitlab"
RegistrationLink = "https://gitlab.com/users/sign_up"
} else if singleton.Conf.Oauth2.Type == model.ConfigTypeJihulab {
LoginType = "Jihulab"
RegistrationLink = "https://jihulab.com/users/sign_up"
} else if singleton.Conf.Oauth2.Type == model.ConfigTypeGitea {
LoginType = "Gitea"
RegistrationLink = fmt.Sprintf("%s/user/sign_up", singleton.Conf.Oauth2.Endpoint)
} else if singleton.Conf.Oauth2.Type == model.ConfigTypeCloudflare {
LoginType = "Cloudflare"
RegistrationLink = "https://dash.cloudflare.com/sign-up/teams"
}
2022-06-02 21:45:11 -04:00
c.HTML(http.StatusOK, "dashboard-"+singleton.Conf.Site.DashboardTheme+"/login", mygin.CommonEnvironment(c, gin.H{
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "Login"}),
"LoginType": LoginType,
"RegistrationLink": RegistrationLink,
2019-12-08 03:59:58 -05:00
}))
}