|
|
|
@ -64,6 +64,12 @@ func Routers(r *gin.RouterGroup) {
|
|
|
|
|
// @Success 200 {object} Model.Res
|
|
|
|
|
// @Router /oauth2/getCaptcha [get]
|
|
|
|
|
func getCaptcha(c *gin.Context) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
//自定义redis为存储器
|
|
|
|
|
captcha.SetCustomStore(&ControllerRecaptcha.RedisStoreBean)
|
|
|
|
|
|
|
|
|
@ -97,6 +103,12 @@ func getCaptcha(c *gin.Context) {
|
|
|
|
|
// @Router /oauth2/getCaptchaPng [get]
|
|
|
|
|
// @X-LengthLimit [{"captchaId":"20,20"}]
|
|
|
|
|
func getCaptchaPng(c *gin.Context) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
ControllerRecaptcha.ServeHTTP(c.Writer, c.Request)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -106,6 +118,12 @@ func getCaptchaPng(c *gin.Context) {
|
|
|
|
|
时间:2020-03-13
|
|
|
|
|
*/
|
|
|
|
|
func generateAuthCode(context *gin.Context, identityId string, personId string, deviceId string, typeId string) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
//1、生成加密串
|
|
|
|
|
r, _ := AesUtil.Encrypt([]byte(identityId + "_" + personId + "_" + deviceId + "_" + ConvertUtil.Int64ToString(CommonUtil.GetCurrentTimestamp())))
|
|
|
|
|
//2、转base64
|
|
|
|
@ -177,6 +195,12 @@ func generateAuthCode(context *gin.Context, identityId string, personId string,
|
|
|
|
|
// @Success 200 {string} string
|
|
|
|
|
// @Router /oauth2/access_token [post]
|
|
|
|
|
func accessToken(context *gin.Context) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
req := context.Request
|
|
|
|
|
resp := RedisStorage.OsinServer.NewResponse()
|
|
|
|
|
defer resp.Close()
|
|
|
|
@ -303,6 +327,12 @@ func accessToken(context *gin.Context) {
|
|
|
|
|
// @X-IntLimit ["device_id"]
|
|
|
|
|
// @X-EmptyLimit ["username","password","captchaId","value"]
|
|
|
|
|
func authorizePost(context *gin.Context) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
var identityId string
|
|
|
|
|
var personId string
|
|
|
|
|
var success bool
|
|
|
|
@ -382,6 +412,12 @@ func authorizePost(context *gin.Context) {
|
|
|
|
|
// @Router /oauth2/authorize [get]
|
|
|
|
|
// @X-EmptyLimit ["client_id","redirect_uri","device_id","oauth_callback"]
|
|
|
|
|
func authorizeGet(context *gin.Context) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
//客户端的client_id
|
|
|
|
|
var paraClientId = context.Query("client_id")
|
|
|
|
|
//回调接口地址
|
|
|
|
@ -437,6 +473,12 @@ func authorizeGet(context *gin.Context) {
|
|
|
|
|
// @Success 200 {string} string
|
|
|
|
|
// @Router /oauth2/logout [get]
|
|
|
|
|
func logout(context *gin.Context) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
//取出现在的cookie中的accessToken
|
|
|
|
|
accessToken := SsoUtil.ReadSsoCookie(context)
|
|
|
|
|
//获取所有接入系统的
|
|
|
|
@ -494,6 +536,12 @@ func logout(context *gin.Context) {
|
|
|
|
|
// @Router /oauth2/resetRemainCount [get]
|
|
|
|
|
// @X-EmptyLimit ["userName"]
|
|
|
|
|
func resetRemainCount(context *gin.Context) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
userName := context.Query("userName")
|
|
|
|
|
RedisUtil.DEL(Const.RemainCountRedisPrefix + userName)
|
|
|
|
|
msg := "成功清除禁用标识!"
|
|
|
|
@ -511,6 +559,12 @@ func resetRemainCount(context *gin.Context) {
|
|
|
|
|
// @Router /oauth2/wxLogin [post]
|
|
|
|
|
// @X-EmptyLimit ["code"]
|
|
|
|
|
func wxLogin(context *gin.Context) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
var code = context.PostForm("code")
|
|
|
|
|
//对接微信,腾讯给的AK+SK
|
|
|
|
|
appId := "wx3e0449144386938a"
|
|
|
|
@ -529,7 +583,7 @@ func wxLogin(context *gin.Context) {
|
|
|
|
|
if resp.StatusCode == 200 {
|
|
|
|
|
//将返回结果转为json
|
|
|
|
|
openid := gjson.Get(string(body), "openid")
|
|
|
|
|
context.Redirect(301, "/sso/static/bindUser.html?openid="+openid.Str)
|
|
|
|
|
context.JSON(http.StatusOK, map[string]interface{}{"success": true, "openid": openid})
|
|
|
|
|
} else {
|
|
|
|
|
context.JSON(http.StatusOK, map[string]interface{}{"success": false, "openid": ""})
|
|
|
|
|
}
|
|
|
|
@ -543,6 +597,12 @@ func wxLogin(context *gin.Context) {
|
|
|
|
|
// @Success 200 {string} string
|
|
|
|
|
// @Router /oauth2/wxShowImg [get]
|
|
|
|
|
func wxShowImg(context *gin.Context) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
url := `https://open.weixin.qq.com/connect/qrconnect?appid=wx3e0449144386938a&redirect_uri=http://fort.edusoa.com:7777/sso/static/jumpWx.html&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect`
|
|
|
|
|
//获取http代码
|
|
|
|
|
p, err := goquery.ParseUrl(url)
|
|
|
|
@ -570,3 +630,44 @@ func wxShowImg(context *gin.Context) {
|
|
|
|
|
context.File(pngFile)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Summary 检查OPENID的是否已经绑定
|
|
|
|
|
// @Description 检查OPENID的是否已经绑定
|
|
|
|
|
// @Tags 登录验证类
|
|
|
|
|
// @Accept application/x-www-form-urlencoded
|
|
|
|
|
// @Produce json
|
|
|
|
|
// @Param openid query string true "OpenId"
|
|
|
|
|
// @Success 200 {string} string
|
|
|
|
|
// @Router /oauth2/checkOpenId [get]
|
|
|
|
|
func checkOpenId(context *gin.Context) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
openId := context.Query("openid")
|
|
|
|
|
found, err, identityId, personId := ServiceLoginPerson.CheckOpenId(openId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
context.JSON(http.StatusOK, map[string]interface{}{"success": false, "message": "检查OpenId失败!"})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//1、此OpenId已经存在挂接关系,那么写入相应的登录标识,并跳转到指定的页面
|
|
|
|
|
if found {
|
|
|
|
|
//1、生成加密串
|
|
|
|
|
r, _ := AesUtil.Encrypt([]byte(CommonUtil.ConvertInt64ToString(identityId) + "_" + personId + "_1_" + ConvertUtil.Int64ToString(CommonUtil.GetCurrentTimestamp())))
|
|
|
|
|
//2、转base64
|
|
|
|
|
encodeString := base64.RawURLEncoding.EncodeToString([]byte(r))
|
|
|
|
|
//3、写cookie
|
|
|
|
|
context.SetCookie(ConfigUtil.AccessToken, encodeString, 0, "/", "", false, true)
|
|
|
|
|
//4、跳转到XXX页面,比如集成页,或者管理员的首页
|
|
|
|
|
if identityId==1{
|
|
|
|
|
context.Redirect(301, "/dsBaseWeb/#/organization/bureau")
|
|
|
|
|
}else{
|
|
|
|
|
context.Redirect(301, "/dsBaseWeb/pages/personPortal/")
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
//2、如果此OpenId没有实现过挂接,应该跳转到绑定用户页面
|
|
|
|
|
context.Redirect(301, "/sso/static/bindUser.html?openId="+openId)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|