diff --git a/package.json b/package.json index d45d473c..68d75071 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "bulma": "^0.9.0", "bulma-switch": "^2.0.0", "chart.js": "^2.9.3", - "crypto": "^1.0.1", + "crypto-js": "^4.0.0", "fork-awesome": "^1.1.7", "ng-keyboard-shortcuts": "^10.1.17", "ng2-charts": "^2.3.0", @@ -78,6 +78,7 @@ "@compodoc/compodoc": "^1.1.11", "@types/jest": "^26.0.0", "@types/node": "^14.0.1", + "@types/crypto-js": "^4.0.0", "@typescript-eslint/eslint-plugin": "^3.0.0", "@typescript-eslint/parser": "^3.0.0", "babel-jest": "^26.0.0", diff --git a/src/app/core/services/api.service.ts b/src/app/core/services/api.service.ts index 94196174..3f69f88b 100644 --- a/src/app/core/services/api.service.ts +++ b/src/app/core/services/api.service.ts @@ -171,6 +171,8 @@ export class ApiService { } catch (error) { if (error.response?.status === 404) { return undefined; + } else if (error.response?.status === 403) { + return error; } else { ApiService.handleError(error); } diff --git a/src/app/features/consultation/consultation-routing.module.ts b/src/app/features/consultation/consultation-routing.module.ts index b1f36c89..9432512f 100644 --- a/src/app/features/consultation/consultation-routing.module.ts +++ b/src/app/features/consultation/consultation-routing.module.ts @@ -3,16 +3,17 @@ import { RouterModule, Routes } from '@angular/router'; import { ConsultationComponent } from './consultation.component'; import { WipTodoComponent } from '../../shared/components/ui/wip-todo/wip-todo.component'; +import { PasswordPromptComponent } from './password/password-prompt/password-prompt.component'; const routes: Routes = [ { path: 'secure/:pass_hash', component: ConsultationComponent }, + { path: 'prompt', component: PasswordPromptComponent }, + { path: 'simple', component: WipTodoComponent }, + { path: 'table', component: WipTodoComponent }, { path: '', component: ConsultationComponent, - children: [ - { path: 'simple', component: WipTodoComponent }, - { path: 'table', component: WipTodoComponent }, - ], + children: [], }, ]; @NgModule({ diff --git a/src/app/features/consultation/consultation.module.ts b/src/app/features/consultation/consultation.module.ts index 7091bdbe..7771ab14 100644 --- a/src/app/features/consultation/consultation.module.ts +++ b/src/app/features/consultation/consultation.module.ts @@ -8,6 +8,7 @@ import { ConsultationComponent } from './consultation.component'; import { PollResultsCompactComponent } from './poll-results-compact/poll-results-compact.component'; import { PollResultsDetailedComponent } from './poll-results-detailed/poll-results-detailed.component'; import { ChoiceButtonComponent } from '../../shared/components/choice-item/choice-button.component'; +import { PasswordPromptComponent } from './password/password-prompt/password-prompt.component'; @NgModule({ declarations: [ @@ -15,6 +16,7 @@ import { ChoiceButtonComponent } from '../../shared/components/choice-item/choic PollResultsCompactComponent, PollResultsDetailedComponent, ChoiceButtonComponent, + PasswordPromptComponent, ], imports: [CommonModule, ConsultationRoutingModule, SharedModule, TranslateModule.forChild({ extend: true })], }) diff --git a/src/app/features/consultation/password/password-prompt/password-prompt.component.html b/src/app/features/consultation/password/password-prompt/password-prompt.component.html new file mode 100644 index 00000000..9b2aa1aa --- /dev/null +++ b/src/app/features/consultation/password/password-prompt/password-prompt.component.html @@ -0,0 +1,29 @@ +
+

+ + Sondage protégé +

+

Pour accéder au sondage {{ custom_url }} il vous faut saisir la phrase de passe.

+ + +
+ +
+ Méthode de chiffrement 1: + + Méthode de chiffrement 2: + + + steak haché: + {{ cipherPass() }} + +
+ + +
diff --git a/src/app/features/consultation/password/password-prompt/password-prompt.component.scss b/src/app/features/consultation/password/password-prompt/password-prompt.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/src/app/features/consultation/password/password-prompt/password-prompt.component.spec.ts b/src/app/features/consultation/password/password-prompt/password-prompt.component.spec.ts new file mode 100644 index 00000000..93c88861 --- /dev/null +++ b/src/app/features/consultation/password/password-prompt/password-prompt.component.spec.ts @@ -0,0 +1,24 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PasswordPromptComponent } from './password-prompt.component'; + +describe('PasswordPromptComponent', () => { + let component: PasswordPromptComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [PasswordPromptComponent], + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(PasswordPromptComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/features/consultation/password/password-prompt/password-prompt.component.ts b/src/app/features/consultation/password/password-prompt/password-prompt.component.ts new file mode 100644 index 00000000..9350276b --- /dev/null +++ b/src/app/features/consultation/password/password-prompt/password-prompt.component.ts @@ -0,0 +1,34 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, ParamMap, Router } from '@angular/router'; +import { MD5, enc } from 'crypto-js'; + +@Component({ + selector: 'app-password-prompt', + templateUrl: './password-prompt.component.html', + styleUrls: ['./password-prompt.component.scss'], +}) +export class PasswordPromptComponent implements OnInit { + password = 'le pass woute woute'; + method = 'md5'; + display_pass = true; + custom_url = ''; + password_ciphered: string; + + constructor(private router: Router, private _Activatedroute: ActivatedRoute) {} + + ngOnInit(): void { + this._Activatedroute.paramMap.subscribe((params: ParamMap) => { + this.custom_url = params.get('custom_url'); + }); + } + + cipherPass() { + this.password_ciphered = MD5(this.password).toString(enc.Hex); + this.password_ciphered = MD5(this.password_ciphered).toString(enc.Hex); + return this.password_ciphered; + } + + redirectToConsultationPage() { + this.router.navigate(['/poll/' + this.custom_url + '/consultation/secure/' + this.password_ciphered]); + } +} diff --git a/yarn.lock b/yarn.lock index ee06a708..1cfae0be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1678,6 +1678,11 @@ resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0" integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ== +"@types/crypto-js@^4.0.0": + version "4.0.1" + resolved "https://registry.yarnpkg.com/@types/crypto-js/-/crypto-js-4.0.1.tgz#3a4bd24518b0e6c5940da4e2659eeb2ef0806963" + integrity sha512-6+OPzqhKX/cx5xh+yO8Cqg3u3alrkhoxhE5ZOdSEv0DOzJ13lwJ6laqGU0Kv6+XDMFmlnGId04LtY22PsFLQUw== + "@types/eslint-visitor-keys@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d" @@ -3745,16 +3750,16 @@ crypto-js@^3.1.9-1: resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-3.3.0.tgz#846dd1cce2f68aacfa156c8578f926a609b7976b" integrity sha512-DIT51nX0dCfKltpRiXV+/TVZq+Qq2NgF4644+K7Ttnla7zEzqc+kjJyiB96BHNyUTBxyjzRcZYpUdZa+QAqi6Q== +crypto-js@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.0.0.tgz#2904ab2677a9d042856a2ea2ef80de92e4a36dcc" + integrity sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg== + crypto-random-string@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-2.0.0.tgz#ef2a7a966ec11083388369baa02ebead229b30d5" integrity sha512-v1plID3y9r/lPhviJ1wrXpLeyUIGAZ2SHNYTEapm7/8A9nLPoyvVp3RK/EPFqn5kEznyWgYZNsRtYYIWbuG8KA== -crypto@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/crypto/-/crypto-1.0.1.tgz#2af1b7cad8175d24c8a1b0778255794a21803037" - integrity sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig== - css-color-names@0.0.4, css-color-names@^0.0.4: version "0.0.4" resolved "https://registry.yarnpkg.com/css-color-names/-/css-color-names-0.0.4.tgz#808adc2e79cf84738069b646cb20ec27beb629e0"