cheny hace 4 años
padre
commit
bcc8765ad2
Se han modificado 5 ficheros con 30 adiciones y 6 borrados
  1. 3 3
      app/service/login.js
  2. 10 0
      config/config.default.js
  3. 9 1
      config/config.prod.js
  4. 4 0
      config/plugin.js
  5. 4 2
      package.json

+ 3 - 3
app/service/login.js

@@ -85,7 +85,7 @@ class LoginService extends CrudService {
     // }
     // 取出用户的类型,根据用户类型返回相应信息
     const state = uuid();
-    // const key = `free:auth:state:${state}`;
+    const key = `free:auth:state:${state}`;
     // const _menus = [];
     // for (const elm of user.menus) {
     //   const _menu = await this.rmodel.findById({ _id: ObjectId(elm) });
@@ -95,8 +95,8 @@ class LoginService extends CrudService {
     // }
     // user.menus = JSON.stringify(_menus);
     const token = await this.createJwt(user);
-    // await this.app.redis.set(key, token, 'EX', 60 * 60 * 24);
-    return { token };
+    await this.app.redis.set(key, token, 'EX', 60 * 60 * 24);
+    return { key };
   }
 
   // 创建登录Token

+ 10 - 0
config/config.default.js

@@ -66,6 +66,16 @@ module.exports = appInfo => {
     issuer: 'jobs',
   };
 
+  // redis config
+  config.redis = {
+    client: {
+      port: 6379, // Redis port
+      host: '127.0.0.1', // Redis host
+      password: 123456,
+      db: 0,
+    },
+  };
+
   return {
     ...config,
     ...userConfig,

+ 9 - 1
config/config.prod.js

@@ -30,6 +30,14 @@ module.exports = () => {
     app: true,
     agent: true,
   };
-
+  // redis config
+  config.redis = {
+    client: {
+      port: 6379, // Redis port
+      host: '127.0.0.1', // Redis host
+      password: 123456,
+      db: 0,
+    },
+  };
   return config;
 };

+ 4 - 0
config/plugin.js

@@ -5,3 +5,7 @@ exports.amqp = {
   enable: true,
   package: 'egg-naf-amqp',
 };
+exports.redis = {
+  enable: true,
+  package: 'egg-redis',
+};

+ 4 - 2
package.json

@@ -8,12 +8,14 @@
   },
   "dependencies": {
     "egg": "^2.15.1",
+    "egg-naf-amqp": "0.0.13",
+    "egg-redis": "^2.4.0",
     "egg-scripts": "^2.11.0",
     "lodash": "^4.17.15",
     "moment": "^2.24.0",
     "naf-framework-mongoose": "^0.6.11",
-    "silly-datetime": "^0.1.2",
-    "egg-naf-amqp": "0.0.13"
+    "redis": "^3.0.2",
+    "silly-datetime": "^0.1.2"
   },
   "devDependencies": {
     "autod": "^3.0.1",