style: Oauth page languages
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
|||||||
apiResp "github.com/lejianwen/rustdesk-api/v2/http/response/api"
|
apiResp "github.com/lejianwen/rustdesk-api/v2/http/response/api"
|
||||||
"github.com/lejianwen/rustdesk-api/v2/model"
|
"github.com/lejianwen/rustdesk-api/v2/model"
|
||||||
"github.com/lejianwen/rustdesk-api/v2/service"
|
"github.com/lejianwen/rustdesk-api/v2/service"
|
||||||
|
"github.com/lejianwen/rustdesk-api/v2/utils"
|
||||||
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -145,7 +147,8 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|||||||
state := c.Query("state")
|
state := c.Query("state")
|
||||||
if state == "" {
|
if state == "" {
|
||||||
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
||||||
"message": response.TranslateParamMsg(c, "ParamIsEmpty", "state"),
|
"message": "ParamIsEmpty",
|
||||||
|
"sub_message": "state",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -155,7 +158,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|||||||
oauthCache := oauthService.GetOauthCache(cacheKey)
|
oauthCache := oauthService.GetOauthCache(cacheKey)
|
||||||
if oauthCache == nil {
|
if oauthCache == nil {
|
||||||
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
||||||
"message": response.TranslateMsg(c, "OauthExpired"),
|
"message": "OauthExpired",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -169,7 +172,8 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|||||||
err, oauthUser := oauthService.Callback(code, verifier, op, nonce)
|
err, oauthUser := oauthService.Callback(code, verifier, op, nonce)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
||||||
"message": response.TranslateMsg(c, "OauthFailed") + response.TranslateMsg(c, err.Error()),
|
"message": "OauthFailed",
|
||||||
|
"sub_message": err.Error(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -182,7 +186,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|||||||
utr := oauthService.UserThirdInfo(op, openid)
|
utr := oauthService.UserThirdInfo(op, openid)
|
||||||
if utr.UserId > 0 {
|
if utr.UserId > 0 {
|
||||||
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
||||||
"message": response.TranslateMsg(c, "OauthHasBindOtherUser"),
|
"message": "OauthHasBindOtherUser",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -190,7 +194,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|||||||
user = service.AllService.UserService.InfoById(userId)
|
user = service.AllService.UserService.InfoById(userId)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
||||||
"message": response.TranslateMsg(c, "ItemNotFound"),
|
"message": "ItemNotFound",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -198,12 +202,12 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|||||||
err := oauthService.BindOauthUser(userId, oauthUser, op)
|
err := oauthService.BindOauthUser(userId, oauthUser, op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
||||||
"message": response.TranslateMsg(c, "BindFail"),
|
"message": "BindFail",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.HTML(http.StatusOK, "oauth_success.html", gin.H{
|
c.HTML(http.StatusOK, "oauth_success.html", gin.H{
|
||||||
"message": response.TranslateMsg(c, "BindSuccess"),
|
"message": "BindSuccess",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -211,7 +215,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|||||||
//登录
|
//登录
|
||||||
if userId != 0 {
|
if userId != 0 {
|
||||||
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
||||||
"message": response.TranslateMsg(c, "OauthHasBeenSuccess"),
|
"message": "OauthHasBeenSuccess",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -230,7 +234,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|||||||
err, user = service.AllService.UserService.RegisterByOauth(oauthUser, op)
|
err, user = service.AllService.UserService.RegisterByOauth(oauthUser, op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
||||||
"message": response.TranslateMsg(c, err.Error()),
|
"message": err.Error(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -252,14 +256,50 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.HTML(http.StatusOK, "oauth_success.html", gin.H{
|
c.HTML(http.StatusOK, "oauth_success.html", gin.H{
|
||||||
"message": response.TranslateMsg(c, "OauthSuccess"),
|
"message": "OauthSuccess",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
||||||
"message": response.TranslateMsg(c, "ParamsError"),
|
"message": "ParamsError",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MessageParams struct {
|
||||||
|
Lang string `json:"lang" form:"lang"`
|
||||||
|
Title string `json:"title" form:"title"`
|
||||||
|
Msg string `json:"msg" form:"msg"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *Oauth) Message(c *gin.Context) {
|
||||||
|
mp := &MessageParams{}
|
||||||
|
if err := c.ShouldBindQuery(mp); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
localizer := global.Localizer(mp.Lang)
|
||||||
|
res := ""
|
||||||
|
if mp.Title != "" {
|
||||||
|
title, err := localizer.LocalizeMessage(&i18n.Message{
|
||||||
|
ID: mp.Title,
|
||||||
|
})
|
||||||
|
if err == nil {
|
||||||
|
res = utils.StringConcat(";title='", title, "';")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if mp.Msg != "" {
|
||||||
|
msg, err := localizer.LocalizeMessage(&i18n.Message{
|
||||||
|
ID: mp.Msg,
|
||||||
|
})
|
||||||
|
if err == nil {
|
||||||
|
res = utils.StringConcat(res, "msg = '", msg, "';")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//返回js内容
|
||||||
|
c.Header("Content-Type", "application/javascript")
|
||||||
|
c.String(http.StatusOK, res)
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ func ApiInit(g *gin.Engine) {
|
|||||||
//api/oauth/callback
|
//api/oauth/callback
|
||||||
frg.GET("/oauth/callback", o.OauthCallback)
|
frg.GET("/oauth/callback", o.OauthCallback)
|
||||||
frg.GET("/oauth/login", o.OauthCallback)
|
frg.GET("/oauth/login", o.OauthCallback)
|
||||||
|
frg.GET("/oauth/msg", o.Message)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
pe := &api.Peer{}
|
pe := &api.Peer{}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="zh-CN">
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>授权失败 - RustDesk API</title>
|
<title>OauthFailed - RustDesk API</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
|
||||||
@@ -57,17 +57,25 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<link rel="stylesheet" href="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/font-awesome/6.0.0/css/all.min.css">
|
<link rel="stylesheet" href="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/font-awesome/6.0.0/css/all.min.css">
|
||||||
|
<script>
|
||||||
|
var lang = navigator.language || navigator.userLanguage || 'zh-CN';
|
||||||
|
var title = 'OauthFailed'
|
||||||
|
var msg = '{{.message}}'
|
||||||
|
var btn = 'Close'
|
||||||
|
document.writeln('<script src="/api/oauth/msg?lang=' + lang + '&msg=' + msg + '&title=OauthFailed"><\/script>');
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="success-container">
|
<div class="success-container">
|
||||||
<i class="fas fa-triangle-exclamation checkmark"></i>
|
<i class="fas fa-triangle-exclamation checkmark"></i>
|
||||||
<h1>授权失败!</h1>
|
<h1 id="h1"></h1>
|
||||||
<p>{{.message}}</p>
|
<p id="msg"></p>
|
||||||
<a href="javascript:window.close()" class="return-link">关闭页面</a>
|
<a href="javascript:window.close()" class="return-link" id="btn">Close</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
document.title = title + ' - RustDesk API';
|
||||||
|
document.getElementById('h1').innerText = title;
|
||||||
|
document.getElementById('msg').innerText = msg;
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>授权成功 - RustDesk API</title>
|
<title>OauthSuccess - RustDesk API</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
|
||||||
@@ -56,18 +56,27 @@
|
|||||||
background-color: #45a049;
|
background-color: #45a049;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<script>
|
||||||
|
var lang = navigator.language || navigator.userLanguage || 'zh-CN';
|
||||||
|
var title = 'OauthSuccess'
|
||||||
|
var msg = '{{.message}}'
|
||||||
|
var btn = 'Close'
|
||||||
|
document.writeln('<script src="/api/oauth/msg?lang=' + lang + '&msg=' + msg + '&title=OauthSuccess"><\/script>');
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="success-container">
|
<div class="success-container">
|
||||||
<i class="fas fa-check-circle checkmark"></i>
|
<i class="fas fa-check-circle checkmark"></i>
|
||||||
<h1>授权成功!</h1>
|
<h1 id="h1"></h1>
|
||||||
<p>您已成功授权访问您的账户。</p>
|
<!-- <p>您已成功授权访问您的账户。</p>-->
|
||||||
<p>现在可以关闭本页面或返回应用继续操作。</p>
|
<!-- <p>现在可以关闭本页面或返回应用继续操作。</p>-->
|
||||||
<a href="javascript:window.close()" class="return-link">关闭页面</a>
|
<a href="javascript:window.close()" class="return-link">Close</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
document.title = title + ' - RustDesk API';
|
||||||
|
document.getElementById('h1').innerText = title;
|
||||||
|
document.getElementById('msg').innerText = msg;
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Md5(str string) string {
|
func Md5(str string) string {
|
||||||
@@ -100,3 +101,11 @@ func InArray(k string, arr []string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StringConcat(strs ...string) string {
|
||||||
|
var builder strings.Builder
|
||||||
|
for _, str := range strs {
|
||||||
|
builder.WriteString(str)
|
||||||
|
}
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user