Skip to content

Commit 1d1599e

Browse files
author
lucifer
committed
feat: login
1 parent a29bce2 commit 1d1599e

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

routes/index.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
const fetch = require("node-fetch");
21
const router = require("koa-router")();
32

4-
const clientId = "c16b80e7b58a5a007157";
5-
const clientSecret = process.env.secret;
6-
7-
const db = [
8-
{
9-
login: "azl397985856",
10-
},
11-
];
12-
13-
const loginedUsers = Set();
14-
153
router.get("/", async (ctx) => {
164
await ctx.render("index", {
175
title: "欢迎来到 91 天学算法~",

routes/users.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
const router = require("koa-router")();
2+
const fetch = require("node-fetch");
23
const crypto = require("crypto");
34

45
const secret = process.env.secret;
56

6-
router.prefix("/api/v1/user");
7+
const clientId = "c16b80e7b58a5a007157";
8+
const clientSecret = process.env.secret;
9+
10+
const db = [
11+
{
12+
login: "azl397985856",
13+
},
14+
];
715

816
function encrypt(str) {
917
const cipher = crypto.createCipher("aes192", secret);
@@ -19,7 +27,7 @@ function decrypt(str) {
1927
return dec;
2028
}
2129

22-
router.get("/", async (ctx) => {
30+
router.get("/api/v1/user", async (ctx) => {
2331
const token = ctx.cookies.get("token");
2432

2533
if (token) {
@@ -43,9 +51,7 @@ router.get("/", async (ctx) => {
4351
Authorization: `token ${access_token}`,
4452
},
4553
}).then((res) => res.json());
46-
if (user.login) {
47-
loginedUsers.add(user.login);
48-
}
54+
4955
if (db.find((q) => q.login === user.login)) {
5056
ctx.cookies.set("token", encrypt(JSON.stringify(user)), {
5157
httpOnly: false,

0 commit comments

Comments
 (0)