Ver código fonte

Merge branch 'test' into dev

formation 3 anos atrás
pai
commit
06b7c89f86
50 arquivos alterados com 354 adições e 243 exclusões
  1. 1 1
      angular-client/karma-ci.conf.js
  2. 47 5
      angular-client/package-lock.json
  3. 1 1
      angular-client/package.json
  4. 4 4
      angular-client/src/app/app.component.spec.ts
  5. 2 2
      angular-client/src/app/components/admin/assistance/assistance-list/assistance-list.component.spec.ts
  6. 2 2
      angular-client/src/app/components/admin/assistance/assistance.component.spec.ts
  7. 2 2
      angular-client/src/app/components/admin/assistance/response-contact/response-contact.component.spec.ts
  8. 2 2
      angular-client/src/app/components/admin/emailing/email-form/email-form.component.spec.ts
  9. 2 2
      angular-client/src/app/components/admin/emailing/emailing.component.spec.ts
  10. 2 2
      angular-client/src/app/components/admin/lots/lots.component.spec.ts
  11. 2 2
      angular-client/src/app/components/admin/statistic/statistic.component.spec.ts
  12. 2 2
      angular-client/src/app/components/admin/users/users-bloque/users-bloque.component.spec.ts
  13. 2 2
      angular-client/src/app/components/admin/users/users-delete/users-delete.component.spec.ts
  14. 2 2
      angular-client/src/app/components/admin/users/users-details/users-details.component.spec.ts
  15. 2 2
      angular-client/src/app/components/admin/users/users-edit/users-edit.component.spec.ts
  16. 2 2
      angular-client/src/app/components/admin/users/users-form/users-form.component.spec.ts
  17. 2 2
      angular-client/src/app/components/admin/users/users-list/users-list.component.spec.ts
  18. 2 2
      angular-client/src/app/components/admin/users/users.component.spec.ts
  19. 2 2
      angular-client/src/app/components/auth/gain/gain-form/gain-form.component.spec.ts
  20. 2 2
      angular-client/src/app/components/auth/gain/gain-list/gain-list.component.spec.ts
  21. 2 2
      angular-client/src/app/components/auth/gain/gain.component.spec.ts
  22. 2 2
      angular-client/src/app/components/auth/profil/edit-profil-info-connexion/edit-profil-info-connexion.component.spec.ts
  23. 2 2
      angular-client/src/app/components/auth/profil/edit-profil-info-user/edit-profil-info-user.component.spec.ts
  24. 11 7
      angular-client/src/app/components/auth/profil/edit-profil-info-user/edit-profil-info-user.component.ts
  25. 2 2
      angular-client/src/app/components/auth/profil/profil.component.spec.ts
  26. 2 2
      angular-client/src/app/components/home/home.component.spec.ts
  27. 39 3
      angular-client/src/app/components/login/login.component.spec.ts
  28. 2 2
      angular-client/src/app/components/login/lost-password/lost-password.component.spec.ts
  29. 2 2
      angular-client/src/app/components/login/reset-password/reset-password.component.spec.ts
  30. 12 0
      angular-client/src/app/components/register/register.component.html
  31. 10 1
      angular-client/src/app/components/register/register.component.scss
  32. 2 2
      angular-client/src/app/components/register/register.component.spec.ts
  33. 8 0
      angular-client/src/app/components/register/register.component.ts
  34. 2 2
      angular-client/src/app/components/shared/alert-message/alert-message.component.spec.ts
  35. 2 2
      angular-client/src/app/components/shared/cgu/cgu.component.spec.ts
  36. 2 2
      angular-client/src/app/components/shared/confirm-message/confirm-message.component.spec.ts
  37. 2 2
      angular-client/src/app/components/shared/contact/contact.component.spec.ts
  38. 2 2
      angular-client/src/app/components/shared/contact/formulaire/confirm/confirm.component.spec.ts
  39. 2 2
      angular-client/src/app/components/shared/contact/formulaire/formulaire.component.spec.ts
  40. 2 2
      angular-client/src/app/components/shared/contact/information/information.component.spec.ts
  41. 2 2
      angular-client/src/app/components/shared/contact/map/map.component.spec.ts
  42. 2 2
      angular-client/src/app/components/shared/footer/footer.component.spec.ts
  43. 2 2
      angular-client/src/app/components/shared/mentions-legales/mentions-legales.component.spec.ts
  44. 2 2
      angular-client/src/app/components/shared/navbar/navbar.component.spec.ts
  45. 2 2
      angular-client/src/app/components/shared/not-found/not-found.component.spec.ts
  46. 2 2
      angular-client/src/app/components/shared/politique-confidentialite/politique-confidentialite.component.spec.ts
  47. 7 7
      express-server/index.js
  48. 2 2
      express-server/lib/db.js
  49. 30 30
      express-server/routes/facebook.js
  50. 108 108
      express-server/routes/google.js

+ 1 - 1
angular-client/karma-ci.conf.js

@@ -46,7 +46,7 @@ module.exports = function (config) {
         outputDir: 'target/surefire-reports/TESTS-TestSuite.xml'
     },
     angularCli: {
-      environment: 'dev'
+      environment: 'test'
     },
     reporters: ['progress', 'kjhtml', 'junit'],
     browsers: ['ChromeHeadless'],

+ 47 - 5
angular-client/package-lock.json

