File tree 4 files changed +23
-7
lines changed 4 files changed +23
-7
lines changed Original file line number Diff line number Diff line change 1
1
2
2
import { db } from "./database" ;
3
+ import { sessionStore } from "./session-store" ;
3
4
4
5
5
6
export function readAllLessons ( req , res ) {
6
7
7
- res . status ( 200 ) . json ( db . readAllLessons ( ) ) ;
8
+ const sessionId = req . cookies [ "SESSIONID" ] ;
9
+
10
+ const isSessionValid = sessionStore . isSessionValid ( sessionId ) ;
11
+
12
+ if ( ! isSessionValid ) {
13
+ res . sendStatus ( 403 ) ;
14
+ }
15
+ else {
16
+ res . status ( 200 ) . json ( { lessons :db . readAllLessons ( ) } ) ;
17
+ }
8
18
9
19
}
Original file line number Diff line number Diff line change @@ -15,11 +15,15 @@ class SessionStore {
15
15
16
16
const session = this . sessions [ sessionId ] ;
17
17
18
- const isSessionValid = session && session . isValid ( ) ;
19
-
20
- return isSessionValid ? session . user : undefined ;
18
+ return this . isSessionValid ( sessionId ) ? session . user : undefined ;
21
19
}
22
20
21
+ isSessionValid ( sessionId : string ) : boolean {
22
+
23
+ const session = this . sessions [ sessionId ] ;
24
+
25
+ return session && session . isValid ( ) ;
26
+ }
23
27
}
24
28
25
29
Original file line number Diff line number Diff line change 1
1
2
- < div class ="lessons-list-container v-h-center-block-parent ">
2
+ < div class ="lessons-list-container v-h-center-block-parent " *ngIf =" isLoggedIn$ | async " >
3
3
4
4
< h2 > All Lessons</ h2 >
5
5
Original file line number Diff line number Diff line change 2
2
import { Injectable } from "@angular/core" ;
3
3
import { HttpClient } from "@angular/common/http" ;
4
4
import { Lesson } from "../model/lesson" ;
5
+ import { Observable } from "rxjs/Observable" ;
5
6
6
7
7
8
@Injectable ( )
@@ -11,8 +12,9 @@ export class LessonsService {
11
12
12
13
}
13
14
14
- loadAllLessons ( ) {
15
- return this . http . get < Lesson [ ] > ( '/api/lessons' ) ;
15
+ loadAllLessons ( ) : Observable < Lesson [ ] > {
16
+ return this . http . get < any > ( '/api/lessons' )
17
+ . map ( res => res . lessons ) ;
16
18
}
17
19
18
20
findLessonById ( id :number ) {
You can’t perform that action at this time.
0 commit comments