Files
waf-platform/EdgeUser/internal/web/actions/default/login/index.go
2026-02-04 20:27:13 +08:00

87 lines
2.4 KiB
Go

package login
import (
"fmt"
"github.com/TeaOSLab/EdgeUser/internal/configloaders"
teaconst "github.com/TeaOSLab/EdgeUser/internal/const"
"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
}
// 首页(登录页)
// 修改此页面时需要同步修改 index/index.php
func (this *IndexAction) RunGet(params struct {
From string
Auth *helpers.UserShouldAuth
}) {
// 检测是否自动跳转到HTTPS
this.CheckHTTPSRedirecting()
this.Data["username"] = ""
this.Data["password"] = ""
this.Data["passwordMd5"] = ""
// demo
if teaconst.IsDemoMode {
this.Data["username"] = "user"
this.Data["password"] = "123456"
this.Data["passwordMd5"] = stringutil.Md5("123456")
}
// 已登录跳转到dashboard
if params.Auth.IsUser() {
this.RedirectURL("/dashboard")
return
}
this.Data["isUser"] = false
this.Data["menu"] = "signIn"
timestamp := fmt.Sprintf("%d", time.Now().Unix())
this.Data["token"] = stringutil.Md5(actionutils.TokenSalt+timestamp) + timestamp
this.Data["from"] = params.From
config, err := configloaders.LoadUIConfig()
if err != nil {
this.ErrorPage(err)
return
}
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["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()
}