@@ -2464,6 +2464,16 @@
       "integrity": "sha512-Phlt0plgpIIBOGTT/ehfFnbNlfsDEiqmzE2KRXoX1bLIlir4X/MR+zSyBEkL05ffWgnRSf/DXv+WrUAVr93/ow==",
       "dev": true
     },
+    "bindings": {
+      "version": "1.5.0",
+      "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
+      "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
+      "dev": true,
+      "optional": true,
+      "requires": {
+        "file-uri-to-path": "1.0.0"
+      }
+    },
     "bl": {
       "version": "4.0.2",
       "resolved": "https://registry.npmjs.org/bl/-/bl-4.0.2.tgz",
@@ -5058,6 +5068,13 @@
         "schema-utils": "^2.6.5"
       }
     },
+    "file-uri-to-path": {
+      "version": "1.0.0",
+      "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
+      "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==",
+      "dev": true,
+      "optional": true
+    },
     "fileset": {
       "version": "2.0.3",
       "resolved": "https://registry.npmjs.org/fileset/-/fileset-2.0.3.tgz",
@@ -8367,6 +8384,13 @@
       "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==",
       "dev": true
     },
+    "nan": {
+      "version": "2.17.0",
+      "resolved": "https://registry.npmjs.org/nan/-/nan-2.17.0.tgz",
+      "integrity": "sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==",
+      "dev": true,
+      "optional": true
+    },
     "nanomatch": {
       "version": "1.2.13",
       "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz",
@@ -13287,7 +13311,11 @@
           "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz",
           "integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==",
           "dev": true,
-          "optional": true
+          "optional": true,
+          "requires": {
+            "bindings": "^1.5.0",
+            "nan": "^2.12.1"
+          }
         },
         "is-binary-path": {
           "version": "1.0.1",
@@ -13685,7 +13713,11 @@
           "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz",
           "integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==",
           "dev": true,
-          "optional": true
+          "optional": true,
+          "requires": {
+            "bindings": "^1.5.0",
+            "nan": "^2.12.1"
+          }
         },
         "is-absolute-url": {
           "version": "3.0.3",
@@ -14244,9 +14276,19 @@
       "dev": true
     },
     "zone.js": {
-      "version": "0.10.3",
-      "resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.10.3.tgz",
-      "integrity": "sha512-LXVLVEq0NNOqK/fLJo3d0kfzd4sxwn2/h67/02pjCjfKDxgx1i9QqpvtHD8CrBnSSwMw5+dy11O7FRX5mkO7Cg=="
+      "version": "0.11.3",
+      "resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.11.3.tgz",
+      "integrity": "sha512-Y4hTHoh4VcxU5BDGAqEoOnOiyT254w6CiHtpQxAJUSMZPyVgdbKf+5R7Mwz6xsPhMIeBXk5rTopRZDpjssTCUg==",
+      "requires": {
+        "tslib": "^2.0.0"
+      },
+      "dependencies": {
+        "tslib": {
+          "version": "2.4.0",
+          "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz",
+          "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ=="
+        }
+      }
     }
   }
 }

+ 1 - 1
angular-client/package.json

@@ -37,7 +37,7 @@
     "rxjs": "~6.5.4",
     "saturn-datepicker": "^8.0.5",
     "tslib": "^1.10.0",
-    "zone.js": "~0.10.2"
+    "zone.js": "^0.11.3"
   },
   "devDependencies": {
     "@angular-devkit/build-angular": "~0.901.4",

+ 4 - 4
angular-client/src/app/app.component.spec.ts

@@ -1,9 +1,9 @@
-import { TestBed, waitForAsync } from '@angular/core/testing';
+import { TestBed, async } from '@angular/core/testing';
 import { RouterTestingModule } from '@angular/router/testing';
 import { AppComponent } from './app.component';
 
 describe('AppComponent', () => {
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       imports: [
         RouterTestingModule
@@ -29,7 +29,7 @@ describe('AppComponent', () => {
   it('should render title', () => {
     const fixture = TestBed.createComponent(AppComponent);
     fixture.detectChanges();
-    const compiled = fixture.nativeElement;
-    expect(compiled.querySelector('.content span').textContent).toContain('fatboar app is running!');
+    const compiled = fixture.nativeElement as HTMLElement;
+    expect(compiled.querySelector('h1').textContent).toContain('fatboar app is running!');
   });
 });

+ 2 - 2
angular-client/src/app/components/admin/assistance/assistance-list/assistance-list.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { AssistanceListComponent } from './assistance-list.component';
 
@@ -6,7 +6,7 @@ describe('AssistanceListComponent', () => {
   let component: AssistanceListComponent;
   let fixture: ComponentFixture<AssistanceListComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ AssistanceListComponent ]
     })

+ 2 - 2
angular-client/src/app/components/admin/assistance/assistance.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { AssistanceComponent } from './assistance.component';
 
@@ -6,7 +6,7 @@ describe('AssistanceComponent', () => {
   let component: AssistanceComponent;
   let fixture: ComponentFixture<AssistanceComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ AssistanceComponent ]
     })

+ 2 - 2
angular-client/src/app/components/admin/assistance/response-contact/response-contact.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { ResponseContactComponent } from './response-contact.component';
 
@@ -6,7 +6,7 @@ describe('ResponseContactComponent', () => {
   let component: ResponseContactComponent;
   let fixture: ComponentFixture<ResponseContactComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ ResponseContactComponent ]
     })

+ 2 - 2
angular-client/src/app/components/admin/emailing/email-form/email-form.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { EmailFormComponent } from './email-form.component';
 
@@ -6,7 +6,7 @@ describe('EmailFormComponent', () => {
   let component: EmailFormComponent;
   let fixture: ComponentFixture<EmailFormComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ EmailFormComponent ]
     })

