diff --git a/api/.idea/workspace.xml b/api/.idea/workspace.xml index 75c87912dd3b5131bd81144c017ff443c5862a79..ea2ba50d1de92a45e44d07a8ba441965262c506e 100644 --- a/api/.idea/workspace.xml +++ b/api/.idea/workspace.xml @@ -20,16 +20,23 @@ </component> <component name="ChangeListManager"> <list default="true" id="79458ffd-9370-4e15-812e-5103bfca39de" name="Default Changelist" comment=""> + <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/routes/messages_routes.js" beforeDir="false" afterPath="$PROJECT_DIR$/routes/messages_routes.js" afterDir="false" /> <change beforePath="$PROJECT_DIR$/routes/rooms_routes.js" beforeDir="false" afterPath="$PROJECT_DIR$/routes/rooms_routes.js" afterDir="false" /> <change beforePath="$PROJECT_DIR$/routes/users_routes.js" beforeDir="false" afterPath="$PROJECT_DIR$/routes/users_routes.js" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/server.js" beforeDir="false" afterPath="$PROJECT_DIR$/server.js" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/../ionic/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../ionic/.idea/vcs.xml" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/../ionic/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../ionic/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../ionic/src/app/app-routing.module.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../ionic/src/app/app-routing.module.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../ionic/src/app/app.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../ionic/src/app/app.component.ts" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/../ionic/src/app/auth/login/login.page.html" beforeDir="false" afterPath="$PROJECT_DIR$/../ionic/src/app/auth/login/login.page.html" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/../ionic/src/app/auth/login/login.page.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../ionic/src/app/auth/login/login.page.ts" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/../ionic/src/app/conversation/conversation.page.html" beforeDir="false" afterPath="$PROJECT_DIR$/../ionic/src/app/conversation/conversation.page.html" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/../ionic/src/app/conversation/conversation.page.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../ionic/src/app/conversation/conversation.page.ts" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/../ionic/src/app/global.service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../ionic/src/app/global.service.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../ionic/src/app/services/tab3.service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../ionic/src/app/services/tab3.service.ts" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/../ionic/src/app/tab1/tab1.page.html" beforeDir="false" afterPath="$PROJECT_DIR$/../ionic/src/app/tab1/tab1.page.html" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/../ionic/src/app/tab1/tab1.page.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../ionic/src/app/tab1/tab1.page.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../ionic/src/app/tab3/tab3.page.html" beforeDir="false" afterPath="$PROJECT_DIR$/../ionic/src/app/tab3/tab3.page.html" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../ionic/src/app/tab3/tab3.page.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../ionic/src/app/tab3/tab3.page.ts" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/../ionic/src/app/tabs/tabs.page.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../ionic/src/app/tabs/tabs.page.ts" afterDir="false" /> </list> <option name="SHOW_DIALOG" value="false" /> <option name="HIGHLIGHT_CONFLICTS" value="true" /> @@ -65,6 +72,10 @@ <updated>1611921289511</updated> <workItem from="1611921290628" duration="9485000" /> <workItem from="1611931390283" duration="1223000" /> + <workItem from="1612089474992" duration="2366000" /> + <workItem from="1612185070940" duration="92000" /> + <workItem from="1616839353281" duration="2544000" /> + <workItem from="1616922102856" duration="2050000" /> </task> <servers /> </component> @@ -83,4 +94,10 @@ </option> <option name="oldMeFiltersMigrated" value="true" /> </component> + <component name="WindowStateProjectService"> + <state x="779" y="311" width="424" height="491" key="FileChooserDialogImpl" timestamp="1612185160871"> + <screen x="72" y="27" width="1848" height="1053" /> + </state> + <state x="779" y="311" width="424" height="491" key="FileChooserDialogImpl/72.27.1848.1053@72.27.1848.1053" timestamp="1612185160871" /> + </component> </project> \ No newline at end of file diff --git a/api/routes/messages_routes.js b/api/routes/messages_routes.js index 655d94e6fbd78b89fe7b0ca909780de0b3d195cd..020a84f7d02b76b3d248a1fe71327cc69cf27c7c 100644 --- a/api/routes/messages_routes.js +++ b/api/routes/messages_routes.js @@ -12,6 +12,8 @@ router.post('/', async function(req, res, next){ let author = null; let room = null; + console.log("author : " + req.user.id); + console.log("rommId : " + req.body.roomId); try { author = await User.findById(req.user.id).exec(); room = await Room.findById(req.body.roomId).exec(); diff --git a/api/routes/rooms_routes.js b/api/routes/rooms_routes.js index 665fc01c50532b4a1e1d13e71028ff9f493d83f6..a1d0b30c48009640e955272894d33e5844af59ef 100644 --- a/api/routes/rooms_routes.js +++ b/api/routes/rooms_routes.js @@ -41,6 +41,7 @@ router.post('/', async function(req, res, next){ // Pas de room publique router.get('/', async function (req, res, next){ let room = null; + console.log(req.user.id); try { room = await Room.find({users: req.user.id}).populate('users'); } catch(err) { @@ -60,6 +61,8 @@ router.get('/', async function (req, res, next){ router.get('/:id/messages', async function (req, res, next) { let room = null; + console.log(req.params.id); + try { room = await Room.findById(req.params.id); } catch (err){ diff --git a/api/routes/users_routes.js b/api/routes/users_routes.js index e545169ea8ade784760231de31c6519fa05c10ab..cdf2de8c76776a3889490dda3128eb3d43d5a739 100644 --- a/api/routes/users_routes.js +++ b/api/routes/users_routes.js @@ -7,6 +7,7 @@ import jwt from 'jsonwebtoken'; // Créer un nouvel utilisateur router.post('/', async function(req, res){ + console.log(req.body); if (!req.body.username) { return res.status(400).json({ diff --git a/ionic/.idea/vcs.xml b/ionic/.idea/vcs.xml index 94a25f7f4cb416c083d265558da75d457237d671..288b36b1efb71c411d5c27a1ea6c08e41a7fed46 100644 --- a/ionic/.idea/vcs.xml +++ b/ionic/.idea/vcs.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$/.." vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" /> </component> </project> \ No newline at end of file diff --git a/ionic/.idea/workspace.xml b/ionic/.idea/workspace.xml index 1643d76c4127f8be9c906a1362636582563efbd9..b1c337321d2b95d14d01d7c7dd14fc730827ffcd 100644 --- a/ionic/.idea/workspace.xml +++ b/ionic/.idea/workspace.xml @@ -2,16 +2,10 @@ <project version="4"> <component name="ChangeListManager"> <list default="true" id="9cc781ee-29d5-4b75-ae20-525abe98f749" name="Default Changelist" comment=""> - <change beforePath="$PROJECT_DIR$/ionic.config.json" beforeDir="false" afterPath="$PROJECT_DIR$/ionic.config.json" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/package-lock.json" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/app/app-routing.module.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/app-routing.module.ts" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/app/tab1/tab1.page.html" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/tab1/tab1.page.html" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/app/tab2/tab2.page.html" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/tab2/tab2.page.html" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/app/tab3/tab3.page.html" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/tab3/tab3.page.html" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/app/tab3/tab3.page.scss" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/tab3/tab3.page.scss" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/app/tabs/tabs.page.html" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/tabs/tabs.page.html" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/theme/variables.scss" beforeDir="false" afterPath="$PROJECT_DIR$/src/theme/variables.scss" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/../api/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../api/.idea/workspace.xml" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/../api/routes/messages_routes.js" beforeDir="false" afterPath="$PROJECT_DIR$/../api/routes/messages_routes.js" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/../api/routes/rooms_routes.js" beforeDir="false" afterPath="$PROJECT_DIR$/../api/routes/rooms_routes.js" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/../api/routes/users_routes.js" beforeDir="false" afterPath="$PROJECT_DIR$/../api/routes/users_routes.js" afterDir="false" /> </list> <option name="SHOW_DIALOG" value="false" /> <option name="HIGHLIGHT_CONFLICTS" value="true" /> @@ -22,9 +16,10 @@ <execution /> </component> <component name="Git.Settings"> - <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> + <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." /> </component> <component name="ProjectId" id="1mYdwbwpn2oA6tSartxgyroG60q" /> + <component name="ProjectLevelVcsManager" settingsEditedManually="true" /> <component name="ProjectViewState"> <option name="hideEmptyMiddlePackages" value="true" /> <option name="showLibraryContents" value="true" /> @@ -34,7 +29,7 @@ <property name="RunOnceActivity.ShowReadmeOnStart" value="true" /> <property name="WebServerToolWindowFactoryState" value="false" /> <property name="dart.analysis.tool.window.visible" value="false" /> - <property name="last_opened_file_path" value="$PROJECT_DIR$/platforms/android" /> + <property name="last_opened_file_path" value="$PROJECT_DIR$/src/app/services/conversation" /> <property name="node.js.detected.package.tslint" value="true" /> <property name="node.js.path.for.package.tslint" value="project" /> <property name="node.js.selected.package.tslint" value="(autodetect)" /> @@ -43,7 +38,12 @@ <property name="ts.external.directory.path" value="$PROJECT_DIR$/node_modules/typescript/lib" /> <property name="vue.rearranger.settings.migration" value="true" /> </component> - <component name="RunManager"> + <component name="RecentsManager"> + <key name="CopyFile.RECENT_KEYS"> + <recent name="$PROJECT_DIR$/src/app/services/conversation" /> + </key> + </component> + <component name="RunManager" selected="JavaScript Debug.Angular Application"> <configuration name="E2E Tests (app)" type="JavaScriptTestRunnerProtractor"> <config-file value="$PROJECT_DIR$/e2e/protractor.conf.js" /> <node-interpreter value="project" /> @@ -66,7 +66,7 @@ <method v="2" /> </configuration> </component> - <component name="SpellCheckerSettings" BundledDictionaries="0" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" Dictionaries="0" CorrectionsLimit="5" DefaultDictionary="application-level" UseSingleDictionary="true" /> + <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> <component name="SvnConfiguration"> <configuration /> </component> @@ -79,6 +79,9 @@ <updated>1609674697438</updated> <workItem from="1609674698560" duration="1630000" /> <workItem from="1610370594809" duration="111000" /> + <workItem from="1616658846989" duration="319000" /> + <workItem from="1616839188513" duration="3313000" /> + <workItem from="1616922103931" duration="3010000" /> </task> <servers /> </component> @@ -90,9 +93,9 @@ <screen x="72" y="27" width="1848" height="1053" /> </state> <state x="454" y="211" key="#com.intellij.execution.impl.EditConfigurationsDialog/72.27.1848.1053@72.27.1848.1053" timestamp="1611221615660" /> - <state x="779" y="311" width="424" height="491" key="FileChooserDialogImpl" timestamp="1611221651546"> + <state x="779" y="311" width="424" height="491" key="FileChooserDialogImpl" timestamp="1616839347885"> <screen x="72" y="27" width="1848" height="1053" /> </state> - <state x="779" y="311" width="424" height="491" key="FileChooserDialogImpl/72.27.1848.1053@72.27.1848.1053" timestamp="1611221651546" /> + <state x="779" y="311" width="424" height="491" key="FileChooserDialogImpl/72.27.1848.1053@72.27.1848.1053" timestamp="1616839347885" /> </component> </project> \ No newline at end of file diff --git a/ionic/src/app/app-routing.module.ts b/ionic/src/app/app-routing.module.ts index f340c53a7d4c9d4d173a1808f748b23a8e1ef4de..13053a8518cf88eddb037f07e617990e4d98de38 100644 --- a/ionic/src/app/app-routing.module.ts +++ b/ionic/src/app/app-routing.module.ts @@ -7,12 +7,16 @@ const routes: Routes = [ loadChildren: () => import('./tabs/tabs.module').then(m => m.TabsPageModule) }, { - path: 'conversation', + path: 'conversation/:id', loadChildren: () => import('./conversation/conversation.module').then( m => m.ConversationPageModule) }, { path: 'login', loadChildren: () => import('./auth/login/login.module').then( m => m.LoginPageModule) + }, + { + path: 'register', + loadChildren: () => import('./auth/register/register.module').then( m => m.RegisterPageModule) } ]; @NgModule({ diff --git a/ionic/src/app/app.component.ts b/ionic/src/app/app.component.ts index 00f78a85f612339f537f4ebbacba53f78d30b713..a95c3a22ed7edcd6fc73558cda279c51e089a865 100644 --- a/ionic/src/app/app.component.ts +++ b/ionic/src/app/app.component.ts @@ -21,7 +21,7 @@ export class AppComponent { initializeApp() { this.platform.ready().then(() => { - if(!localStorage.getItem('token')){ + if (!localStorage.getItem('token')){ this.router.navigateByUrl('/login'); } this.statusBar.styleDefault(); diff --git a/ionic/src/app/auth/login/login.page.html b/ionic/src/app/auth/login/login.page.html index 3d3e477a5e646bdc3f0c71eff23297ac0a8b5640..32bef520c322456af0a3e707b610eec967f825f2 100644 --- a/ionic/src/app/auth/login/login.page.html +++ b/ionic/src/app/auth/login/login.page.html @@ -1,5 +1,5 @@ <ion-content padding> - <form class="form_login" #form="ngForm" (ngSubmit)="login(form)"> + <form class="form_login" #form="ngForm"> <ion-grid> <ion-row class="ion-justify-content-center"> <ion-col class="align-self-center" size-md="6" size-lg="5" size-xs="12"> @@ -15,10 +15,15 @@ </ion-item> </div> <div class="ion-padding"> - <ion-button size="large" type="submit" [disabled]="form.invalid" expand="block">Se connecter</ion-button> + <ion-button size="large" type="submit" [disabled]="form.invalid" expand="block" (click)="login(form)">Se connecter</ion-button> + </div> + <div class="ion-padding"> + <ion-button size="large" routerLink="/register" expand="block"> + S'inscrire + </ion-button> </div> </ion-col> </ion-row> </ion-grid> </form> -</ion-content> \ No newline at end of file +</ion-content> diff --git a/ionic/src/app/auth/login/login.page.ts b/ionic/src/app/auth/login/login.page.ts index 5cc3b69ced31dc5a95cf2549b3ac09a388ec7a63..39693b1593a6b293a5d07255b74ef62167f0ad79 100644 --- a/ionic/src/app/auth/login/login.page.ts +++ b/ionic/src/app/auth/login/login.page.ts @@ -1,12 +1,11 @@ import { Component, OnInit } from '@angular/core'; -import { Router } from "@angular/router"; +import { Router } from '@angular/router'; import { HttpClient } from '@angular/common/http'; -import { GlobalService } from "../../global.service"; +import { GlobalService } from '../../global.service'; import { LoginService } from '../../services/auth/login/login.service'; import { AlertController } from '@ionic/angular'; - @Component({ selector: 'app-login', templateUrl: './login.page.html', @@ -14,7 +13,8 @@ import { AlertController } from '@ionic/angular'; }) export class LoginPage implements OnInit { - constructor(private router: Router, private http: HttpClient, private global: GlobalService, private loginService: LoginService, private alertController: AlertController) {} + constructor(private router: Router, private http: HttpClient, private global: GlobalService, private loginService: LoginService, + private alertController: AlertController) {} async presentAlert() { const alert = await this.alertController.create({ @@ -33,19 +33,18 @@ export class LoginPage implements OnInit { async login(form){ - let results = await this.loginService.authenticate(form); + const results = await this.loginService.authenticate(form); results.subscribe(res => { - if(res.token){ - localStorage.setItem('token',res.token) - localStorage.setItem('user',`{ + if ( res.token ){ + localStorage.setItem('token', res.token); + localStorage.setItem('user', `{ "username":"${res.user.username}", "id":"${res.user.id}" - }`) + }`); this.router.navigate(['tabs/tab1']); }else{ this.presentAlert(); } - - }) + }); } -} \ No newline at end of file +} diff --git a/ionic/src/app/auth/register/register-routing.module.ts b/ionic/src/app/auth/register/register-routing.module.ts new file mode 100644 index 0000000000000000000000000000000000000000..ec4af6e8b4598103524d48c860bfdfe243db213e --- /dev/null +++ b/ionic/src/app/auth/register/register-routing.module.ts @@ -0,0 +1,17 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +import { RegisterPage } from './register.page'; + +const routes: Routes = [ + { + path: '', + component: RegisterPage + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class RegisterPageRoutingModule {} diff --git a/ionic/src/app/auth/register/register.module.ts b/ionic/src/app/auth/register/register.module.ts new file mode 100644 index 0000000000000000000000000000000000000000..0b18f979c7ecd85c0fdffdaf17f15edee6fbf382 --- /dev/null +++ b/ionic/src/app/auth/register/register.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; + +import { IonicModule } from '@ionic/angular'; + +import { RegisterPageRoutingModule } from './register-routing.module'; + +import { RegisterPage } from './register.page'; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + IonicModule, + RegisterPageRoutingModule + ], + declarations: [RegisterPage] +}) +export class RegisterPageModule {} diff --git a/ionic/src/app/auth/register/register.page.html b/ionic/src/app/auth/register/register.page.html new file mode 100644 index 0000000000000000000000000000000000000000..2a055be1b59016140e3820311fb8cbb941b68576 --- /dev/null +++ b/ionic/src/app/auth/register/register.page.html @@ -0,0 +1,29 @@ +<ion-content padding> + <form class="form_reg" #form="ngForm"> + <ion-grid> + <ion-row class="ion-justify-content-center"> + <ion-col class="align-self-center" size-md="6" size-lg="5" size-xs="12"> + <div class="ion-text-center"> + <h3>S'inscrire</h3> + </div> + <div class="ion-padding"> + <ion-item> + <ion-input name="username" type="utilisateur" placeholder="Nom d'utilisateur" ngModel required></ion-input> + </ion-item> + <ion-item> + <ion-input name="password" type="password" placeholder="Mot de passe" ngModel required></ion-input> + </ion-item> + </div> + <div class="ion-padding"> + <ion-button size="large" type="submit" [disabled]="form.invalid" (click)="register(form)" expand="block">S'inscrire</ion-button> + </div> + <div class="ion-padding"> + <ion-button size="large" routerLink="/login" expand="block"> + Se connecter + </ion-button> + </div> + </ion-col> + </ion-row> + </ion-grid> + </form> +</ion-content> diff --git a/ionic/src/app/auth/register/register.page.scss b/ionic/src/app/auth/register/register.page.scss new file mode 100644 index 0000000000000000000000000000000000000000..052d2ec26f6f4124a4ec1754c331b284e603e068 --- /dev/null +++ b/ionic/src/app/auth/register/register.page.scss @@ -0,0 +1,6 @@ +.form_reg { + display: flex !important; + justify-content: center !important; + align-items: center !important; + height: 100%; +} diff --git a/ionic/src/app/auth/register/register.page.spec.ts b/ionic/src/app/auth/register/register.page.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..78ab86699ba036d4754f0b275efe27a4d932302f --- /dev/null +++ b/ionic/src/app/auth/register/register.page.spec.ts @@ -0,0 +1,24 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { IonicModule } from '@ionic/angular'; + +import { RegisterPage } from './register.page'; + +describe('RegisterPage', () => { + let component: RegisterPage; + let fixture: ComponentFixture<RegisterPage>; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ RegisterPage ], + imports: [IonicModule.forRoot()] + }).compileComponents(); + + fixture = TestBed.createComponent(RegisterPage); + component = fixture.componentInstance; + fixture.detectChanges(); + })); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ionic/src/app/auth/register/register.page.ts b/ionic/src/app/auth/register/register.page.ts new file mode 100644 index 0000000000000000000000000000000000000000..5b59232e84b90baecf419c305c67f5db632fde8b --- /dev/null +++ b/ionic/src/app/auth/register/register.page.ts @@ -0,0 +1,43 @@ +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { HttpClient } from '@angular/common/http'; +import { GlobalService } from '../../global.service'; +import { AlertController } from '@ionic/angular'; +import { RegisterService } from '../../services/auth/register/register.service'; +import {LoginService} from '../../services/auth/login/login.service'; + + + +@Component({ + selector: 'app-register', + templateUrl: './register.page.html', + styleUrls: ['./register.page.scss'], +}) +export class RegisterPage implements OnInit { + + constructor(private router: Router, private http: HttpClient, private global: GlobalService, private registerService: RegisterService, + private alertController: AlertController) {} + + async presentAlert() { + const alert = await this.alertController.create({ + cssClass: 'my-custom-class', + header: 'Erreur', + subHeader: 'authentification', + message: 'Une erreur s\'est produite durant l\'inscription', + buttons: ['OK'] + }); + + await alert.present(); + } + + ngOnInit() { + } + + async register(form){ + const results = await this.registerService.register(form); + results.subscribe(res => { + console.log(results); + this.router.navigate(['login']); + }); + } +} diff --git a/ionic/src/app/conversation/conversation.page.html b/ionic/src/app/conversation/conversation.page.html index 693fdbbdfd7a99c3e10838b2bdb30c7a248c8a5a..ed2213537b7fb3b7d558033bfcd08bdb5756371a 100644 --- a/ionic/src/app/conversation/conversation.page.html +++ b/ionic/src/app/conversation/conversation.page.html @@ -3,7 +3,7 @@ <ion-buttons slot="start"> <ion-back-button text="Retour"></ion-back-button> </ion-buttons> - <ion-title>Luke Skywalker</ion-title> + <ion-title>Messages</ion-title> <ion-avatar slot="end"> <img src="../../assets/icon/favicon.png"> </ion-avatar> @@ -12,20 +12,18 @@ <ion-content> <div class="bg"></div> - <ion-item lines="none"> - <ion-badge color="warning" slot="end">Hey Luke comment ça va ?! <ion-note color="medium">21:16 <ion-icon name="done-all"></ion-icon></ion-note></ion-badge> - </ion-item> - <ion-item lines="none"> - <ion-badge color="light" slot="start">Plutôt bien merci <ion-note color="medium">21:17</ion-note></ion-badge> + <ion-item *ngFor="let message of messages" lines="none"> + <ion-badge *ngIf="message.author != idUser" color="warning" slot="end">{{message.body}}<ion-note color="medium">{{message.date}} <ion-icon name="done-all"></ion-icon></ion-note></ion-badge> + <ion-badge *ngIf="message.author == idUser" color="light" slot="start">{{message.body}} <ion-note color="medium">{{message.date}} </ion-note></ion-badge> </ion-item> </ion-content> <ion-footer> <ion-toolbar> - <ion-input placeholder="Votre message"></ion-input> + <ion-input type='text' [(ngModel)]="text" placeholder="Votre message"></ion-input> <ion-buttons slot="end"> - <ion-button > + <ion-button (click) = "sendMessage()"> Envoyer </ion-button> </ion-buttons> diff --git a/ionic/src/app/conversation/conversation.page.ts b/ionic/src/app/conversation/conversation.page.ts index bc08210487b785c36ed595ddec5ff2b57e155e94..18551b83db7d49b4076736e8265c9ab689e8d404 100644 --- a/ionic/src/app/conversation/conversation.page.ts +++ b/ionic/src/app/conversation/conversation.page.ts @@ -1,4 +1,8 @@ import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { ConversationService } from '../services/conversation/conversation.service'; + + @Component({ selector: 'app-conversation', @@ -7,9 +11,30 @@ import { Component, OnInit } from '@angular/core'; }) export class ConversationPage implements OnInit { - constructor() { } + messages; + id; + text: string; + idUser; + + constructor(private activatedRoute: ActivatedRoute, private conversationService: ConversationService) { } ngOnInit() { + this.id = this.activatedRoute.snapshot.paramMap.get('id'); + this.getMessages(); + this.idUser = JSON.parse(localStorage.getItem('user')).id; } + getMessages(){ + this.conversationService.messages(this.id).subscribe(data => { + this.messages = data.reverse(); + console.log(this.messages); + }); + } + + sendMessage(){ + this.conversationService.sendMessage(this.text , this.id).subscribe(data => { + console.log(data); + }); + this.getMessages(); + } } diff --git a/ionic/src/app/global.service.ts b/ionic/src/app/global.service.ts index 6d0e9f0016961d6ef48a36c0a0b2e97afbdd39e9..1eea1cc8963cbe25691cccd28d32cb7209b009e8 100644 --- a/ionic/src/app/global.service.ts +++ b/ionic/src/app/global.service.ts @@ -8,8 +8,6 @@ export class GlobalService { public apiRoot: string; public httpOptions; - public headerHttpGetConnected; - public headerHttpPostConnected; constructor() { this.apiRoot = "http://localhost:3000"; @@ -18,18 +16,24 @@ export class GlobalService { 'Content-Type': 'application/json', }) }; - this.headerHttpGetConnected = { + } + + getHeaderHttpGetConnected(){ + return { headers: new HttpHeaders({ 'Authorization': "Bearer " + localStorage.getItem('token'), 'user': JSON.parse(localStorage.getItem('user')) }) - } - this.headerHttpPostConnected = { + }; + } + + getHeaderHttpPostConnected(){ + return { headers: new HttpHeaders({ 'Authorization': "Bearer " + localStorage.getItem('token'), 'user': JSON.parse(localStorage.getItem('user')), 'Content-Type': 'application/json' }) - } + }; } } diff --git a/ionic/src/app/services/auth/register/register.service.spec.ts b/ionic/src/app/services/auth/register/register.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..2ba39608d3cae72fcea3354a8a69c852dae2fccd --- /dev/null +++ b/ionic/src/app/services/auth/register/register.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { RegisterService } from './register.service'; + +describe('RegisterService', () => { + let service: RegisterService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(RegisterService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/ionic/src/app/services/auth/register/register.service.ts b/ionic/src/app/services/auth/register/register.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..87a94a1e79f74c05b7ac91ad222c5b9bdbf0ae72 --- /dev/null +++ b/ionic/src/app/services/auth/register/register.service.ts @@ -0,0 +1,38 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; +import { GlobalService } from '../../../global.service'; +import { catchError } from 'rxjs/operators'; +import { of } from 'rxjs'; + + + +@Injectable({ + providedIn: 'root' +}) +export class RegisterService { + + private urlRegister: string; + + constructor(private http: HttpClient, private global: GlobalService) { + this.urlRegister = this.global.apiRoot + '/users' + } + + register(form): Observable<any> { + const body = ` + { + "username":"${form.value.username}", + "password":"${form.value.password}", + "confirm":"${form.value.password}" + } + `; + return this.http.post(`${this.urlRegister}`, body , this.global.httpOptions).pipe( + map(results => { + console.log('RAW : ' + results); + return results; + }), + catchError(err => of(err)) + ); + } +} diff --git a/ionic/src/app/services/conversation/conversation.service.ts b/ionic/src/app/services/conversation/conversation.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..09d3109ddd3f41e04622e8fa290cbfea5c1ec09c --- /dev/null +++ b/ionic/src/app/services/conversation/conversation.service.ts @@ -0,0 +1,46 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; +import { GlobalService } from '../../global.service'; +import { catchError } from 'rxjs/operators'; +import { of } from 'rxjs'; + + + +@Injectable({ + providedIn: 'root' +}) +export class ConversationService { + + private urlRooms: string; + + constructor(private http: HttpClient, private global: GlobalService) { + this.urlRooms = this.global.apiRoot + '/rooms/'; + } + + messages(id): Observable<any> { + return this.http.get(`${this.urlRooms}` + id + '/messages', this.global.getHeaderHttpPostConnected()).pipe( + map(results => { + console.log('get : ' + results); + return results; + }), + catchError(err => of(err)) + ); + } + + sendMessage(text, idRoom){ + const body = { + body: text, + roomId: idRoom, + }; + + return this.http.post(this.global.apiRoot + '/messages', body , this.global.getHeaderHttpPostConnected()).pipe( + map(results => { + console.log('send : ' + results); + return results; + }), + catchError(err => of(err)) + ); + } +} diff --git a/ionic/src/app/services/conversation/conversation.spec.ts b/ionic/src/app/services/conversation/conversation.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..737c79d7e0df1572d315419224dc3a79f78d2b33 --- /dev/null +++ b/ionic/src/app/services/conversation/conversation.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { ConversationService } from './conversation.service'; + +describe('ConversationService', () => { + let service: ConversationService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ConversationService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/ionic/src/app/services/tab3.service.ts b/ionic/src/app/services/tab3.service.ts index c69899ac633caafce0a12c959f881393bb3673ab..536ca16481e75401166e7c9a45a5140d48773421 100644 --- a/ionic/src/app/services/tab3.service.ts +++ b/ionic/src/app/services/tab3.service.ts @@ -23,15 +23,8 @@ export class Tab3Service { this.urlCreateRoom= this.global.apiRoot + "/rooms" } - getGroups(): Observable<any> { - console.log(localStorage.getItem("token")) - return this.http.get(`${this.urlRooms}`,this.global.headerHttpGetConnected).pipe( - map(results => { - console.log('RAW : ' + results) - return results; - }), - catchError(err => of(err)) - ) + getGroups(){ + return this.http.get(`${this.urlRooms}`,this.global.getHeaderHttpGetConnected()); } createGroups(){ @@ -39,7 +32,7 @@ export class Tab3Service { "name": "ungroupe", "description": "unedescription" } - return this.http.post(this.urlCreateRoom,body,this.global.headerHttpPostConnected).pipe( + return this.http.post(this.urlCreateRoom,body,this.global.getHeaderHttpPostConnected()).pipe( map(results => { console.log('RAW : ' + results) return results; diff --git a/ionic/src/app/tab3/tab3.page.html b/ionic/src/app/tab3/tab3.page.html index 62c4ca341db61224b5ebea0889189981d9960fea..b0a0f5ef3dbbc9bf3b04dbc94bff035b8581e9cd 100644 --- a/ionic/src/app/tab3/tab3.page.html +++ b/ionic/src/app/tab3/tab3.page.html @@ -11,7 +11,7 @@ <ion-content> <ion-list> - <ion-item *ngFor="let item of (results | async)" routerLink="/conversation"> + <ion-item *ngFor="let item of results" routerLink="/conversation/{{ item._id }}"> <ion-avatar slot="start" > <img src="../../assets/icon/favicon.png"> </ion-avatar> diff --git a/ionic/src/app/tab3/tab3.page.ts b/ionic/src/app/tab3/tab3.page.ts index 711a9f2bc65bcb2f52351acc56403acd856291f4..18c9fc84996ac4e71bea3a815666bab2d88e6ba8 100644 --- a/ionic/src/app/tab3/tab3.page.ts +++ b/ionic/src/app/tab3/tab3.page.ts @@ -9,24 +9,23 @@ import { Tab3Service } from '../services/tab3.service'; }) export class Tab3Page { - results: Observable<any>; + results; constructor(private tab3Service: Tab3Service) { this.getGroups(); } getGroups(){ - this.results = this.tab3Service.getGroups(); - this.results.subscribe(res => { - console.log("les groupes : " + JSON.stringify(res)) - }) + this.tab3Service.getGroups().subscribe(data => { + this.results = data; + }); } async createGroup(){ - let groupe = await this.tab3Service.createGroups(); + const groupe = await this.tab3Service.createGroups(); groupe.subscribe(res => { - console.log("groupe crée : " + res); - }) + console.log('groupe crée : ' + res); + }); } } diff --git a/ionic/src/app/tabs/tabs.page.ts b/ionic/src/app/tabs/tabs.page.ts index 7d64f975daccfaaee6c7dcb239ae0a618beb793d..62ee25989e827609d9ae9924dcac6922e4dca2db 100644 --- a/ionic/src/app/tabs/tabs.page.ts +++ b/ionic/src/app/tabs/tabs.page.ts @@ -1,5 +1,6 @@ import { Component } from '@angular/core'; + @Component({ selector: 'app-tabs', templateUrl: 'tabs.page.html', @@ -8,5 +9,4 @@ import { Component } from '@angular/core'; export class TabsPage { constructor() {} - }