|
|
|
@ -40,7 +40,7 @@ type CurrentUserInfo struct {
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
var err error
|
|
|
|
|
globalSessions, err = SessionUtil.NewSessionManager("memory", "goSessionid", 3600 * 8)
|
|
|
|
|
globalSessions, err = SessionUtil.NewSessionManager("memory", "goSessionid", 3600 * 24 * 365 * 10)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
return
|
|
|
|
@ -73,12 +73,6 @@ func Login(c *gin.Context) {
|
|
|
|
|
var r *http.Request = c.Request
|
|
|
|
|
|
|
|
|
|
sess := globalSessions.SessionStart(w, r)
|
|
|
|
|
//val := sess.Get("username")
|
|
|
|
|
//if val != nil {
|
|
|
|
|
// fmt.Println(val)
|
|
|
|
|
//} else {
|
|
|
|
|
//
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
username := raw.Username
|
|
|
|
|
password := raw.Password
|
|
|
|
@ -90,8 +84,8 @@ func Login(c *gin.Context) {
|
|
|
|
|
|
|
|
|
|
s, _, accessToken := AccountService.CreateAccessToken("TEST_009", time.Now().Format("200601021504"))
|
|
|
|
|
if s == true {
|
|
|
|
|
c.SetCookie("access_token", accessToken, 3600 * 8, "/", "", false, false)
|
|
|
|
|
c.SetCookie("access_time", time.Now().Format("200601021504"), 3600 * 8, "/", "", false, false)
|
|
|
|
|
c.SetCookie("access_token", accessToken, 3600 * 24 * 365 * 10, "/", "", false, false)
|
|
|
|
|
c.SetCookie("access_time", time.Now().Format("200601021504"), 3600 * 24 * 365 * 10, "/", "", false, false)
|
|
|
|
|
}
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
"status" : "ok",
|
|
|
|
@ -113,7 +107,61 @@ func Login(c *gin.Context) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 后台登陆 godoc
|
|
|
|
|
// @Summary 后台登陆
|
|
|
|
|
// @Description json:"username" xorm:"not null comment('账号') VARCHAR(100)" example:"example"
|
|
|
|
|
// @Tags account
|
|
|
|
|
// @ID loginAccount
|
|
|
|
|
// @Accept json
|
|
|
|
|
// @Produce json
|
|
|
|
|
// @Param input body MySwagger.AccountSwag true "账号密码"
|
|
|
|
|
// @Success 200 {object} MySwagger.Result
|
|
|
|
|
// @Failure 400 {object} MySwagger.Result
|
|
|
|
|
// @Router /support/account/login2 [post]
|
|
|
|
|
func Login2(c *gin.Context) {
|
|
|
|
|
var raw MySwagger.AccountSwag
|
|
|
|
|
|
|
|
|
|
if err := c.ShouldBindJSON(&raw); err != nil {
|
|
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false, Message: "接入系统数据JSON格式错误"})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var w http.ResponseWriter = c.Writer
|
|
|
|
|
var r *http.Request = c.Request
|
|
|
|
|
|
|
|
|
|
sess := globalSessions.SessionStart(w, r)
|
|
|
|
|
|
|
|
|
|
username := raw.Username
|
|
|
|
|
|
|
|
|
|
success, _ := AccountService.Login2(username)
|
|
|
|
|
if success {
|
|
|
|
|
sess.Set("username", username)
|
|
|
|
|
fmt.Println("set session")
|
|
|
|
|
|
|
|
|
|
s, _, accessToken := AccountService.CreateAccessToken("TEST_009", time.Now().Format("200601021504"))
|
|
|
|
|
if s == true {
|
|
|
|
|
c.SetCookie("access_token", accessToken, 3600 * 24 * 365 * 10, "/", "", false, false)
|
|
|
|
|
c.SetCookie("access_time", time.Now().Format("200601021504"), 3600 * 24 * 365 * 10, "/", "", false, false)
|
|
|
|
|
}
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
"status" : "ok",
|
|
|
|
|
"type" : "account",
|
|
|
|
|
"currentAuthority" : username,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
} else {
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
"status" : "error",
|
|
|
|
|
"type" : "account",
|
|
|
|
|
"currentAuthority" : "guest",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 当前登陆者信息 godoc
|
|
|
|
|
// @Summary 当前登陆者信息
|
|
|
|
|