+ 2 - 2
angular-client/src/app/components/admin/emailing/emailing.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { EmailingComponent } from './emailing.component';
 
@@ -6,7 +6,7 @@ describe('EmailingComponent', () => {
   let component: EmailingComponent;
   let fixture: ComponentFixture<EmailingComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ EmailingComponent ]
     })

+ 2 - 2
angular-client/src/app/components/admin/lots/lots.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { LotsComponent } from './lots.component';
 
@@ -6,7 +6,7 @@ describe('LotsComponent', () => {
   let component: LotsComponent;
   let fixture: ComponentFixture<LotsComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ LotsComponent ]
     })

+ 2 - 2
angular-client/src/app/components/admin/statistic/statistic.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { StatisticComponent } from './statistic.component';
 
@@ -6,7 +6,7 @@ describe('StatisticComponent', () => {
   let component: StatisticComponent;
   let fixture: ComponentFixture<StatisticComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ StatisticComponent ]
     })

+ 2 - 2
angular-client/src/app/components/admin/users/users-bloque/users-bloque.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { UsersBloqueComponent } from './users-bloque.component';
 
@@ -6,7 +6,7 @@ describe('UsersBloqueComponent', () => {
   let component: UsersBloqueComponent;
   let fixture: ComponentFixture<UsersBloqueComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ UsersBloqueComponent ]
     })

+ 2 - 2
angular-client/src/app/components/admin/users/users-delete/users-delete.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { UsersDeleteComponent } from './users-delete.component';
 
@@ -6,7 +6,7 @@ describe('UsersDeleteComponent', () => {
   let component: UsersDeleteComponent;
   let fixture: ComponentFixture<UsersDeleteComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ UsersDeleteComponent ]
     })

+ 2 - 2
angular-client/src/app/components/admin/users/users-details/users-details.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { UsersDetailsComponent } from './users-details.component';
 
@@ -6,7 +6,7 @@ describe('UsersDetailsComponent', () => {
   let component: UsersDetailsComponent;
   let fixture: ComponentFixture<UsersDetailsComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ UsersDetailsComponent ]
     })

+ 2 - 2
angular-client/src/app/components/admin/users/users-edit/users-edit.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { UsersEditComponent } from './users-edit.component';
 
@@ -6,7 +6,7 @@ describe('UsersEditComponent', () => {
   let component: UsersEditComponent;
   let fixture: ComponentFixture<UsersEditComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ UsersEditComponent ]
     })

+ 2 - 2
angular-client/src/app/components/admin/users/users-form/users-form.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { UsersFormComponent } from './users-form.component';
 
@@ -6,7 +6,7 @@ describe('UsersFormComponent', () => {
   let component: UsersFormComponent;
   let fixture: ComponentFixture<UsersFormComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ UsersFormComponent ]
     })

+ 2 - 2
angular-client/src/app/components/admin/users/users-list/users-list.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { UsersListComponent } from './users-list.component';
 
@@ -6,7 +6,7 @@ describe('UsersListComponent', () => {
   let component: UsersListComponent;
   let fixture: ComponentFixture<UsersListComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ UsersListComponent ]
     })

+ 2 - 2
angular-client/src/app/components/admin/users/users.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { UsersComponent } from './users.component';
 
@@ -6,7 +6,7 @@ describe('UsersComponent', () => {
   let component: UsersComponent;
   let fixture: ComponentFixture<UsersComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ UsersComponent ]
     })

+ 2 - 2
angular-client/src/app/components/auth/gain/gain-form/gain-form.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { GainFormComponent } from './gain-form.component';
 
@@ -6,7 +6,7 @@ describe('GainFormComponent', () => {
   let component: GainFormComponent;
   let fixture: ComponentFixture<GainFormComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ GainFormComponent ]
     })

+ 2 - 2
angular-client/src/app/components/auth/gain/gain-list/gain-list.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { GainListComponent } from './gain-list.component';
 
@@ -6,7 +6,7 @@ describe('GainListComponent', () => {
   let component: GainListComponent;
   let fixture: ComponentFixture<GainListComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ GainListComponent ]
     })

+ 2 - 2
angular-client/src/app/components/auth/gain/gain.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { GainComponent } from './gain.component';
 
@@ -6,7 +6,7 @@ describe('GainComponent', () => {
   let component: GainComponent;
   let fixture: ComponentFixture<GainComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ GainComponent ]
     })

+ 2 - 2
angular-client/src/app/components/auth/profil/edit-profil-info-connexion/edit-profil-info-connexion.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { EditProfilInfoConnexionComponent } from './edit-profil-info-connexion.component';
 
@@ -6,7 +6,7 @@ describe('EditProfilInfoConnexionComponent', () => {
   let component: EditProfilInfoConnexionComponent;
   let fixture: ComponentFixture<EditProfilInfoConnexionComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ EditProfilInfoConnexionComponent ]
     })

