|
|
@@ -145,7 +145,9 @@ func (o *Oauth) OidcAuthQuery(c *gin.Context) {
|
|
145
|
145
|
func (o *Oauth) OauthCallback(c *gin.Context) {
|
|
146
|
146
|
state := c.Query("state")
|
|
147
|
147
|
if state == "" {
|
|
148
|
|
- c.String(http.StatusInternalServerError, response.TranslateParamMsg(c, "ParamIsEmpty", "state"))
|
|
|
148
|
+ c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
|
149
|
+ "message": response.TranslateParamMsg(c, "ParamIsEmpty", "state"),
|
|
|
150
|
+ })
|
|
149
|
151
|
return
|
|
150
|
152
|
}
|
|
151
|
153
|
cacheKey := state
|
|
|
@@ -153,7 +155,9 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|
153
|
155
|
//从缓存中获取
|
|
154
|
156
|
oauthCache := oauthService.GetOauthCache(cacheKey)
|
|
155
|
157
|
if oauthCache == nil {
|
|
156
|
|
- c.String(http.StatusInternalServerError, response.TranslateMsg(c, "OauthExpired"))
|
|
|
158
|
+ c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
|
159
|
+ "message": response.TranslateMsg(c, "OauthExpired"),
|
|
|
160
|
+ })
|
|
157
|
161
|
return
|
|
158
|
162
|
}
|
|
159
|
163
|
op := oauthCache.Op
|
|
|
@@ -164,7 +168,9 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|
164
|
168
|
code := c.Query("code")
|
|
165
|
169
|
err, oauthUser := oauthService.Callback(code, verifier, op)
|
|
166
|
170
|
if err != nil {
|
|
167
|
|
- c.String(http.StatusInternalServerError, response.TranslateMsg(c, "OauthFailed")+response.TranslateMsg(c, err.Error()))
|
|
|
171
|
+ c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
|
172
|
+ "message": response.TranslateMsg(c, "OauthFailed") + response.TranslateMsg(c, err.Error()),
|
|
|
173
|
+ })
|
|
168
|
174
|
return
|
|
169
|
175
|
}
|
|
170
|
176
|
userId := oauthCache.UserId
|
|
|
@@ -175,28 +181,38 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|
175
|
181
|
// 检查此openid是否已经绑定过
|
|
176
|
182
|
utr := oauthService.UserThirdInfo(op, openid)
|
|
177
|
183
|
if utr.UserId > 0 {
|
|
178
|
|
- c.String(http.StatusInternalServerError, response.TranslateMsg(c, "OauthHasBindOtherUser"))
|
|
|
184
|
+ c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
|
185
|
+ "message": response.TranslateMsg(c, "OauthHasBindOtherUser"),
|
|
|
186
|
+ })
|
|
179
|
187
|
return
|
|
180
|
188
|
}
|
|
181
|
189
|
//绑定
|
|
182
|
190
|
user = service.AllService.UserService.InfoById(userId)
|
|
183
|
191
|
if user == nil {
|
|
184
|
|
- c.String(http.StatusInternalServerError, response.TranslateMsg(c, "ItemNotFound"))
|
|
|
192
|
+ c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
|
193
|
+ "message": response.TranslateMsg(c, "ItemNotFound"),
|
|
|
194
|
+ })
|
|
185
|
195
|
return
|
|
186
|
196
|
}
|
|
187
|
197
|
//绑定
|
|
188
|
198
|
err := oauthService.BindOauthUser(userId, oauthUser, op)
|
|
189
|
199
|
if err != nil {
|
|
190
|
|
- c.String(http.StatusInternalServerError, response.TranslateMsg(c, "BindFail"))
|
|
|
200
|
+ c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
|
201
|
+ "message": response.TranslateMsg(c, "BindFail"),
|
|
|
202
|
+ })
|
|
191
|
203
|
return
|
|
192
|
204
|
}
|
|
193
|
|
- c.String(http.StatusOK, response.TranslateMsg(c, "BindSuccess"))
|
|
|
205
|
+ c.HTML(http.StatusOK, "oauth_success.html", gin.H{
|
|
|
206
|
+ "message": response.TranslateMsg(c, "BindSuccess"),
|
|
|
207
|
+ })
|
|
194
|
208
|
return
|
|
195
|
209
|
|
|
196
|
210
|
} else if action == service.OauthActionTypeLogin {
|
|
197
|
211
|
//登录
|
|
198
|
212
|
if userId != 0 {
|
|
199
|
|
- c.String(http.StatusInternalServerError, response.TranslateMsg(c, "OauthHasBeenSuccess"))
|
|
|
213
|
+ c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
|
214
|
+ "message": response.TranslateMsg(c, "OauthHasBeenSuccess"),
|
|
|
215
|
+ })
|
|
200
|
216
|
return
|
|
201
|
217
|
}
|
|
202
|
218
|
user = service.AllService.UserService.InfoByOauthId(op, openid)
|
|
|
@@ -213,7 +229,9 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|
213
|
229
|
//自动注册
|
|
214
|
230
|
err, user = service.AllService.UserService.RegisterByOauth(oauthUser, op)
|
|
215
|
231
|
if err != nil {
|
|
216
|
|
- c.String(http.StatusInternalServerError, response.TranslateMsg(c, err.Error()))
|
|
|
232
|
+ c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
|
233
|
+ "message": response.TranslateMsg(c, err.Error()),
|
|
|
234
|
+ })
|
|
217
|
235
|
return
|
|
218
|
236
|
}
|
|
219
|
237
|
}
|
|
|
@@ -233,10 +251,14 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
|
233
|
251
|
c.Redirect(http.StatusFound, url)
|
|
234
|
252
|
return
|
|
235
|
253
|
}
|
|
236
|
|
- c.String(http.StatusOK, response.TranslateMsg(c, "OauthSuccess"))
|
|
|
254
|
+ c.HTML(http.StatusOK, "oauth_success.html", gin.H{
|
|
|
255
|
+ "message": response.TranslateMsg(c, "OauthSuccess"),
|
|
|
256
|
+ })
|
|
237
|
257
|
return
|
|
238
|
258
|
} else {
|
|
239
|
|
- c.String(http.StatusInternalServerError, response.TranslateMsg(c, "ParamsError"))
|
|
|
259
|
+ c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
|
|
260
|
+ "message": response.TranslateMsg(c, "ParamsError"),
|
|
|
261
|
+ })
|
|
240
|
262
|
return
|
|
241
|
263
|
}
|
|
242
|
264
|
|