Browse Source

pseudo login and remembering a users info

nafis nibir 8 years ago
parent
commit
244353bc60

+ 3
- 1
client/src/app/app.component.ts View File

@@ -10,7 +10,9 @@ import { TabsPage } from '../pages/tabs/tabs';
10 10
 })
11 11
 export class MyApp {
12 12
   //rootPage:any = TabsPage;
13
-  rootPage:any = 'RegisterPage';
13
+  //rootPage:any = 'RegisterPage';
14
+  rootPage:any = 'LoginPage';
15
+
14 16
 
15 17
   constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
16 18
     platform.ready().then(() => {

+ 5
- 2
client/src/app/app.module.ts View File

@@ -14,6 +14,7 @@ import {GamesPageModule} from "../pages/games/games.module";
14 14
 import {UserPageModule} from "../pages/user/user.module";
15 15
 import {HttpClientModule} from "@angular/common/http";
16 16
 import {AuthServiceProvider} from "../providers/auth-service";
17
+import { RegisterPage } from '../pages/register/register';
17 18
 
18 19
 @NgModule({
19 20
   declarations: [
@@ -21,7 +22,8 @@ import {AuthServiceProvider} from "../providers/auth-service";
21 22
     AboutPage,
22 23
     ContactPage,
23 24
     HomePage,
24
-    TabsPage
25
+    TabsPage,
26
+    RegisterPage
25 27
   ],
26 28
   imports: [
27 29
     BrowserModule,
@@ -36,7 +38,8 @@ import {AuthServiceProvider} from "../providers/auth-service";
36 38
     AboutPage,
37 39
     ContactPage,
38 40
     HomePage,
39
-    TabsPage
41
+    TabsPage,
42
+    RegisterPage
40 43
   ],
41 44
   providers: [
42 45
     StatusBar,

+ 8
- 1
client/src/pages/games/games.html View File

@@ -16,6 +16,13 @@
16 16
         <ion-icon name="add-circle"></ion-icon>
17 17
       </button>
18 18
     </ion-buttons>
19
+
20
+    <ion-buttons end>
21
+        <button ion-button icon-only (click)="getImageURL()" color="danger">
22
+          <ion-icon name="image"></ion-icon>
23
+        </button>
24
+    </ion-buttons>
25
+
19 26
   </ion-navbar>
20 27
 </ion-header>
21 28
 
@@ -24,7 +31,7 @@
24 31
     <ion-item-sliding  *ngFor="let game of userGames" (click)="openSummary({id:game.id})">
25 32
     <ion-item>
26 33
         <ion-thumbnail item-start>
27
-            <img src="http://images.igdb.com/igdb/image/upload/t_thumb/svpkxcxez7fvg93kktl8.jpg">
34
+            <img src="{{game.imageURL}}">
28 35
         </ion-thumbnail>
29 36
       <h2>{{game.title}}</h2>
30 37
       <h3>{{ game.studio }}</h3>

+ 8
- 0
client/src/pages/games/games.ts View File

@@ -20,6 +20,7 @@ export class GamesPage {
20 20
   private games: Array<any>;
21 21
   private userGames: Array<any>
22 22
   private singleGame: any ={};
23
+  gameDetails: Array<any>;
23 24
 
24 25
   constructor(public navCtrl: NavController, public navParams: NavParams,
25 26
               public gameService: GameService, public modalCtrl: ModalController,
@@ -32,6 +33,13 @@ export class GamesPage {
32 33
     //}, 5000);
33 34
   }
34 35
 
36
+  getImageURL(){
37
+    this.gameService.getImageURL(this.gameService.currentGame.title).subscribe(games => {
38
+      this.gameDetails = games;
39
+      console.log(games.summary);
40
+    })
41
+  }
42
+
35 43
   getGamesByUserId(){
36 44
     this.gameService.getGameByUserId(this.authService.currentUserId).subscribe(games => {
37 45
       this.userGames = games;

+ 3
- 9
client/src/pages/home/home.html View File

@@ -5,15 +5,9 @@
5 5
 </ion-header>
6 6
 
7 7
 <ion-content padding>
8
-  <h2>User</h2>
9
-  <p>
10
-    This starter project comes with simple tabs-based layout for apps
11
-    that are going to primarily use a Tabbed UI.
12
-  </p>
13
-  <p>
14
-    Take a look at the <code>src/pages/</code> directory to add or change tabs,
15
-    update any existing page or create new pages.
16
-  </p>
8
+  <h2>backlogg feed</h2>
9
+  <p>List of Games?</p>
10
+  <p>List of friends?</p>
17 11
 </ion-content>
18 12
 
19 13
 

+ 35
- 14
client/src/pages/login/login.html View File

@@ -1,18 +1,39 @@
1
-<!--
2
-  Generated template for the LoginPage page.
3
-
4
-  See http://ionicframework.com/docs/components/#navigation for more info on
5
-  Ionic pages and navigation.
6
--->
7 1
 <ion-header>
2
+    <ion-navbar>
3
+      <ion-title color="white">Login</ion-title>
4
+    </ion-navbar>
5
+  </ion-header>
6
+  
7
+  
8
+  <ion-content class="login-content" padding>
9
+    <div class="login-box">
10
+  
11
+      <form (ngSubmit)="login()" #loginForm="ngForm">
12
+        <ion-row>
13
+          <ion-col>
14
+            <ion-list inset>
15
+  
16
+              <ion-item>
17
+                <ion-input type="text" placeholder="Email" name="email" [(ngModel)]="loginCredentials.email" required></ion-input>
18
+              </ion-item>
19
+  
20
+              <ion-item>
21
+                <ion-input type="password" placeholder="Password" name="password" [(ngModel)]="loginCredentials.password" required></ion-input>
22
+              </ion-item>
23
+  
24
+            </ion-list>
25
+          </ion-col>
26
+        </ion-row>
27
+  
28
+        <ion-row>
29
+          <ion-col class="signup-col">
30
+            <button ion-button class="submit-btn" full type="submit" [disabled]="!loginForm.form.valid">Login</button>
31
+          </ion-col>
32
+        </ion-row>
8 33
 
9
-  <ion-navbar>
10
-    <ion-title>login</ion-title>
11
-  </ion-navbar>
12
-
13
-</ion-header>
14
-
34
+      </form>
35
+      <button ion-button class="register-btn" block clear (click)="createAccount()">Register New Account</button>
15 36
 
16
-<ion-content padding>
37
+    </div>
38
+  </ion-content>
17 39
 
18
-</ion-content>

+ 46
- 2
client/src/pages/login/login.scss View File

@@ -1,3 +1,47 @@
1 1
 page-login {
2
-
3
-}
2
+  
3
+    .toolbar-background {
4
+      background-color: rgb(35, 223, 29);
5
+    }
6
+  
7
+    .login-content {
8
+      background: #fcf1e0;
9
+  
10
+      .login-box {
11
+        background: #d7dfe0;
12
+        padding: 20px 20px 0px 20px;
13
+        margin-top: 30px;
14
+      }
15
+  
16
+      ion-row {
17
+        align-items: center;
18
+        text-align: center;
19
+      }
20
+  
21
+      ion-item {
22
+        border-radius: 30px !important;
23
+        padding-left: 30px !important;
24
+        font-size: 0.9em;
25
+        margin-bottom: 10px;
26
+        border: 1px solid #ffffff;
27
+        border-bottom: 0px !important;
28
+        box-shadow: none !important;
29
+      }
30
+  
31
+      .signup-col {
32
+        margin: 0px 16px 0px 16px;
33
+        padding-bottom: 20px;
34
+      }
35
+  
36
+      .item-inner {
37
+        border-bottom-color: #ffffff !important;
38
+        box-shadow: none !important;
39
+      }
40
+  
41
+      .submit-btn {
42
+        background: #51CFB1;
43
+        border-radius: 30px !important;
44
+        border: 1px solid #ffffff;
45
+      }
46
+    }
47
+  }

+ 56
- 4
client/src/pages/login/login.ts View File

@@ -1,5 +1,10 @@
1 1
 import { Component } from '@angular/core';
2
-import { IonicPage, NavController, NavParams } from 'ionic-angular';
2
+import { IonicPage, NavController, NavParams, AlertController } from 'ionic-angular';
3
+import { AuthServiceProvider } from '../../providers/auth-service';
4
+import { GameService } from '../../providers/game-service';
5
+import { TabsPage} from "../tabs/tabs";
6
+import { RegisterPage } from '../register/register';
7
+
3 8
 
4 9
 /**
5 10
  * Generated class for the LoginPage page.
@@ -15,11 +20,58 @@ import { IonicPage, NavController, NavParams } from 'ionic-angular';
15 20
 })
16 21
 export class LoginPage {
17 22
 
18
-  constructor(public navCtrl: NavController, public navParams: NavParams) {
23
+  loginCredentials = { email: '', password:''};
24
+
25
+  constructor(public navCtrl: NavController, public navParams: NavParams,
26
+              public authService: AuthServiceProvider,
27
+              public alertCtrl: AlertController,
28
+              public gameService: GameService) {
29
+  }
30
+
31
+  public login(){
32
+    this.authService.login(this.loginCredentials.email).subscribe(
33
+      response => {
34
+        console.log(response);
35
+        if (response == null){
36
+           this.existingUser();
37
+           return; 
38
+        }
39
+        this.authService.currentUser = response;
40
+        this.authService.currentUserId = response.id;
41
+        this.gameService.currentUserId = response.id;
42
+        this.showPopup("Welcome back!", `Enjoy your stay ${response.name}!`,
43
+         [{
44
+            text: 'ok',
45
+            handler: () => this.navCtrl.push(TabsPage)
46
+         }]
47
+       )
48
+      },
49
+      error => {
50
+        this.showPopup("You have an error!", `Error code: ${error.status}`, [{ text: "ok"}])
51
+      }
52
+
53
+    )
54
+  }
55
+
56
+  existingUser(){
57
+    this.showPopup("Try Registering!", `This user does not exist!`,
58
+         [{
59
+            text: 'ok',
60
+            handler: () => this.navCtrl.push(RegisterPage)
61
+         }]
62
+       )
63
+  }
64
+
65
+  showPopup(title, text, buttons) {
66
+    return this.alertCtrl.create({
67
+      title: title,
68
+      subTitle: text,
69
+      buttons
70
+    }).present();
19 71
   }
20 72
 
21
-  ionViewDidLoad() {
22
-    console.log('ionViewDidLoad LoginPage');
73
+  createAccount(){
74
+    this.navCtrl.push(RegisterPage);
23 75
   }
24 76
 
25 77
 }

+ 1
- 1
client/src/pages/register/register.html View File

@@ -37,4 +37,4 @@
37 37
 
38 38
     </form>
39 39
   </div>
40
-</ion-content>
40
+</ion-content>

+ 2
- 2
client/src/pages/tabs/tabs.ts View File

@@ -14,8 +14,8 @@ export class TabsPage {
14 14
   tab1Root = HomePage;
15 15
   tab2Root = UserPage;
16 16
   tab3Root = GamesPage
17
-  tab4Root = AboutPage;
18
-  tab5Root = ContactPage;
17
+  // tab4Root = AboutPage;
18
+  // tab5Root = ContactPage;
19 19
 
20 20
   constructor() {
21 21
 

+ 5
- 10
client/src/providers/auth-service.ts View File

@@ -48,16 +48,11 @@ export class AuthServiceProvider {
48 48
       return this.http.post(this.REGISTER_URL, credentials);
49 49
       
50 50
   }
51
-
52
-  // setUser(data){
53
-  //   data.subscribe(response => {
54
-  //      this.currentUser = response;
55
-  //      this.currentUserId = response.id;
56
-  //   })
57
-
58
-  //   return data;
59
-  // }
60
-
51
+  
52
+  login(email): Observable<any>{
53
+    console.log("BEFORE REQUEST: " + email);
54
+    return this.http.get(this.LOGIN_URL + "/email/" + email);
55
+  }
61 56
   getUsers(): Observable<any> {
62 57
     return this.http.get(this.LOGIN_URL);
63 58
   }

+ 14
- 2
client/src/providers/game-service.ts View File

@@ -1,5 +1,5 @@
1 1
 import {Injectable} from "@angular/core";
2
-import {HttpClient} from "@angular/common/http";
2
+import {HttpClient, HttpHeaders} from "@angular/common/http";
3 3
 import {Observable} from "rxjs/Observable";
4 4
 
5 5
 export class Game{
@@ -7,12 +7,14 @@ export class Game{
7 7
   title: string;
8 8
   studio: string;
9 9
   platform: string;
10
+  imageURL: string;
10 11
   
11
-  constructor(id:number, title: string, studio: string, platform: string){
12
+  constructor(id:number, title: string, studio: string, platform: string, imageURL: string){
12 13
     this.id = id;
13 14
     this.title = title;
14 15
     this.studio = studio;
15 16
     this.platform = platform;
17
+    this.imageURL = imageURL;
16 18
   }
17 19
 }
18 20
 
@@ -24,6 +26,7 @@ export class GameService{
24 26
   public currentGame: Game;
25 27
   public currentGameId: number;
26 28
   public currentUserId: number;
29
+  public 
27 30
 
28 31
   constructor(public http: HttpClient){
29 32
   }
@@ -53,6 +56,15 @@ export class GameService{
53 56
     return this.http.get(this.GAME_API + "/name/" + credentials);
54 57
   }
55 58
 
59
+  getImageURL(gameTitle: string): Observable<any>{
60
+    var url = "https://cors-anywhere.herokuapp.com/api-endpoint.igdb.com/games/?search=" + gameTitle + "&fields=name,cover,summary";
61
+    let header = new HttpHeaders();
62
+    header = header.set("user-key","4aafe5d7db305154aa7b60f13bad89bd");
63
+    header = header.set('content-type','application/json');
64
+      
65
+    return this.http.get(url,{headers:header});
66
+  }
67
+
56 68
   
57 69
 
58 70
 }

+ 5
- 0
server/src/main/java/com/example/demo/Controller/UserController.java View File

@@ -36,6 +36,11 @@ public class UserController {
36 36
         return this.userService.findAllUsers();
37 37
     }
38 38
 
39
+    @GetMapping( value = "/users/email/{emailField}")
40
+    public User findByEmail(@PathVariable String emailField){
41
+        return this.userService.findByEmail(emailField);
42
+    }
43
+
39 44
     @PutMapping( value = "/users/{userId}/username")
40 45
     public User updateUserName(@RequestBody String newName, @PathVariable Long userId){
41 46
         return this.userService.updateUserName(newName, userId);

+ 1
- 1
server/src/main/java/com/example/demo/Entity/User.java View File

@@ -6,7 +6,7 @@ import java.util.HashSet;
6 6
 import java.util.Set;
7 7
 
8 8
 @Entity
9
-@Table( name = "users")
9
+@Table( name = "users", uniqueConstraints={@UniqueConstraint(columnNames={"email"})})
10 10
 public class User {
11 11
 
12 12
     @Id

+ 2
- 1
server/src/main/java/com/example/demo/Repository/UserRepository.java View File

@@ -13,7 +13,8 @@ import java.util.Set;
13 13
 
14 14
 @RepositoryRestResource
15 15
 public interface UserRepository extends JpaRepository<User, Long> {
16
-    User findByName(String name);
16
+
17
+    User findByEmail(String email);
17 18
 
18 19
 //    @Query("select g.title, g.studio, g.platform" +
19 20
 //    " from Game g" +

+ 5
- 0
server/src/main/java/com/example/demo/Service/UserService.java View File

@@ -33,6 +33,11 @@ public class UserService {
33 33
         return this.userRepository.findAll();
34 34
     }
35 35
 
36
+    public User findByEmail(String email){
37
+
38
+        return this.userRepository.findByEmail(email);
39
+    }
40
+
36 41
 
37 42
 
38 43
     public User findUserById(Long userId) {

+ 14
- 14
server/src/test/java/com/example/demo/RepositoryTest/UserRepositoryTest.java View File

@@ -23,20 +23,20 @@ public class UserRepositoryTest {
23 23
     @Autowired
24 24
     private UserRepository userRepository;
25 25
 
26
-    @Test
27
-    public void findByNameTest(){
28
-
29
-        //given
30
-        User nafis = new User("nafis", "nafis@fake.com", "1234");
31
-        entityManager.persist(nafis);
32
-        entityManager.flush();
33
-
34
-        //when
35
-        User found = userRepository.findByName(nafis.getName());
36
-
37
-        //then
38
-        assertThat(found.getName()).isEqualTo(nafis.getName());
39
-    }
26
+//    @Test
27
+//    public void findByNameTest(){
28
+//
29
+//        //given
30
+//        User nafis = new User("nafis", "nafis@fake.com", "1234");
31
+//        entityManager.persist(nafis);
32
+//        entityManager.flush();
33
+//
34
+//        //when
35
+//        User found = userRepository.findByName(nafis.getName());
36
+//
37
+//        //then
38
+//        assertThat(found.getName()).isEqualTo(nafis.getName());
39
+//    }
40 40
 
41 41
     @Test
42 42
     public void findByIdTest(){