+ 2 - 2
angular-client/src/app/components/auth/profil/edit-profil-info-user/edit-profil-info-user.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { EditProfilInfoUserComponent } from './edit-profil-info-user.component';
 
@@ -6,7 +6,7 @@ describe('EditProfilInfoUserComponent', () => {
   let component: EditProfilInfoUserComponent;
   let fixture: ComponentFixture<EditProfilInfoUserComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ EditProfilInfoUserComponent ]
     })

+ 11 - 7
angular-client/src/app/components/auth/profil/edit-profil-info-user/edit-profil-info-user.component.ts

@@ -1,8 +1,10 @@
 import { UsersService } from './../../../../services/users.service';
+import { AuthService } from 'src/app/services/auth.service'
 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
 import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
 import { User } from './../../../../models/userResponse';
 import { Component, Inject, OnInit } from '@angular/core';
+import { Router } from '@angular/router';
 
 @Component({
   selector: 'app-edit-profil-info-user',
@@ -11,11 +13,12 @@ import { Component, Inject, OnInit } from '@angular/core';
 })
 export class EditProfilInfoUserComponent implements OnInit {
 
-  constructor(@Inject(MAT_DIALOG_DATA) public element: User,  public dialogRef: MatDialogRef<EditProfilInfoUserComponent>,
-    private formBuilder: FormBuilder, private usersService: UsersService)
+  constructor(@Inject(MAT_DIALOG_DATA) public element: User, public router: Router, private authService : AuthService,  public dialogRef: MatDialogRef<EditProfilInfoUserComponent>,
+    private formBuilder: FormBuilder, private usersService: UsersService )
    {}
    formGroup: FormGroup;
    submitted = false;
+   loading = false;
    user = this.element
 
    ngOnInit(): void {
@@ -46,13 +49,14 @@ export class EditProfilInfoUserComponent implements OnInit {
     data => {
         // this.router.navigate([this.returnUrl]);
         console.log(data)
-        // this.loading = false;
-        // this.router.navigate(['auth']);
+         this.loading = false;
+         this.dialogRef.close(true);
+        //this.router.navigate(['auth']);
     },
     err => {
-        // this.loading = false;
-        // console.log(err.error.message)
-        // this.authService.openSnackBar(err.error.message)
+         this.loading = false;
+        console.log(err.error.message)
+         this.authService.openSnackBar(err.error.message)
     });
 }
 

+ 2 - 2
angular-client/src/app/components/auth/profil/profil.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { ProfilComponent } from './profil.component';
 
@@ -6,7 +6,7 @@ describe('ProfilComponent', () => {
   let component: ProfilComponent;
   let fixture: ComponentFixture<ProfilComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ ProfilComponent ]
     })

+ 2 - 2
angular-client/src/app/components/home/home.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { HomeComponent } from './home.component';
 
@@ -6,7 +6,7 @@ describe('HomeComponent', () => {
   let component: HomeComponent;
   let fixture: ComponentFixture<HomeComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ HomeComponent ]
     })

+ 39 - 3
angular-client/src/app/components/login/login.component.spec.ts

@@ -1,14 +1,29 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
+import { FormsModule, ReactiveFormsModule } from '@angular/forms';
+import { Router } from '@angular/router';
 
 import { LoginComponent } from './login.component';
+import { AuthService } from 'src/app/services/auth.service';
+
+
+class AuthServiceMock { }
+class RouterMock { }
+
+
 
 describe('LoginComponent', () => {
   let component: LoginComponent;
   let fixture: ComponentFixture<LoginComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
-      declarations: [ LoginComponent ]
+      imports: [ FormsModule, ReactiveFormsModule ],
+      declarations: [ LoginComponent ],
+      providers: [
+        { provide: Router, useClass: RouterMock },
+        { provide: AuthService, useClass: AuthServiceMock }
+      ]
     })
     .compileComponents();
   }));
@@ -22,4 +37,25 @@ describe('LoginComponent', () => {
   it('should create', () => {
     expect(component).toBeTruthy();
   });
+
+  it('should display the page header text', () => {
+    const el = fixture.debugElement.query(By.css('h1')).nativeElement;
+    expect(el.textContent).toContain('Connexion');
+  });
+
+  it('should display the username and password inputs', () => {
+    const [inputUsername, inputPassword] = fixture.debugElement.queryAll(By.css('input'));
+    expect(inputUsername.nativeElement).toBeTruthy();
+    expect(inputPassword.nativeElement).toBeTruthy();
+    expect(inputUsername.nativeElement.value).toBeFalsy();
+    expect(inputPassword.nativeElement.value).toBeFalsy();
+  });
+
+  it('should display the login button', () => {
+    const el = fixture.debugElement.query(By.css('button')).nativeElement;
+    expect(el).toBeTruthy();
+    expect(el.textContent).toContain('Connexion');
+    expect(el.disabled).toBeTruthy();
+  });
+
 });

+ 2 - 2
angular-client/src/app/components/login/lost-password/lost-password.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { LostPasswordComponent } from './lost-password.component';
 
@@ -6,7 +6,7 @@ describe('LostPasswordComponent', () => {
   let component: LostPasswordComponent;
   let fixture: ComponentFixture<LostPasswordComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ LostPasswordComponent ]
     })

