Bladeren bron

Persisted user to database from UI

Kris Blassingame 6 jaren geleden
bovenliggende
commit
467ae76049

+ 2
- 2
frontEnd/package.json Bestand weergeven

@@ -12,8 +12,8 @@
12 12
   },
13 13
   "dependencies": {
14 14
     "@angular/animations": "5.2.11",
15
-    "@angular/common": "5.2.11",
16
-    "@angular/compiler": "5.2.11",
15
+    "@angular/common": "^5.2.11",
16
+    "@angular/compiler": "^5.2.11",
17 17
     "@angular/compiler-cli": "5.2.11",
18 18
     "@angular/core": "5.2.11",
19 19
     "@angular/forms": "5.2.11",

+ 10
- 2
frontEnd/src/app/app.module.ts Bestand weergeven

@@ -9,6 +9,10 @@ import { GoogleMapComponent } from '../components/google-map/google-map';
9 9
 import { HomePage } from '../pages/home/home';
10 10
 import { RegisterPage } from '../pages/register/register';
11 11
 import { MainMenuPage } from '../pages/main-menu/main-menu';
12
+import { HttpClientModule } from '@angular/common/http';
13
+import { GoogleMapPage } from '../pages/googleMap/googleMap';
14
+import { RestProvider } from '../providers/rest/rest';
15
+
12 16
 
13 17
 @NgModule({
14 18
   declarations: [
@@ -16,11 +20,13 @@ import { MainMenuPage } from '../pages/main-menu/main-menu';
16 20
     HomePage,
17 21
     GoogleMapComponent,
18 22
     MainMenuPage,
19
-    RegisterPage
23
+    RegisterPage,
24
+    GoogleMapPage
20 25
     
21 26
   ],
22 27
   imports: [
23 28
     BrowserModule,
29
+    HttpClientModule,
24 30
     IonicModule.forRoot(MyApp)
25 31
   ],
26 32
   bootstrap: [IonicApp],
@@ -29,11 +35,13 @@ import { MainMenuPage } from '../pages/main-menu/main-menu';
29 35
     HomePage,
30 36
     GoogleMapComponent,
31 37
     MainMenuPage,
32
-    RegisterPage
38
+    RegisterPage,
39
+    GoogleMapPage
33 40
   ],
34 41
   providers: [
35 42
     StatusBar,
36 43
     SplashScreen,
44
+    RestProvider,
37 45
     {provide: ErrorHandler, useClass: IonicErrorHandler}
38 46
   ]
39 47
 })

+ 1
- 1
frontEnd/src/pages/home/home.html Bestand weergeven

@@ -13,7 +13,7 @@
13 13
       <b>Login</b>
14 14
     </button>
15 15
     <button class="regButt" ion-button block (click)="register()">
16
-      <b>Register</b>
16
+      <b>Register new account</b>
17 17
     </button>
18 18
 
19 19
     <p>Forgot Username/Password?

+ 3
- 3
frontEnd/src/pages/register/register.html Bestand weergeven

@@ -11,15 +11,15 @@
11 11
     <ion-list>
12 12
 
13 13
         <ion-item>
14
-          <ion-input type="text" placeholder="Username"></ion-input>
14
+          <ion-input type="text" placeholder="Username" [(ngModel)]  = "user.username"></ion-input>
15 15
         </ion-item>
16 16
 
17 17
         <ion-item>
18
-            <ion-input type="text" placeholder="Email"></ion-input>
18
+            <ion-input type="text" placeholder="Email" [(ngModel)]  = "user.email"></ion-input>
19 19
           </ion-item>
20 20
       
21 21
         <ion-item>
22
-          <ion-input type="password" placeholder="Password"></ion-input>
22
+          <ion-input type="password" placeholder="Password" [(ngModel)]  = "user.password"></ion-input>
23 23
         </ion-item>
24 24
       
25 25
       </ion-list>

+ 2
- 0
frontEnd/src/pages/register/register.module.ts Bestand weergeven

@@ -1,10 +1,12 @@
1 1
 import { NgModule } from '@angular/core';
2 2
 import { IonicPageModule } from 'ionic-angular';
3 3
 import { RegisterPage } from './register';
4
+import { RestProvider } from '../../providers/rest/rest';
4 5
 
5 6
 @NgModule({
6 7
   declarations: [
7 8
     RegisterPage,
9
+    RestProvider
8 10
   ],
9 11
   imports: [
10 12
     IonicPageModule.forChild(RegisterPage),

+ 8
- 3
frontEnd/src/pages/register/register.ts Bestand weergeven

@@ -1,7 +1,7 @@
1 1
 import { Component } from '@angular/core';
2 2
 import { IonicPage, NavController, NavParams } from 'ionic-angular';
3 3
 import { MainMenuPage } from '../main-menu/main-menu';
4
-
4
+import { RestProvider } from '../../providers/rest/rest';
5 5
 
6 6
 @IonicPage()
7 7
 @Component({
@@ -10,16 +10,21 @@ import { MainMenuPage } from '../main-menu/main-menu';
10 10
 })
11 11
 export class RegisterPage {
12 12
 
13
-  constructor(public navCtrl: NavController, public navParams: NavParams) {
13
+  user = { username: '', email: '', password: '' }
14
+
15
+  constructor(public navCtrl: NavController, public navParams: NavParams, public rest: RestProvider) {
14 16
   }
15 17
 
16 18
   ionViewDidLoad() {
17 19
     console.log('ionViewDidLoad RegisterPage');
18 20
   }
19 21
 
22
+
23
+
20 24
   register() {
25
+    console.log(this.user);
26
+    this.rest.addUser(this.user);
21 27
     this.navCtrl.setRoot(MainMenuPage);
22 28
 
23 29
   }
24
-
25 30
 }

+ 35
- 0
frontEnd/src/providers/rest/rest.ts Bestand weergeven

@@ -0,0 +1,35 @@
1
+import { HttpClient } from '@angular/common/http';
2
+import { Injectable } from '@angular/core';
3
+
4
+
5
+
6
+@Injectable()
7
+export class RestProvider {
8
+
9
+  apiUrl = 'http://localhost:8080';
10
+
11
+  constructor(public http: HttpClient) {
12
+    console.log('Hello RestProvider Provider');
13
+  }
14
+
15
+  getUsers() {
16
+    return new Promise(resolve => {
17
+      this.http.get(this.apiUrl + '/getUsers/').subscribe(data => {
18
+        resolve(data);
19
+      }, err => {
20
+        console.log(err);
21
+      });
22
+    });
23
+  }
24
+
25
+  addUser(data) {
26
+    return new Promise((resolve, reject) => {
27
+      this.http.post(this.apiUrl + '/register', data)
28
+        .subscribe(res => {
29
+          resolve(res);
30
+        }, (err) => {
31
+          reject(err);
32
+        });
33
+    });
34
+  }
35
+}