|
|
@@ -8,6 +8,8 @@ import (
|
|
8
|
8
|
apiResp "github.com/lejianwen/rustdesk-api/v2/http/response/api"
|
|
9
|
9
|
"github.com/lejianwen/rustdesk-api/v2/model"
|
|
10
|
10
|
"github.com/lejianwen/rustdesk-api/v2/service"
|
|
|
11
|
+ "github.com/lejianwen/rustdesk-api/v2/utils"
|
|
|
12
|
+ "github.com/nicksnyder/go-i18n/v2/i18n"
|
|
11
|
13
|
"net/http"
|
|
12
|
14
|
)
|
|
13
|
15
|
|
|
|
@@ -145,7 +147,8 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|
145
|
147
|
state := c.Query("state")
|
|
146
|
148
|
if state == "" {
|
|
147
|
149
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
148
|
|
- "message": response.TranslateParamMsg(c, "ParamIsEmpty", "state"),
|
|
|
150
|
+ "message": "ParamIsEmpty",
|
|
|
151
|
+ "sub_message": "state",
|
|
149
|
152
|
})
|
|
150
|
153
|
return
|
|
151
|
154
|
}
|
|
|
@@ -155,7 +158,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|
155
|
158
|
oauthCache := oauthService.GetOauthCache(cacheKey)
|
|
156
|
159
|
if oauthCache == nil {
|
|
157
|
160
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
158
|
|
- "message": response.TranslateMsg(c, "OauthExpired"),
|
|
|
161
|
+ "message": "OauthExpired",
|
|
159
|
162
|
})
|
|
160
|
163
|
return
|
|
161
|
164
|
}
|
|
|
@@ -169,7 +172,8 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|
169
|
172
|
err, oauthUser := oauthService.Callback(code, verifier, op, nonce)
|
|
170
|
173
|
if err != nil {
|
|
171
|
174
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
172
|
|
- "message": response.TranslateMsg(c, "OauthFailed") + response.TranslateMsg(c, err.Error()),
|
|
|
175
|
+ "message": "OauthFailed",
|
|
|
176
|
+ "sub_message": err.Error(),
|
|
173
|
177
|
})
|
|
174
|
178
|
return
|
|
175
|
179
|
}
|
|
|
@@ -182,7 +186,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|
182
|
186
|
utr := oauthService.UserThirdInfo(op, openid)
|
|
183
|
187
|
if utr.UserId > 0 {
|
|
184
|
188
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
185
|
|
- "message": response.TranslateMsg(c, "OauthHasBindOtherUser"),
|
|
|
189
|
+ "message": "OauthHasBindOtherUser",
|
|
186
|
190
|
})
|
|
187
|
191
|
return
|
|
188
|
192
|
}
|
|
|
@@ -190,7 +194,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|
190
|
194
|
user = service.AllService.UserService.InfoById(userId)
|
|
191
|
195
|
if user == nil {
|
|
192
|
196
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
193
|
|
- "message": response.TranslateMsg(c, "ItemNotFound"),
|
|
|
197
|
+ "message": "ItemNotFound",
|
|
194
|
198
|
})
|
|
195
|
199
|
return
|
|
196
|
200
|
}
|
|
|
@@ -198,12 +202,12 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|
198
|
202
|
err := oauthService.BindOauthUser(userId, oauthUser, op)
|
|
199
|
203
|
if err != nil {
|
|
200
|
204
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
201
|
|
- "message": response.TranslateMsg(c, "BindFail"),
|
|
|
205
|
+ "message": "BindFail",
|
|
202
|
206
|
})
|
|
203
|
207
|
return
|
|
204
|
208
|
}
|
|
205
|
209
|
c.HTML(http.StatusOK, "oauth_success.html", gin.H{
|
|
206
|
|
- "message": response.TranslateMsg(c, "BindSuccess"),
|
|
|
210
|
+ "message": "BindSuccess",
|
|
207
|
211
|
})
|
|
208
|
212
|
return
|
|
209
|
213
|
|
|
|
@@ -211,7 +215,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|
211
|
215
|
//登录
|
|
212
|
216
|
if userId != 0 {
|
|
213
|
217
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
214
|
|
- "message": response.TranslateMsg(c, "OauthHasBeenSuccess"),
|
|
|
218
|
+ "message": "OauthHasBeenSuccess",
|
|
215
|
219
|
})
|
|
216
|
220
|
return
|
|
217
|
221
|
}
|
|
|
@@ -230,7 +234,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|
230
|
234
|
err, user = service.AllService.UserService.RegisterByOauth(oauthUser, op)
|
|
231
|
235
|
if err != nil {
|
|
232
|
236
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
233
|
|
- "message": response.TranslateMsg(c, err.Error()),
|
|
|
237
|
+ "message": err.Error(),
|
|
234
|
238
|
})
|
|
235
|
239
|
return
|
|
236
|
240
|
}
|
|
|
@@ -252,14 +256,50 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|
252
|
256
|
return
|
|
253
|
257
|
}
|
|
254
|
258
|
c.HTML(http.StatusOK, "oauth_success.html", gin.H{
|
|
255
|
|
- "message": response.TranslateMsg(c, "OauthSuccess"),
|
|
|
259
|
+ "message": "OauthSuccess",
|
|
256
|
260
|
})
|
|
257
|
261
|
return
|
|
258
|
262
|
} else {
|
|
259
|
263
|
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
260
|
|
- "message": response.TranslateMsg(c, "ParamsError"),
|
|
|
264
|
+ "message": "ParamsError",
|
|
261
|
265
|
})
|
|
262
|
266
|
return
|
|
263
|
267
|
}
|
|
264
|
268
|
|
|
265
|
269
|
}
|
|
|
270
|
+
|
|
|
271
|
+type MessageParams struct {
|
|
|
272
|
+ Lang string `json:"lang" form:"lang"`
|
|
|
273
|
+ Title string `json:"title" form:"title"`
|
|
|
274
|
+ Msg string `json:"msg" form:"msg"`
|
|
|
275
|
+}
|
|
|
276
|
+
|
|
|
277
|
+func (o *Oauth) Message(c *gin.Context) {
|
|
|
278
|
+ mp := &MessageParams{}
|
|
|
279
|
+ if err := c.ShouldBindQuery(mp); err != nil {
|
|
|
280
|
+ return
|
|
|
281
|
+ }
|
|
|
282
|
+ localizer := global.Localizer(mp.Lang)
|
|
|
283
|
+ res := ""
|
|
|
284
|
+ if mp.Title != "" {
|
|
|
285
|
+ title, err := localizer.LocalizeMessage(&i18n.Message{
|
|
|
286
|
+ ID: mp.Title,
|
|
|
287
|
+ })
|
|
|
288
|
+ if err == nil {
|
|
|
289
|
+ res = utils.StringConcat(";title='", title, "';")
|
|
|
290
|
+ }
|
|
|
291
|
+
|
|
|
292
|
+ }
|
|
|
293
|
+ if mp.Msg != "" {
|
|
|
294
|
+ msg, err := localizer.LocalizeMessage(&i18n.Message{
|
|
|
295
|
+ ID: mp.Msg,
|
|
|
296
|
+ })
|
|
|
297
|
+ if err == nil {
|
|
|
298
|
+ res = utils.StringConcat(res, "msg = '", msg, "';")
|
|
|
299
|
+ }
|
|
|
300
|
+ }
|
|
|
301
|
+
|
|
|
302
|
+ //返回js内容
|
|
|
303
|
+ c.Header("Content-Type", "application/javascript")
|
|
|
304
|
+ c.String(http.StatusOK, res)
|
|
|
305
|
+}
|