92 lines
2.5 KiB
Go
92 lines
2.5 KiB
Go
package index
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/TeaOSLab/EdgeUser/internal/configloaders"
|
|
teaconst "github.com/TeaOSLab/EdgeUser/internal/const"
|
|
"github.com/TeaOSLab/EdgeUser/internal/utils/portalutils"
|
|
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
|
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/login/loginutils"
|
|
"github.com/TeaOSLab/EdgeUser/internal/web/helpers"
|
|
stringutil "github.com/iwind/TeaGo/utils/string"
|
|
"time"
|
|
)
|
|
|
|
type IndexAction struct {
|
|
actionutils.LoginAction
|
|
}
|
|
|
|
// 首页(登录页)
|
|
// 修改此页面时需要同步修改 login/index.go
|
|
|
|
func (this *IndexAction) RunGet(params struct {
|
|
From string
|
|
|
|
Auth *helpers.UserShouldAuth
|
|
}) {
|
|
// 跳转到自定义页面
|
|
if portalutils.HasPortalIndex() {
|
|
portalutils.ReadPortalIndex(this.ResponseWriter)
|
|
return
|
|
}
|
|
|
|
// 加载UI配置
|
|
config, err := configloaders.LoadUIConfig()
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
|
|
// 检测是否自动跳转到HTTPS
|
|
this.CheckHTTPSRedirecting()
|
|
|
|
// 跳转到Portal
|
|
if config.Portal.IsOn {
|
|
this.RedirectURL("/portal")
|
|
return
|
|
}
|
|
|
|
// 已登录跳转到dashboard
|
|
if params.Auth.IsUser() {
|
|
this.RedirectURL("/dashboard")
|
|
return
|
|
}
|
|
|
|
this.Data["isUser"] = false
|
|
this.Data["menu"] = "signIn"
|
|
|
|
var timestamp = fmt.Sprintf("%d", time.Now().Unix())
|
|
this.Data["token"] = stringutil.Md5(actionutils.TokenSalt+timestamp) + timestamp
|
|
this.Data["from"] = params.From
|
|
|
|
this.Data["systemName"] = config.UserSystemName
|
|
this.Data["showVersion"] = config.ShowVersion
|
|
if len(config.Version) > 0 {
|
|
this.Data["version"] = config.Version
|
|
} else {
|
|
this.Data["version"] = teaconst.Version
|
|
}
|
|
this.Data["faviconFileId"] = config.FaviconFileId
|
|
this.Data["logoFileId"] = config.LogoFileId
|
|
this.Data["themeBackgroundColor"] = config.Theme.BackgroundColor
|
|
|
|
// 是否可以注册
|
|
this.Data["canRegister"] = false
|
|
this.Data["emailCanLogin"] = false
|
|
this.Data["canResetPassword"] = false
|
|
{
|
|
registerConfig, _ := configloaders.LoadRegisterConfig()
|
|
if registerConfig != nil {
|
|
this.Data["canRegister"] = registerConfig.IsOn
|
|
this.Data["emailCanLogin"] = registerConfig.EmailVerification.IsOn && registerConfig.EmailVerification.CanLogin
|
|
this.Data["canResetPassword"] = registerConfig.EmailVerification.IsOn && registerConfig.EmailResetPassword.IsOn
|
|
this.Data["mobileCanLogin"] = registerConfig.MobileVerification.IsOn && registerConfig.MobileVerification.CanLogin
|
|
}
|
|
}
|
|
|
|
// 删除Cookie
|
|
loginutils.UnsetCookie(this.Object())
|
|
|
|
this.Show()
|
|
}
|