|
@@ -3,6 +3,7 @@ package auth
|
3
|
3
|
import (
|
4
|
4
|
"time"
|
5
|
5
|
|
|
6
|
+ "git.links123.net/links123.com/pkg/utils"
|
6
|
7
|
"github.com/go-redis/redis"
|
7
|
8
|
)
|
8
|
9
|
|
|
@@ -22,14 +23,21 @@ func NewRedisSessionStore(address string, password string) *RedisSessionStore {
|
22
|
23
|
return session
|
23
|
24
|
}
|
24
|
25
|
|
25
|
|
-func (rss *RedisSessionStore) StoreJwtToken(key string, value string, timeout int64) error {
|
26
|
|
- return rss.client.Set(key, value, time.Duration(timeout) * time.Second).Err()
|
|
26
|
+func (rss *RedisSessionStore) StoreJwtToken(token string, uid int64, timeout int64) error {
|
|
27
|
+ k := utils.Md5(token)
|
|
28
|
+ v := map[string]int64{"user_id": uid, "created": time.Now().Unix()}
|
|
29
|
+
|
|
30
|
+ return rss.client.Set(k, v, time.Duration(timeout)*time.Second).Err()
|
27
|
31
|
}
|
28
|
32
|
|
29
|
|
-func (rss *RedisSessionStore) IsExistsJwtToken(key string) bool {
|
30
|
|
- return rss.client.Exists(key).Val() == 1
|
|
33
|
+func (rss *RedisSessionStore) IsExistsJwtToken(token string) bool {
|
|
34
|
+ k := utils.Md5(token)
|
|
35
|
+
|
|
36
|
+ return rss.client.Exists(k).Val() == 1
|
31
|
37
|
}
|
32
|
38
|
|
33
|
|
-func (rss *RedisSessionStore) DeleteJwtToken(key string) bool {
|
34
|
|
- return rss.client.Del(key).Val() == 1
|
|
39
|
+func (rss *RedisSessionStore) DeleteJwtToken(token string) bool {
|
|
40
|
+ k := utils.Md5(token)
|
|
41
|
+
|
|
42
|
+ return rss.client.Del(k).Val() == 1
|
35
|
43
|
}
|