File tree Expand file tree Collapse file tree 2 files changed +11
-17
lines changed Expand file tree Collapse file tree 2 files changed +11
-17
lines changed Original file line number Diff line number Diff line change 1
- const fetch = require ( "node-fetch" ) ;
2
1
const router = require ( "koa-router" ) ( ) ;
3
2
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
-
15
3
router . get ( "/" , async ( ctx ) => {
16
4
await ctx . render ( "index" , {
17
5
title : "欢迎来到 91 天学算法~" ,
Original file line number Diff line number Diff line change 1
1
const router = require ( "koa-router" ) ( ) ;
2
+ const fetch = require ( "node-fetch" ) ;
2
3
const crypto = require ( "crypto" ) ;
3
4
4
5
const secret = process . env . secret ;
5
6
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
+ ] ;
7
15
8
16
function encrypt ( str ) {
9
17
const cipher = crypto . createCipher ( "aes192" , secret ) ;
@@ -19,7 +27,7 @@ function decrypt(str) {
19
27
return dec ;
20
28
}
21
29
22
- router . get ( "/" , async ( ctx ) => {
30
+ router . get ( "/api/v1/user " , async ( ctx ) => {
23
31
const token = ctx . cookies . get ( "token" ) ;
24
32
25
33
if ( token ) {
@@ -43,9 +51,7 @@ router.get("/", async (ctx) => {
43
51
Authorization : `token ${ access_token } ` ,
44
52
} ,
45
53
} ) . then ( ( res ) => res . json ( ) ) ;
46
- if ( user . login ) {
47
- loginedUsers . add ( user . login ) ;
48
- }
54
+
49
55
if ( db . find ( ( q ) => q . login === user . login ) ) {
50
56
ctx . cookies . set ( "token" , encrypt ( JSON . stringify ( user ) ) , {
51
57
httpOnly : false ,
You can’t perform that action at this time.
0 commit comments