-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2579a96
commit e47f6da
Showing
8 changed files
with
134 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package controller | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/taoshihan1991/miaosha/redis" | ||
) | ||
|
||
func checkUserLogin(c *gin.Context) (string, bool) { | ||
session := c.Query("session") | ||
info := redis.GetUserInfo(session) | ||
if session == "" || info == "" { | ||
c.JSON(200, gin.H{ | ||
"code": 400, | ||
"msg": "error please login", | ||
}) | ||
return "", false | ||
} | ||
|
||
return info, true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package controller | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/taoshihan1991/miaosha/redis" | ||
"github.com/taoshihan1991/miaosha/utils" | ||
) | ||
|
||
func GetUserInfo(c *gin.Context) { | ||
session := c.Query("session") | ||
redis.NewRedis() | ||
info := redis.GetUserInfo(session) | ||
if info == "" { | ||
c.JSON(200, gin.H{ | ||
"code": 400, | ||
"msg": "error please login", | ||
}) | ||
return | ||
} | ||
c.JSON(200, gin.H{ | ||
"code": 200, | ||
"msg": "success", | ||
"data": gin.H{ | ||
"username": info, | ||
}, | ||
}) | ||
} | ||
func PostUserInfo(c *gin.Context) { | ||
name := c.PostForm("name") | ||
session := utils.Md5(name) | ||
redis.NewRedis() | ||
info := redis.GetUserInfo(session) | ||
if info != "" { | ||
c.JSON(200, gin.H{ | ||
"code": 400, | ||
"msg": "error username exist", | ||
}) | ||
return | ||
} | ||
redis.SetUserInfo(session, name) | ||
c.JSON(200, gin.H{ | ||
"code": 200, | ||
"msg": "success", | ||
"data": session, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package redis | ||
|
||
import "time" | ||
|
||
func GetUserInfo(session string) string { | ||
key := "session_" + session | ||
return GetStr(key) | ||
} | ||
func SetUserInfo(session string, str string) string { | ||
key := "session_" + session | ||
return SetStr(key, str, 30*time.Minute) | ||
} |