Skip to content

Commit

Permalink
all changes made
Browse files Browse the repository at this point in the history
  • Loading branch information
harshbaldwa committed Sep 2, 2019
1 parent bacb48e commit b2c5be5
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 18 deletions.
17 changes: 16 additions & 1 deletion backend/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require('express');
const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');
const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');

const check_auth = require('./check_auth');
Expand Down Expand Up @@ -55,6 +55,21 @@ function predicateBy(prop) {
};
}

// removing error
app.get('/api/table', (req, res, next) => {
res.status(200);
});

// Getting Ladder Sports
app.post('/api/table/sports', (req, res, next) => {
Player.findOne({_id: req.body.id}).then(data => {
if (data){
sport = data.preferred;
}
res.status(200).json(sport);
});
});

// Squash Data
app.get('/api/table/squash', (req, res, next) => {
const squashData = [];
Expand Down
7 changes: 3 additions & 4 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ export class AppComponent implements OnInit, OnDestroy {

ngOnInit() {
this.authService.autoAuthUser();
localStorage.setItem('sport', 'squash');
this.id = localStorage.getItem('_id');
this.notifN = timer(1000)
this.notifN = timer(1000, 5000)
.subscribe(data => {
this.ladderService.getNumberChallenge(this.id);
});
this.notifC = timer(1000)
this.notifC = timer(1000, 5000)
.subscribe(data => {
this.ladderService.getNumberConfirmations(this.id);
});
this.notifP = timer(1000)
this.notifP = timer(1000, 5000)
.subscribe(data => {
this.ladderService.getNumberPrevious(this.id);
});
Expand Down
19 changes: 19 additions & 0 deletions src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export class LadderService {
private ladderTable: LadderRanking[] = [];
private ladderUpdate = new Subject<LadderRanking[]>();

private sports: string[] = [];
private sportsUpdate = new Subject<string[]>();

private challengesN: number;
private challengesUpdatesN = new Subject<number>();

Expand Down Expand Up @@ -95,6 +98,22 @@ export class LadderService {
return this.challengesUpdatesC.asObservable();
}

// Getting Sports for user
getSports(id: string) {
const myId = { id };
this.http.post(BackendURLLadder + 'sports/', myId)
.subscribe((data: string) => {
if (data && !(data === '')) {
this.sports = data.split(',');
}
this.sportsUpdate.next([...this.sports]);
});
}

getSportsUpdateListener() {
return this.sportsUpdate.asObservable();
}

// Getting Ladder from server
getLadder(sport: string) {
this.http.get<LadderRanking[]>(BackendURLLadder + sport)
Expand Down
11 changes: 10 additions & 1 deletion src/app/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class AuthService {
private token: string;
private isAuthenticated = false;
private authStatusListener = new Subject<boolean>();

private wrongCredential = new Subject<boolean>();
constructor(private http: HttpClient, private router: Router) {}

getToken() {
Expand All @@ -23,6 +23,10 @@ export class AuthService {
return this.isAuthenticated;
}

getCorrectCredential() {
return this.wrongCredential.asObservable();
}

getAuthStatusListener() {
return this.authStatusListener.asObservable();
}
Expand All @@ -49,14 +53,19 @@ export class AuthService {
const token = response.token;
this.token = token;
if (token) {
response.sport = response.sport.split(',')[0];
localStorage.setItem('_id', response.id);
localStorage.setItem('name', response.name);
localStorage.setItem('sport', response.sport);
this.isAuthenticated = true;
this.authStatusListener.next(true);
this.wrongCredential.next(false);
this.saveAuthData(token);
this.router.navigate(['/']);
}
}, error => {
this.authStatusListener.next(false);
this.wrongCredential.next(true);
});
}

Expand Down
1 change: 1 addition & 0 deletions src/app/auth/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
</mat-form-field>
<button mat-raised-button color="accent" type="submit">Login</button>
</form>
<p *ngIf="wrongcred">Wrong Credentials! Please try again.</p>
</mat-card>
25 changes: 23 additions & 2 deletions src/app/auth/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
import { Component } from '@angular/core';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { NgForm } from '@angular/forms';

import { AuthService } from '../auth.service';
import { Subscription } from 'rxjs';

@Component({
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent {
export class LoginComponent implements OnInit, OnDestroy {
isLoading = false;
wrongcred = false;
private wrongC: Subscription;
private authSub: Subscription;

constructor(public authService: AuthService) {}

ngOnInit() {
this.authSub = this.authService.getAuthStatusListener()
.subscribe(data => {
this.isLoading = data;
});

this.wrongC = this.authService.getCorrectCredential()
.subscribe(data => {
this.wrongcred = data;
});
}

onLogin(form: NgForm) {
if (form.invalid) {
return;
}
this.isLoading = true;
this.authService.login(form.value.roll, form.value.password);
}

ngOnDestroy() {
this.authSub.unsubscribe();
this.wrongC.unsubscribe();
}
}
3 changes: 1 addition & 2 deletions src/app/auth/signup/signup.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ export class SignupComponent {
constructor(public authService: AuthService) {}

onSignup(form: NgForm) {
console.log(this.preferred);
let sports = '';
for (const sport of this.preferred) {
sports = sports + sport;
sports = sport + ',' + sports;
}
if (form.invalid) {
return;
Expand Down
8 changes: 4 additions & 4 deletions src/app/ladder-table/ladder-table.component.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<mat-form-field class = "sport">
<mat-label>Sport</mat-label>
<mat-select (valueChange)="getTable($event)" [formControl]="sportName">
<mat-option value="squash">Squash</mat-option>
<mat-option value="tt">Table Tennis</mat-option>
<mat-option value="tennis">Lawn Tennis</mat-option>
<mat-option value="badminton">Badminton</mat-option>
<mat-option *ngIf='issquash' value="squash">Squash</mat-option>
<mat-option *ngIf='istt' value="tt">Table Tennis</mat-option>
<mat-option *ngIf='istennis' value="tennis">Lawn Tennis</mat-option>
<mat-option *ngIf='isbadminton' value="badminton">Badminton</mat-option>
</mat-select>
</mat-form-field>

Expand Down
39 changes: 38 additions & 1 deletion src/app/ladder-table/ladder-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ export class LadderTableComponent implements OnInit, OnDestroy {

table: LadderRanking[] = [];
private tableSub: Subscription;
private sportsSub: Subscription;
userAuthenticated = false;

issquash;
istt;
istennis;
isbadminton;

dataSource;

displayedColumns: string[] = ['rank', 'username', 'points'];
Expand All @@ -41,8 +47,39 @@ export class LadderTableComponent implements OnInit, OnDestroy {
constructor(public ladderService: LadderService, private router: Router, private authService: AuthService) { }

ngOnInit() {
if (localStorage.getItem('_id') == null) {
this.issquash = true;
this.istt = true;
this.istennis = true;
this.isbadminton = true;
this.sportName.setValue('squash');
localStorage.setItem('sport', 'squash');
}
this.ladderService.getSports(localStorage.getItem('_id'));
this.sportName.setValue(localStorage.getItem('sport'));
this.refresher = timer(0, 15000)
this.sportsSub = this.ladderService.getSportsUpdateListener()
.subscribe((sport) => {
for (const entry of sport) {
switch (entry) {
case 'squash':
this.issquash = true;
break;
case 'tt':
this.istt = true;
break;
case 'tennis':
this.istennis = true;
break;
case 'badminton':
this.isbadminton = true;
break;
default:
break;
}
}
});
// this.sportName.setValue(localStorage.getItem('sport'));
this.refresher = timer(100, 15000)
.subscribe(data => {
this.ladderService.getLadder(this.sportName.value);
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/profile/edit/profile.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h1 style="margin-left: 20%;">Profile</h1>
</mat-form-field>
<mat-form-field>
<mat-label>Preferred Sport</mat-label>
<mat-select name="sport" [(ngModel)]="sport">
<mat-select name="sport" [(ngModel)]="sport" multiple>
<mat-option value="squash">Squash</mat-option>
<mat-option value="tt">Table Tennis</mat-option>
<mat-option value="tennis">Lawn Tennis</mat-option>
Expand Down
6 changes: 5 additions & 1 deletion src/app/profile/edit/profile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export class ProfileComponent implements OnInit {
}

changeProfile(form: NgForm) {
let sports = '';
for (const sport of this.sport) {
sports = sport + ',' + sports;
}
if (form.invalid) {
return;
}
Expand All @@ -44,7 +48,7 @@ export class ProfileComponent implements OnInit {
form.value.name,
form.value.hostel,
form.value.gender,
form.value.sport,
sports,
form.value.contact
);
this.openSnackBar();
Expand Down
Binary file removed src/assets/images/award.png
Binary file not shown.
2 changes: 1 addition & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

export const environment = {
production: false,
apiUrl: 'http://13.232.113.230/api/'
apiUrl: 'http://localhost:3000/api/'
};

/*
Expand Down

0 comments on commit b2c5be5

Please sign in to comment.