2019-11-22 19:33:06 +08:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
model "github.com/HFO4/cloudreve/models"
|
|
|
|
"github.com/HFO4/cloudreve/pkg/serializer"
|
2019-11-23 16:38:43 +08:00
|
|
|
"github.com/HFO4/cloudreve/pkg/util"
|
2019-11-22 19:33:06 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
2019-11-23 16:38:43 +08:00
|
|
|
"github.com/mojocn/base64Captcha"
|
2019-11-22 19:33:06 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// SiteConfig 获取站点全局配置
|
|
|
|
func SiteConfig(c *gin.Context) {
|
2020-02-04 15:29:52 +08:00
|
|
|
siteConfig := model.GetSettingByNames(
|
2019-11-22 19:33:06 +08:00
|
|
|
"siteName",
|
|
|
|
"login_captcha",
|
|
|
|
"qq_login",
|
|
|
|
"reg_captcha",
|
|
|
|
"email_active",
|
|
|
|
"forget_captcha",
|
|
|
|
"email_active",
|
|
|
|
"themes",
|
|
|
|
"defaultTheme",
|
2020-01-26 13:07:05 +08:00
|
|
|
"score_enabled",
|
|
|
|
"share_score_rate",
|
2020-01-29 14:25:14 +08:00
|
|
|
"home_view_method",
|
|
|
|
"share_view_method",
|
2020-02-21 10:08:47 +08:00
|
|
|
"authn_enabled",
|
2020-02-04 15:29:52 +08:00
|
|
|
)
|
2019-11-22 19:33:06 +08:00
|
|
|
|
2020-02-12 11:38:04 +08:00
|
|
|
// 如果已登录,则同时返回用户信息和标签
|
2019-11-25 14:08:11 +08:00
|
|
|
user, _ := c.Get("user")
|
|
|
|
if user, ok := user.(*model.User); ok {
|
|
|
|
c.JSON(200, serializer.BuildSiteConfig(siteConfig, user))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(200, serializer.BuildSiteConfig(siteConfig, nil))
|
2019-11-22 19:33:06 +08:00
|
|
|
}
|
2019-11-23 16:38:43 +08:00
|
|
|
|
|
|
|
// Ping 状态检查页面
|
|
|
|
func Ping(c *gin.Context) {
|
|
|
|
c.JSON(200, serializer.Response{
|
|
|
|
Code: 0,
|
|
|
|
Msg: "Pong",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Captcha 获取验证码
|
|
|
|
func Captcha(c *gin.Context) {
|
2020-02-22 12:18:49 +08:00
|
|
|
options := model.GetSettingByNames(
|
|
|
|
"captcha_IsShowHollowLine",
|
|
|
|
"captcha_IsShowNoiseDot",
|
|
|
|
"captcha_IsShowNoiseText",
|
|
|
|
"captcha_IsShowSlimeLine",
|
|
|
|
"captcha_IsShowSineLine",
|
|
|
|
)
|
2019-11-23 16:38:43 +08:00
|
|
|
// 验证码配置
|
|
|
|
var configD = base64Captcha.ConfigCharacter{
|
2020-02-22 12:18:49 +08:00
|
|
|
Height: model.GetIntSetting("captcha_height", 60),
|
|
|
|
Width: model.GetIntSetting("captcha_width", 240),
|
2019-11-23 16:38:43 +08:00
|
|
|
//const CaptchaModeNumber:数字,CaptchaModeAlphabet:字母,CaptchaModeArithmetic:算术,CaptchaModeNumberAlphabet:数字字母混合.
|
2020-02-22 12:18:49 +08:00
|
|
|
Mode: model.GetIntSetting("captcha_mode", 3),
|
|
|
|
ComplexOfNoiseText: model.GetIntSetting("captcha_ComplexOfNoiseText", 0),
|
|
|
|
ComplexOfNoiseDot: model.GetIntSetting("captcha_ComplexOfNoiseDot", 0),
|
|
|
|
IsShowHollowLine: model.IsTrueVal(options["captcha_IsShowHollowLine"]),
|
|
|
|
IsShowNoiseDot: model.IsTrueVal(options["captcha_IsShowNoiseDot"]),
|
|
|
|
IsShowNoiseText: model.IsTrueVal(options["captcha_IsShowNoiseText"]),
|
|
|
|
IsShowSlimeLine: model.IsTrueVal(options["captcha_IsShowSlimeLine"]),
|
|
|
|
IsShowSineLine: model.IsTrueVal(options["captcha_IsShowSineLine"]),
|
|
|
|
CaptchaLen: model.GetIntSetting("captcha_CaptchaLen", 6),
|
2019-11-23 16:38:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 生成验证码
|
|
|
|
idKeyD, capD := base64Captcha.GenerateCaptcha("", configD)
|
|
|
|
// 将验证码UID存入Session以便后续验证
|
|
|
|
util.SetSession(c, map[string]interface{}{
|
|
|
|
"captchaID": idKeyD,
|
|
|
|
})
|
|
|
|
|
|
|
|
// 将验证码图像编码为Base64
|
|
|
|
base64stringD := base64Captcha.CaptchaWriteToBase64Encoding(capD)
|
|
|
|
|
|
|
|
c.JSON(200, serializer.Response{
|
|
|
|
Code: 0,
|
|
|
|
Data: base64stringD,
|
|
|
|
})
|
|
|
|
}
|