+ 2 - 2
angular-client/src/app/components/login/reset-password/reset-password.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { ResetPasswordComponent } from './reset-password.component';
 
@@ -6,7 +6,7 @@ describe('ResetPasswordComponent', () => {
   let component: ResetPasswordComponent;
   let fixture: ComponentFixture<ResetPasswordComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ ResetPasswordComponent ]
     })

+ 12 - 0
angular-client/src/app/components/register/register.component.html

@@ -109,6 +109,18 @@
               </mat-error>
               </mat-form-field>
             </div>
+            <div class="row justify-content-center">
+              <div class="control" controlErrorContainer>
+                <label class="checkbox">
+                <input type="checkbox" formControlName="terms" [customErrors]="customErrors">
+                <p class="row justify-content-center mt-3"> J'ai lu et j'accepte <a href="#"> les conditions générales d'utilisation </a> et j'ai pris connaissance de la <a href="#"> politique de confidentialité.</a></p>
+                </label>
+                <mat-error *ngIf="!formGroup.controls['terms'].valid || formGroup.controls['terms'].touched">
+                  {{ getErrorTerms() }}
+                </mat-error>
+              </div>
+            </div>
+
 
   
             <div class="row justify-content-center mt-3">

+ 10 - 1
angular-client/src/app/components/register/register.component.scss

@@ -5,4 +5,13 @@
 
   .marginButton{
     margin-bottom: 0em !important;
-  }
+  }
+  
+.terms{  
+  display: block;
+  margin-left: 3.5rem;
+  }
+
+  .test{ 
+  font-size: x-small;
+}

+ 2 - 2
angular-client/src/app/components/register/register.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { RegisterComponent } from './register.component';
 
@@ -6,7 +6,7 @@ describe('RegisterComponent', () => {
   let component: RegisterComponent;
   let fixture: ComponentFixture<RegisterComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ RegisterComponent ]
     })

+ 8 - 0
angular-client/src/app/components/register/register.component.ts

@@ -52,6 +52,7 @@ export class RegisterComponent implements OnInit {
       firstname: [null, [Validators.required, Validators.pattern(caracereregex)]],
       phonenumber: [null,[Validators.required, Validators.pattern(phonenumberregex)]],
       birthday: [null,[Validators.required]],
+      terms: ['', Validators.requiredTrue],
       adress: [null,[Validators.required, Validators.pattern(adressregex)]],
       email: [null, [Validators.required, Validators.pattern(emailregex)]],
       password: [null, [Validators.required, this.checkPassword]],
@@ -95,6 +96,13 @@ export class RegisterComponent implements OnInit {
     this.formGroup.get('birthday').hasError('pattern') ? 'Date de naissance non valide' : '';
   }
 
+  getErrorTerms(){
+
+    return this.formGroup.get('terms').hasError('required') ? 'Please accept the terms' : 
+    this.formGroup.get('terms').hasError('pattern') ? 'Date de naissance non valide' : '';
+
+  }
+
   getErrorConfirmPassword() {
     return this.formGroup.get('confirmPassword').hasError('required') ? 'Confirmation mot de passe requise' :
       this.formGroup.hasError('MustMatch') ? 

+ 2 - 2
angular-client/src/app/components/shared/alert-message/alert-message.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { AlertMessageComponent } from './alert-message.component';
 
@@ -6,7 +6,7 @@ describe('AlertMessageComponent', () => {
   let component: AlertMessageComponent;
   let fixture: ComponentFixture<AlertMessageComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ AlertMessageComponent ]
     })

+ 2 - 2
angular-client/src/app/components/shared/cgu/cgu.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { CguComponent } from './cgu.component';
 
@@ -6,7 +6,7 @@ describe('CguComponent', () => {
   let component: CguComponent;
   let fixture: ComponentFixture<CguComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ CguComponent ]
     })

+ 2 - 2
angular-client/src/app/components/shared/confirm-message/confirm-message.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { ConfirmMessageComponent } from './confirm-message.component';
 
@@ -6,7 +6,7 @@ describe('ConfirmMessageComponent', () => {
   let component: ConfirmMessageComponent;
   let fixture: ComponentFixture<ConfirmMessageComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ ConfirmMessageComponent ]
     })

+ 2 - 2
angular-client/src/app/components/shared/contact/contact.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { ContactComponent } from './contact.component';
 
@@ -6,7 +6,7 @@ describe('ContactComponent', () => {
   let component: ContactComponent;
   let fixture: ComponentFixture<ContactComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ ContactComponent ]
     })

+ 2 - 2
angular-client/src/app/components/shared/contact/formulaire/confirm/confirm.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { ConfirmComponent } from './confirm.component';
 
@@ -6,7 +6,7 @@ describe('ConfirmComponent', () => {
   let component: ConfirmComponent;
   let fixture: ComponentFixture<ConfirmComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ ConfirmComponent ]
     })

+ 2 - 2
angular-client/src/app/components/shared/contact/formulaire/formulaire.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { FormulaireComponent } from './formulaire.component';
 
@@ -6,7 +6,7 @@ describe('FormulaireComponent', () => {
   let component: FormulaireComponent;
   let fixture: ComponentFixture<FormulaireComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ FormulaireComponent ]
     })

