-
Notifications
You must be signed in to change notification settings - Fork 0
Task-8 #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
YurikMurik
wants to merge
1
commit into
task-7
Choose a base branch
from
task-8
base: task-7
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Task-8 #7
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| { | ||
| "courses": [ | ||
| { | ||
| "id": "1", | ||
| "title": "Video about Denmark", | ||
| "createdAtDate": "1/1/2019", | ||
| "durationTime": 120, | ||
| "topRated": true, | ||
| "authors": [], | ||
| "description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Fuga at magni dignissimos accusamus asperiores enim corrupti nobis dolorem ducimus nostrum dolor, consequuntur, quia laudantium tempore? Neque doloremque eos rerum nulla. Fuga at magni dignissimos accusamus asperiores enim corrupti nobis dolorem ducimus nostrum dolor, consequuntur, quia laudantium tempore? Neque doloremque eos rerum nulla." | ||
| }, | ||
| { | ||
| "id": "2", | ||
| "title": "Video about Canada", | ||
| "createdAtDate": "5/20/2020", | ||
| "durationTime": 180, | ||
| "authors": [ | ||
| "me", | ||
| "me" | ||
| ], | ||
| "description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Fuga at magni dignissimos accusamus asperiores enim corrupti nobis dolorem ducimus nostrum dolor, consequuntur, quia laudantium tempore? Neque doloremque eos rerum nulla. Fuga at magni dignissimos accusamus asperiores enim corrupti nobis dolorem ducimus nostrum dolor, consequuntur, quia laudantium tempore? Neque doloremque eos rerum nulla." | ||
| }, | ||
| { | ||
| "id": "3", | ||
| "title": "Video about Brazil", | ||
| "createdAtDate": "12/14/2021", | ||
| "durationTime": 180, | ||
| "topRated": false, | ||
| "authors": [ | ||
| "me", | ||
| "me", | ||
| "id3" | ||
| ], | ||
| "description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Fuga at magni dignissimos accusamus asperiores enim corrupti nobis dolorem ducimus nostrum dolor, consequuntur, quia laudantium tempore? Neque doloremque eos rerum nulla. Fuga at magni dignissimos accusamus asperiores enim corrupti nobis dolorem ducimus nostrum dolor, consequuntur, quia laudantium tempore? Neque doloremque eos rerum nulla." | ||
| }, | ||
| { | ||
| "id": "4", | ||
| "title": "Video about Australia", | ||
| "createdAtDate": "10/20/2020", | ||
| "durationTime": 132, | ||
| "topRated": false, | ||
| "authors": [ | ||
| "me", | ||
| "me", | ||
| "id4" | ||
| ], | ||
| "description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Fuga at magni dignissimos accusamus asperiores enim corrupti nobis dolorem ducimus nostrum dolor, consequuntur, quia laudantium tempore? Neque doloremque eos rerum nulla. Fuga at magni dignissimos accusamus asperiores enim corrupti nobis dolorem ducimus nostrum dolor, consequuntur, quia laudantium tempore? Neque doloremque eos rerum nulla." | ||
| }, | ||
| { | ||
| "id": "6", | ||
| "title": "Video about Sweden", | ||
| "createdAtDate": "1/1/2021", | ||
| "durationTime": 119, | ||
| "topRated": true, | ||
| "authors": [ | ||
| "me", | ||
| "me", | ||
| "id6" | ||
| ], | ||
| "description": "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Fuga at magni dignissimos accusamus asperiores enim corrupti nobis dolorem ducimus nostrum dolor, consequuntur, quia laudantium tempore? Neque doloremque eos rerum nulla. Fuga at magni dignissimos accusamus asperiores enim corrupti nobis dolorem ducimus nostrum dolor, consequuntur, quia laudantium tempore? Neque doloremque eos rerum nulla." | ||
| }, | ||
| { | ||
| "title": "New fantastic course !", | ||
| "createdAtDate": "2020-05-22T21:00:00.000Z", | ||
| "durationTime": "123", | ||
| "description": "Asd asd description ", | ||
| "authors": [ | ||
| "me" | ||
| ], | ||
| "id": "951abhdfm" | ||
| } | ||
| ], | ||
| "users": [ | ||
| { | ||
| "id": 1, | ||
| "firstName": "Vasya", | ||
| "lastName": "Pupkin", | ||
| "login": "vasya", | ||
| "password": "12345", | ||
| "token": "randomtoken_1234556789$" | ||
| } | ||
| ] | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,20 @@ | ||
| import { NgModule } from '@angular/core'; | ||
| import { CommonModule } from '@angular/common'; | ||
| import { HTTP_INTERCEPTORS } from '@angular/common/http'; | ||
| import { AuthInterceptor } from './services/auth-interceptors.service'; | ||
|
|
||
| @NgModule({ | ||
| declarations: [], | ||
| exports: [], | ||
| imports: [ | ||
| CommonModule | ||
| ] | ||
| providers: [ | ||
| [ | ||
| { | ||
| provide: HTTP_INTERCEPTORS, | ||
| useClass: AuthInterceptor, | ||
| multi: true | ||
| } | ||
| ] | ||
| ], | ||
| imports: [ CommonModule ] | ||
| }) | ||
| export class CoreModule { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
|
|
||
| export interface CourseItemInfo { | ||
| id?: number; | ||
| id?: string; | ||
| title: string; | ||
| createdAtDate: Date; | ||
| durationTime: number; | ||
| description: string; | ||
| topRated?: boolean; | ||
| authors?: string; | ||
| authors?: string[]; | ||
| } |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { Injectable } from '@angular/core'; | ||
| import { HttpEvent, HttpHandler, HttpInterceptor, HttpSentEvent } from '@angular/common/http'; | ||
| import { HttpRequest } from '@angular/common/http'; | ||
| import { Observable } from 'rxjs'; | ||
| import { AuthService } from './auth.service'; | ||
| import { CourseItemInfo, UserInfo } from '../models'; | ||
|
|
||
| @Injectable() | ||
| export class AuthInterceptor implements HttpInterceptor { | ||
| constructor(private authService: AuthService) { | ||
| } | ||
|
|
||
| public intercept( | ||
| req: HttpRequest<CourseItemInfo | UserInfo>, | ||
| next: HttpHandler | ||
| ): Observable<HttpEvent<HttpSentEvent>> { | ||
| if (req.headers.get('SkipInterceptor')) { | ||
| return next.handle(req); | ||
| } | ||
|
|
||
| if (this.authService.isAuthentificated()) { | ||
| const clonedRequest: HttpRequest<CourseItemInfo | UserInfo> = req.clone({ | ||
| headers: req.headers.set( | ||
| 'X-CustomAuthHeader', | ||
| this.authService.getToken() | ||
| ) | ||
| }); | ||
| return next.handle(clonedRequest); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,40 @@ | ||
| import { Injectable } from '@angular/core'; | ||
| import { fakeUserInfo } from '../mocks/mocked-user'; | ||
| import { UserInfo } from '../models'; | ||
| import { Observable, of } from 'rxjs'; | ||
| import { Observable } from 'rxjs'; | ||
| import { HttpClient } from '@angular/common/http'; | ||
| import { map } from 'rxjs/operators'; | ||
|
|
||
| @Injectable({ | ||
| providedIn: 'root' | ||
| }) | ||
| export class AuthService { | ||
| private userInfo: UserInfo; | ||
| private userUrl: string = 'http://localhost:3000/users'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. лучше бы в константу |
||
|
|
||
| constructor() { | ||
| this.userInfo = fakeUserInfo; | ||
| } | ||
| constructor( | ||
| private http: HttpClient, | ||
| ) { } | ||
|
|
||
| public getUserInfo(): UserInfo { | ||
| return this.userInfo; | ||
| public getUserInfo(): Observable<UserInfo> { | ||
| return this.http.get<UserInfo>(this.userUrl); | ||
| } | ||
|
|
||
| public userLogin(sentLogin: string, sentPassword: string): boolean { | ||
| const { | ||
| login, | ||
| password, | ||
| firstName, | ||
| lastName, | ||
| token | ||
| } = this.userInfo; | ||
|
|
||
| if (sentLogin === login && sentPassword === password && token) { | ||
| localStorage.setItem('userData', JSON.stringify({ firstName, lastName, token })); | ||
| } | ||
| return this.isAuthentificated(); | ||
| public userLogin(sentLogin: string, sentPassword: string): Observable<boolean> { | ||
| return this.http.get<UserInfo>(this.userUrl, { headers: { SkipInterceptor: 'true' }}) | ||
| .pipe( | ||
| map(data => { | ||
| const { | ||
| login, | ||
| password, | ||
| firstName, | ||
| lastName, | ||
| token | ||
| } = data[0]; | ||
| if ((sentLogin === login) && (sentPassword === password) && token) { | ||
| localStorage.setItem('userData', JSON.stringify({ firstName, lastName, token })); | ||
| } | ||
| return this.isAuthentificated(); | ||
| }) | ||
| ); | ||
| } | ||
|
|
||
| public userLogout(): boolean { | ||
|
|
@@ -41,4 +46,9 @@ export class AuthService { | |
| const userDataFromLS: UserInfo = JSON.parse(localStorage.getItem('userData')); | ||
| return userDataFromLS && !!userDataFromLS.token; | ||
| } | ||
|
|
||
| public getToken(): string { | ||
| const userDataFromLS: UserInfo = JSON.parse(localStorage.getItem('userData')); | ||
| return userDataFromLS.token; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
json-server было бы здорово установить локально)