+ 2 - 2
angular-client/src/app/components/shared/contact/information/information.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { InformationComponent } from './information.component';
 
@@ -6,7 +6,7 @@ describe('InformationComponent', () => {
   let component: InformationComponent;
   let fixture: ComponentFixture<InformationComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ InformationComponent ]
     })

+ 2 - 2
angular-client/src/app/components/shared/contact/map/map.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { MapComponent } from './map.component';
 
@@ -6,7 +6,7 @@ describe('MapComponent', () => {
   let component: MapComponent;
   let fixture: ComponentFixture<MapComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ MapComponent ]
     })

+ 2 - 2
angular-client/src/app/components/shared/footer/footer.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { FooterComponent } from './footer.component';
 
@@ -6,7 +6,7 @@ describe('FooterComponent', () => {
   let component: FooterComponent;
   let fixture: ComponentFixture<FooterComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ FooterComponent ]
     })

+ 2 - 2
angular-client/src/app/components/shared/mentions-legales/mentions-legales.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { MentionsLegalesComponent } from './mentions-legales.component';
 
@@ -6,7 +6,7 @@ describe('MentionsLegalesComponent', () => {
   let component: MentionsLegalesComponent;
   let fixture: ComponentFixture<MentionsLegalesComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ MentionsLegalesComponent ]
     })

+ 2 - 2
angular-client/src/app/components/shared/navbar/navbar.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { NavbarComponent } from './navbar.component';
 
@@ -6,7 +6,7 @@ describe('NavbarComponent', () => {
   let component: NavbarComponent;
   let fixture: ComponentFixture<NavbarComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ NavbarComponent ]
     })

+ 2 - 2
angular-client/src/app/components/shared/not-found/not-found.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { NotFoundComponent } from './not-found.component';
 
@@ -6,7 +6,7 @@ describe('NotFoundComponent', () => {
   let component: NotFoundComponent;
   let fixture: ComponentFixture<NotFoundComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ NotFoundComponent ]
     })

+ 2 - 2
angular-client/src/app/components/shared/politique-confidentialite/politique-confidentialite.component.spec.ts

@@ -1,4 +1,4 @@
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
 
 import { PolitiqueConfidentialiteComponent } from './politique-confidentialite.component';
 
@@ -6,7 +6,7 @@ describe('PolitiqueConfidentialiteComponent', () => {
   let component: PolitiqueConfidentialiteComponent;
   let fixture: ComponentFixture<PolitiqueConfidentialiteComponent>;
 
-  beforeEach(waitForAsync(() => {
+  beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ PolitiqueConfidentialiteComponent ]
     })

+ 7 - 7
express-server/index.js

@@ -2,7 +2,7 @@ const express = require('express');
 const bodyparser = require('body-parser');
 const passport = require('passport');
 const mongoose = require('mongoose');
-const cors = require('cors');
+//const cors = require('cors');
 // const config = require('./config/db.config');
 
 
@@ -12,8 +12,8 @@ const authRoutes = require('./routes/auth');
 //const oauthRoutes = require('./routes/oauth');
 const ticketRoutes = require('./routes/ticket');
 const emailsRoutes = require('./routes/emailing');
-//const authGoogle = require('./routes/google');
-//const authFacebook = require('./routes/facebook');
+const authGoogle = require('./routes/google');
+const authFacebook = require('./routes/facebook');
 const tirageRoutes = require('./routes/tirage');
 const contactRoutes = require('./routes/contact');
 const restaurantRoutes = require('./routes/restaurant');
@@ -37,7 +37,7 @@ app.use(metricsMiddleware);
 
 //metrics
 app.use(makeApiMiddleware()); 
-app.use(cors());
+//app.use(cors());
 
 app.get("/api", (req, res) => {
     res.status(200).send("Api Works.");
@@ -69,7 +69,7 @@ app.use(function(req, res, next) {
 // parse requests  body params
 app.use(bodyparser.json());
 app.use(bodyparser.urlencoded({extended: true}));
-app.use(passport.initialize());
+//app.use(passport.initialize());
 
 //simple route
 app.use('/api/users', userRoutes );
@@ -79,8 +79,8 @@ app.use('/api/auth',  authRoutes );
 //app.use('/api/auth', oauthRoutes );
 //app.use('/api/auth',  authGoogle );
 app.use('/api/emails',  emailsRoutes );
-//app.use('/api/auth/google',  authGoogle );
-//app.use('/api/auth/facebook',  authFacebook );
+app.use('/api/auth/google',  authGoogle );
+app.use('/api/auth/facebook',  authFacebook );
 app.use('/api/tirage',  tirageRoutes );
 app.use('/api/contact',  contactRoutes );
 app.use('/api/restaurants',  restaurantRoutes );

+ 2 - 2
express-server/lib/db.js

@@ -30,13 +30,13 @@ module.exports = mongoose.connection;
 
 // let min = 999999999;
 // let max = 10000000000;
-// for (i = 0; i < 2; i++) {
+// for (i = 0; i < 50000; i++) {
 //     let code = Math.floor(Math.random() * (max - min + 1)) + min;
      
 //          const ticke = new Ticket({
 //              code: code,
 //              isUsed: false,
-//              gains: "un menu du jour",
+//              gains: "une entrée ou un dessert au choix",
 //              date_used: new Date(),
 //              index: 'index',
 //              isServed: true

+ 30 - 30
express-server/routes/facebook.js

@@ -1,38 +1,38 @@
-// const express = require('express');
-// const router = express.Router();
-// const { Email } = require('../models/email.model');
-// const { User } = require('../models/user.model');
-// const nodemailer = require('nodemailer');
+const express = require('express');
+const router = express.Router();
+const { Email } = require('../models/email.model');
+const { User } = require('../models/user.model');
+const nodemailer = require('nodemailer');
 
-// const passport = require('passport');
-// const  FacebookStrategy  = require('passport-facebook').Strategy;
+const passport = require('passport');
+const  FacebookStrategy  = require('passport-facebook').Strategy;
 
-// passport.use(new FacebookStrategy({
-//     clientID: "318954999682335",
-//     clientSecret: "9f8d5261decefbaf556f4c42539ee358",
-//     callbackURL: "http://localhost:4000/api/auth/facebook/callback",
-//     enableProof: false
-//   },
+passport.use(new FacebookStrategy({
+    clientID: "318954999682335",
+    clientSecret: "9f8d5261decefbaf556f4c42539ee358",
+    callbackURL: "http://localhost:4000/api/auth/facebook/callback",
+    enableProof: false
+  },
  
-//   (accessToken, refreshToken, profile, done) => {
-//    try{
-//     console.log('acces token ',accessToken);
-//     console.log('refresh token ',refreshToken);
-//     console.log('profile ',profile);
-//     console.log('done ',done);
-// }  catch(error){
-//    console.log(error)
-// }
+  (accessToken, refreshToken, profile, done) => {
+   try{
+    console.log('acces token ',accessToken);
+    console.log('refresh token ',refreshToken);
+    console.log('profile ',profile);
+    console.log('done ',done);
+}  catch(error){
+   console.log(error)
+}
     
-//   }
-// ));
+  }
+));
 
 
-// router.get('/', passport.authenticate('facebook' ) );
-// router.get('/callback',  passport.authenticate('facebook',
-//  { successRedirect: '/profile',
-//   failureRedirect: '/'}
-//   ));
+router.get('/', passport.authenticate('facebook' ) );
+router.get('/callback',  passport.authenticate('facebook',
+ { successRedirect: '/profile',
+  failureRedirect: '/'}
+  ));
 
 
-// module.exports = router; 
+module.exports = router; 

+ 108 - 108
express-server/routes/google.js

@@ -1,79 +1,79 @@
-// const express = require('express');
-// const router = express.Router();
-// const jwt = require("jsonwebtoken");
-// const { Email } = require('../models/email.model');
-// const { User } = require('../models/user.model');
-// const nodemailer = require('nodemailer');
-// const role = require('../lib/role');
-// require('dotenv').config();
+const express = require('express');
+const router = express.Router();
+const jwt = require("jsonwebtoken");
+const { Email } = require('../models/email.model');
+const { User } = require('../models/user.model');
+const nodemailer = require('nodemailer');
+const role = require('../lib/role');
+//require('dotenv').config();
 
-// const passport = require('passport');
-// const GoogleStrategy = require('passport-google-oauth20').Strategy;
+const passport = require('passport');
+const GoogleStrategy = require('passport-google-oauth20').Strategy;
 
-// router.use(passport.initialize());
-// //router.use(passport.session());
+router.use(passport.initialize());
+//router.use(passport.session());
 
 
-// passport.serializeUser((user, cb) => {
-//   cb(null, user);
-// });
+passport.serializeUser((user, cb) => {
+  cb(null, user);
+});
 
 
-// passport.deserializeUser((obj, cb) => {
-//   cb(null, obj);
-// });
+passport.deserializeUser((obj, cb) => {
+  cb(null, obj);
+});
 
 
-// // passport.use(new GoogleStrategy({
-// //     clientID: "493465923713-qrbgtq8d53iguine1gf928483mn4odes.apps.googleusercontent.com",
-// //     clientSecret: "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",
-// //     callbackURL: "http://localhost:4000/api/auth/google/callback"
-// //   },
+// passport.use(new GoogleStrategy({
+//     clientID: "493465923713-qrbgtq8d53iguine1gf928483mn4odes.apps.googleusercontent.com",
+//     clientSecret: "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",
+//     callbackURL: "http://localhost:4000/api/auth/google/callback"
+//   },
 
-// //      async  (accessToken, refreshToken, profile, done) => {
+//      async  (accessToken, refreshToken, profile, done) => {
 
 
-// //       console.log(profile.emails[0].value)
+//       console.log(profile.emails[0].value)
 
-// //        return done(null, profile);
+//        return done(null, profile);
 
-// //  var email = profile.emails[0].value
-// //  const user =  await User.findOne({email: email})
+//  var email = profile.emails[0].value
+//  const user =  await User.findOne({email: email})
 
 
-// // if (user) {
-// //   console.log(user)
-// //   user.username = accessToken;
+// if (user) {
+//   console.log(user)
+//   user.username = accessToken;
 
 
-// //   user.save().then(()=>{
-// //     return done(null, user);
-// //   })
-// // }else{
+//   user.save().then(()=>{
+//     return done(null, user);
+//   })
+// }else{
 
-// // console.log('creation of user')
-// // //make a new record
-// // let user = await new User({
-// //   googleId: profile.id,
-// //   email: profile.emails[0].value,
-// //   accessToken : accessToken,
-// //   refreshToken : refreshToken
-// // }).save()
-// // done(null, user);
-// // }
+// console.log('creation of user')
+// //make a new record
+// let user = await new User({
+//   googleId: profile.id,
+//   email: profile.emails[0].value,
+//   accessToken : accessToken,
+//   refreshToken : refreshToken
+// }).save()
+// done(null, user);
+// }
 
 
 
 
 
-// // console.log('acces token ',accessToken);
-// // console.log('refresh token ',refreshToken);
-// //  console.log('prfile ',profile.emails[0].value);
-// // console.log('done ',done);
+// console.log('acces token ',accessToken);
+// console.log('refresh token ',refreshToken);
+//  console.log('prfile ',profile.emails[0].value);
+// console.log('done ',done);
 
 
-// //   }
-// // ));
+//   }
+// ));
 
 
 
@@ -84,77 +84,77 @@
 
 
 
-// passport.use(new GoogleStrategy({
-//   clientID: "493465923713-qrbgtq8d53iguine1gf928483mn4odes.apps.googleusercontent.com",
-//   clientSecret: "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",
-//   callbackURL: "http://localhost:4000/api/auth/google/callback"
-// },
-// async (req, accessToken, refreshToken, profile, cb) => {
-
-//     User.findOne({ email: profile.emails[0].value }, (err, user) => {
-//       if (err) {
-//         cb(err); // handle errors!
-//       }
-//       if (!err && user !== null) {
-//         cb(err, user);
-//       }
-//       else {
-
-//         user = new User({
-//           googleId: profile.id,
-//           email: profile.emails[0].value,
-//           firstname: profile.name.givenName,
-//           lastname: profile.name.familyName,
-//           role: role.Client,
-//           isActive: true,
-//           isGain: false,
-//         });
-
-//         user.save((err) => {
-//           if (err) {
-//             cb(err); // handle errors!
-//           } else {
-//             cb(null, user);
-//           }
-//         });
-//       }
-//     });
-//   }
-// ));
+passport.use(new GoogleStrategy({
+  clientID: "493465923713-qrbgtq8d53iguine1gf928483mn4odes.apps.googleusercontent.com",
+  clientSecret: "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",
+  callbackURL: "http://localhost:4000/api/auth/google/callback"
+},
+async (req, accessToken, refreshToken, profile, cb) => {
+
+    User.findOne({ email: profile.emails[0].value }, (err, user) => {
+      if (err) {
+        cb(err); // handle errors!
+      }
+      if (!err && user !== null) {
+        cb(err, user);
+      }
+      else {
+
+        user = new User({
+          googleId: profile.id,
+          email: profile.emails[0].value,
+          firstname: profile.name.givenName,
+          lastname: profile.name.familyName,
+          role: role.Client,
+          isActive: true,
+          isGain: false,
+        });
+
+        user.save((err) => {
+          if (err) {
+            cb(err); // handle errors!
+          } else {
+            cb(null, user);
+          }
+        });
+      }
+    });
+  }
+));
 
 
 
 
 
-// router.get('/', passport.authenticate('google', { session: false, scope: ['profile', 'email'] }), 
-// async () => {
-//   console.log('je suis dans mon get root')
-// });
+router.get('/', passport.authenticate('google', { session: false, scope: ['profile', 'email'] }), 
+async () => {
+  console.log('je suis dans mon get root')
+});
 
-// // router.get('/callback', passport.authenticate('google') )
+// router.get('/callback', passport.authenticate('google') )
 
 
 
-// router.get('/callback',  passport.authenticate('google', { failureRedirect: '/failed' }),
-//   async (req, res) => {
-//       console.log('je susi dans ma fonction callback ', req.user)
-//       const token = jwt.sign({ userId: req.user._id, email: req.user.email, role: req.user.role }, process.env.SECRET_KEY, { expiresIn: '10 h' })
-//        //res.status(200).json({ success: true, token, expireIn: `${new Date().getTime() + 120000}` })
-//       console.log(token) 
-//       res.redirect(`${process.env.URL}/auth/?token=${token}`);
-//     });
+router.get('/callback',  passport.authenticate('google', { failureRedirect: '/failed' }),
+  async (req, res) => {
+      console.log('je susi dans ma fonction callback ', req.user)
+      const token = jwt.sign({ userId: req.user._id, email: req.user.email, role: req.user.role }, process.env.SECRET_KEY, { expiresIn: '10 h' })
+       //res.status(200).json({ success: true, token, expireIn: `${new Date().getTime() + 120000}` })
+      console.log(token) 
+      res.redirect(`http://localhost:4200/auth/?token=${token}`);
+    });
 
 
-// //failed auth google 
-// router.get('/failed', async (req, res) => { res.status(404).send('erreur authentification') })
+//failed auth google 
+router.get('/failed', async (req, res) => { res.status(404).send('erreur authentification') })
 
 
 
-// //get all users
-// router.get('/good', async (req, res) => {
+//get all users
+router.get('/good', async (req, res) => {
 
-//   res.status(200).send('welcome mr ');
-// })
+  res.status(200).send('welcome mr ');
+})
 
 
 
@@ -162,4 +162,4 @@
 
 
 
-// module.exports = router; 
+module.exports = router;