diff --git a/.gitignore b/.gitignore index cc8aaaa..495e67b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ env.php scratch.* scratch/ +vendor/ # Logs logs *.log diff --git a/client/CapstonePalette.PNG b/client/CapstonePalette.PNG deleted file mode 100644 index 28de99a..0000000 Binary files a/client/CapstonePalette.PNG and /dev/null differ diff --git a/client/src/app/app-routing.module.ts b/client/src/app/app-routing.module.ts index 7381c3c..a011bd1 100644 --- a/client/src/app/app-routing.module.ts +++ b/client/src/app/app-routing.module.ts @@ -23,14 +23,6 @@ const routes: Routes = [ path: 'strategies', loadChildren: () => import('./strategies/strategies.module').then(m => m.StrategiesPageModule) }, - { - path: 'test', - loadChildren: () => import('./test/test.module').then(m => m.TestPageModule) - }, - { - path: 'navigation', - loadChildren: () => import('./navigation/navigation.module').then(m => m.NavigationPageModule) - }, { path: 'login', loadChildren: () => import('./login/login.module').then(m => m.LoginPageModule) @@ -57,12 +49,13 @@ const routes: Routes = [ }, { path: 'policy', - loadChildren: () => import('./policy/policy.module').then( m => m.PolicyPageModule) - }, { - path: 'footer', - loadChildren: () => import('./footer/footer.module').then( m => m.FooterPageModule) - }, - + loadChildren: () => import('./policy/policy.module').then(m => m.PolicyPageModule) + }, + { + path: 'footer', + loadChildren: () => import('./footer/footer.module').then(m => m.FooterPageModule) + }, + diff --git a/client/src/app/education/education.page.html b/client/src/app/education/education.page.html index 8ee790d..3f43200 100644 --- a/client/src/app/education/education.page.html +++ b/client/src/app/education/education.page.html @@ -5,10 +5,6 @@ - -

Cognitive Load

-
- @@ -21,11 +17,12 @@

Cognitive Load

- - Cognitive Load is the mental effort required to - complete a - task. - + + Cognitive Load is the mental effort + required to + complete a + task. + There are three types of Cognitive Load: @@ -46,7 +43,7 @@

Cognitive Load

- + @@ -104,19 +101,19 @@

Cognitive Load

Intrinsic + class="hover-trigger">Intrinsic Extraneous + class="hover-trigger">Extraneous Germane + class="hover-trigger">Germane diff --git a/client/src/app/login/login.page.html b/client/src/app/login/login.page.html index 63da89f..9db9274 100644 --- a/client/src/app/login/login.page.html +++ b/client/src/app/login/login.page.html @@ -7,7 +7,7 @@
-
+
diff --git a/client/src/app/nav/nav.component.html b/client/src/app/nav/nav.component.html index 353a833..bb07b87 100644 --- a/client/src/app/nav/nav.component.html +++ b/client/src/app/nav/nav.component.html @@ -27,6 +27,6 @@
Quiz - NASA TLX
New Task
Results
-
Test
+ \ No newline at end of file diff --git a/client/src/app/nav/nav.component.ts b/client/src/app/nav/nav.component.ts index 38f514b..72124b8 100644 --- a/client/src/app/nav/nav.component.ts +++ b/client/src/app/nav/nav.component.ts @@ -1,8 +1,8 @@ -import {Component, OnInit} from '@angular/core'; -import {IonicModule} from '@ionic/angular'; -import {Router} from '@angular/router'; - - +import { Component, OnInit } from '@angular/core'; +import { IonicModule } from '@ionic/angular'; +import { Router } from '@angular/router'; +import { UserDataService } from '../services/user-data.service'; +import { ToastController } from '@ionic/angular'; @Component({ selector: 'app-nav', templateUrl: './nav.component.html', @@ -13,7 +13,7 @@ import {Router} from '@angular/router'; }) export class NavComponent implements OnInit { - constructor(private router: Router) { + constructor(private router: Router, private userDataService: UserDataService, private toastController: ToastController) { } goHome() { @@ -69,12 +69,44 @@ export class NavComponent implements OnInit { } logout() { + this.userDataService.logout().subscribe({ + next: async (response: any) => { + const alert = await this.toastController.create({ + message: 'Successfully logged out of your account!', + duration: 2000, + position: 'bottom', + color: 'success' + }); + await alert.present(); + + sessionStorage.removeItem("sessionID") + sessionStorage.removeItem("access") + sessionStorage.removeItem("userID") + + sessionStorage.clear(); + this.router.navigateByUrl('/login'); + }, + error: async (error) => { + const alert = await this.toastController.create({ + message: 'Error Logging Out. Please try again. If this error persists, please email support at kartikinpublic@gmail.com', + duration: 2000, + position: 'bottom', + color: 'danger' + }); + await alert.present(); + + } + + }) + sessionStorage.removeItem("sessionID") sessionStorage.removeItem("access") sessionStorage.removeItem("userID") sessionStorage.clear(); + + this.navigateTo('/login') } } diff --git a/client/src/app/navigation/navigation-routing.module.ts b/client/src/app/navigation/navigation-routing.module.ts deleted file mode 100644 index c335b6f..0000000 --- a/client/src/app/navigation/navigation-routing.module.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { NgModule } from '@angular/core'; -import { Routes, RouterModule } from '@angular/router'; - -import { NavigationPage } from './navigation.page'; - -const routes: Routes = [ - { - path: '', - component: NavigationPage - } -]; - -@NgModule({ - imports: [RouterModule.forChild(routes)], - exports: [RouterModule], -}) -export class NavigationPageRoutingModule {} diff --git a/client/src/app/navigation/navigation.module.ts b/client/src/app/navigation/navigation.module.ts deleted file mode 100644 index d611b40..0000000 --- a/client/src/app/navigation/navigation.module.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { FormsModule } from '@angular/forms'; - -import { IonicModule } from '@ionic/angular'; - -import { NavigationPageRoutingModule } from './navigation-routing.module'; - -import { NavigationPage } from './navigation.page'; - -@NgModule({ - imports: [ - CommonModule, - FormsModule, - IonicModule, - NavigationPageRoutingModule - ], - declarations: [NavigationPage] -}) -export class NavigationPageModule {} diff --git a/client/src/app/navigation/navigation.page.html b/client/src/app/navigation/navigation.page.html deleted file mode 100644 index a647343..0000000 --- a/client/src/app/navigation/navigation.page.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - Home - -
Home
-
- - - Education - -
Cog Load Page
-
Strategies
-
Measure
-
- - - Quiz - -
Quiz - Builder
-
New Task
-
Quiz - Task Load
-
Quiz - Results
-
-
\ No newline at end of file diff --git a/client/src/app/navigation/navigation.page.scss b/client/src/app/navigation/navigation.page.scss deleted file mode 100644 index 81faa3d..0000000 --- a/client/src/app/navigation/navigation.page.scss +++ /dev/null @@ -1,6 +0,0 @@ -ion-accordion { - font-family: Arial, sans-serif; - font: 16px bold; - color: #f4f4f4; - background-color: #011411; -} \ No newline at end of file diff --git a/client/src/app/navigation/navigation.page.spec.ts b/client/src/app/navigation/navigation.page.spec.ts deleted file mode 100644 index 306f4c8..0000000 --- a/client/src/app/navigation/navigation.page.spec.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { NavigationPage } from './navigation.page'; - -describe('NavigationPage', () => { - let component: NavigationPage; - let fixture: ComponentFixture; - - beforeEach((() => { - fixture = TestBed.createComponent(NavigationPage); - component = fixture.componentInstance; - fixture.detectChanges(); - })); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/client/src/app/navigation/navigation.page.ts b/client/src/app/navigation/navigation.page.ts deleted file mode 100644 index 6edd400..0000000 --- a/client/src/app/navigation/navigation.page.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Component, OnInit } from '@angular/core'; - -@Component({ - selector: 'app-navigation', - templateUrl: './navigation.page.html', - styleUrls: ['./navigation.page.scss'], -}) -export class NavigationPage implements OnInit { - - constructor() { } - - ngOnInit() { - } - -} diff --git a/client/src/app/quiz/quiz.page.ts b/client/src/app/quiz/quiz.page.ts index f77c771..35d16a0 100644 --- a/client/src/app/quiz/quiz.page.ts +++ b/client/src/app/quiz/quiz.page.ts @@ -1,8 +1,8 @@ -import {Component, OnInit} from '@angular/core'; -import {AnswerDataService} from '../services/answer-data.service'; -import {TaskDataService} from '../services/task-data.service'; -import {ToastController} from '@ionic/angular'; -import {Router} from '@angular/router'; +import { Component, OnInit } from '@angular/core'; +import { AnswerDataService } from '../services/answer-data.service'; +import { TaskDataService } from '../services/task-data.service'; +import { ToastController } from '@ionic/angular'; +import { Router } from '@angular/router'; @Component({ selector: 'app-quiz', @@ -122,8 +122,21 @@ export class QuizPage implements OnInit { ngOnInit() { } - ionViewDidEnter() { - this.getTasks() + async ionViewDidEnter() { + if (sessionStorage.getItem('sessionID') && sessionStorage.getItem('access') === 'true' && sessionStorage.getItem('userID')) { + this.getTasks() + } else { + const alert = this.toastController.create({ + message: 'Not Logged In - Unable to take a quiz.', + duration: 2000, + position: 'bottom', + color: 'danger' + }); + await (await alert).present(); + + await this.router.navigateByUrl('/login') + + } } } diff --git a/client/src/app/results/results.page.ts b/client/src/app/results/results.page.ts index 93c84f8..4817d1f 100644 --- a/client/src/app/results/results.page.ts +++ b/client/src/app/results/results.page.ts @@ -1,10 +1,10 @@ -import {Component, OnInit} from '@angular/core'; -import {Router} from '@angular/router'; -import {TaskDataService} from '../services/task-data.service'; +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { TaskDataService } from '../services/task-data.service'; TaskDataService -import {AnswerDataService} from '../services/answer-data.service'; -import {ToastController} from '@ionic/angular'; +import { AnswerDataService } from '../services/answer-data.service'; +import { ToastController } from '@ionic/angular'; @Component({ selector: 'app-results', @@ -138,7 +138,7 @@ export class ResultsPage implements OnInit { taskData.totalScore += taskScore; } } else { - taskScoresMap.set(taskID, {count: 1, totalScore: taskScore}); + taskScoresMap.set(taskID, { count: 1, totalScore: taskScore }); } } @@ -185,13 +185,13 @@ export class ResultsPage implements OnInit { } async ionViewDidEnter() { - if (sessionStorage.getItem('sessionID')) { + if (sessionStorage.getItem('sessionID') && sessionStorage.getItem('access') === 'true' && sessionStorage.getItem('userID')) { this.getTaskData(); this.getAnswerData(); } else { const alert = this.toastController.create({ - message: 'Not Logged In - Unable to view tasks.', + message: 'Not Logged In - Unable to view results.', duration: 2000, position: 'bottom', color: 'danger' diff --git a/client/src/app/services/user-data.service.ts b/client/src/app/services/user-data.service.ts index b470452..cc0381c 100644 --- a/client/src/app/services/user-data.service.ts +++ b/client/src/app/services/user-data.service.ts @@ -105,6 +105,32 @@ export class UserDataService { } + logout() { + const logoutURL = `${this.url}auth/logout.php`; + + const sessionID = sessionStorage.getItem("sessionID") + const userID = sessionStorage.getItem("userID") + + const formData: any = {} + + formData.sessionID = sessionID; + formData.userID = userID; + + const httpOptions = { + headers: new HttpHeaders({ + 'Content-Type': 'application/x-www-form-urlencoded' + }), + params: new HttpParams(), + }; + + // Convert the formData object to URL-encoded format + let body = new HttpParams(); + for (const key of Object.keys(formData)) { + body = body.set(key, formData[key]); + } + + return this.http.post(logoutURL, body.toString(), httpOptions); + } diff --git a/client/src/app/signup/signup.page.html b/client/src/app/signup/signup.page.html index cf87888..b997bf0 100644 --- a/client/src/app/signup/signup.page.html +++ b/client/src/app/signup/signup.page.html @@ -1,13 +1,12 @@ - - - + Sign Up - -
+ + +
@@ -33,11 +32,19 @@ Terms and Conditions - - I have read and agree - to the Terms and - Conditions linked above. - +
+ + +

I have read and agree + to the Terms and + Conditions linked above. +

+
+
+ +
+ diff --git a/client/src/app/signup/signup.page.ts b/client/src/app/signup/signup.page.ts index 9f48399..0995c2d 100644 --- a/client/src/app/signup/signup.page.ts +++ b/client/src/app/signup/signup.page.ts @@ -42,12 +42,13 @@ export class SignupPage implements OnInit { // set session variables in client sessionStorage.setItem("sessionID", response.sessionID); sessionStorage.setItem("access", response.Authorization); + sessionStorage.setItem("userID", response.userID); this.router.navigateByUrl('/task'); }, error: async (error) => { console.error('Error:', error) const alert = await this.toastController.create({ - message: error, + message: 'An error has occurred. Please try to Log In', duration: 2000, position: 'bottom', color: 'danger' diff --git a/client/src/app/strategies/strategies.page.html b/client/src/app/strategies/strategies.page.html index ac64e5a..6b2048f 100644 --- a/client/src/app/strategies/strategies.page.html +++ b/client/src/app/strategies/strategies.page.html @@ -50,7 +50,7 @@ Tips for Intrinsic Load - + @@ -79,7 +79,7 @@ - + @@ -109,7 +109,7 @@ - + @@ -143,7 +143,7 @@ Tips for Extraneous Load - + @@ -166,7 +166,7 @@ - + @@ -219,7 +219,7 @@
- < + Tips for Germane Load @@ -345,8 +345,8 @@ - - + +
diff --git a/client/src/app/task/task.page.html b/client/src/app/task/task.page.html index 079af26..b987ddf 100644 --- a/client/src/app/task/task.page.html +++ b/client/src/app/task/task.page.html @@ -8,13 +8,12 @@ - - + Type a Task Name - + @@ -23,11 +22,11 @@ Choose or Type a Task Type - - Intrinsic - Extraneous - Germane - +
+ Intrinsic + Extraneous + Germane +
Type a Task Type @@ -51,7 +50,9 @@ - Save Task +
+ Save Task +
diff --git a/client/src/app/task/task.page.ts b/client/src/app/task/task.page.ts index 6623175..f9998ef 100644 --- a/client/src/app/task/task.page.ts +++ b/client/src/app/task/task.page.ts @@ -75,4 +75,22 @@ export class TaskPage implements OnInit { } }); } + + async ionViewDidEnter() { + if (sessionStorage.getItem('sessionID') && sessionStorage.getItem('access') === 'true' && sessionStorage.getItem('userID')) { + + } else { + const alert = this.toastController.create({ + message: 'Not Logged In - Unable to view tasks.', + duration: 2000, + position: 'bottom', + color: 'danger' + }); + await (await alert).present(); + + await this.router.navigateByUrl('/login') + + } + } + } diff --git a/client/src/app/test/test-routing.module.ts b/client/src/app/test/test-routing.module.ts deleted file mode 100644 index 7f8abfd..0000000 --- a/client/src/app/test/test-routing.module.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { NgModule } from '@angular/core'; -import { Routes, RouterModule } from '@angular/router'; - -import { TestPage } from './test.page'; - -const routes: Routes = [ - { - path: '', - component: TestPage - } -]; - -@NgModule({ - imports: [RouterModule.forChild(routes)], - exports: [RouterModule], -}) -export class TestPageRoutingModule {} diff --git a/client/src/app/test/test.module.ts b/client/src/app/test/test.module.ts deleted file mode 100644 index de6465d..0000000 --- a/client/src/app/test/test.module.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { FormsModule } from '@angular/forms'; - -import { IonicModule } from '@ionic/angular'; - -import { TestPageRoutingModule } from './test-routing.module'; - -import { TestPage } from './test.page'; - -import { HttpClientModule } from '@angular/common/http'; - -import { NavComponent } from '../nav/nav.component'; - - -@NgModule({ - imports: [ - CommonModule, - FormsModule, - IonicModule, - TestPageRoutingModule, - HttpClientModule, - NavComponent - ], - declarations: [TestPage] -}) -export class TestPageModule { } diff --git a/client/src/app/test/test.page.html b/client/src/app/test/test.page.html deleted file mode 100644 index cec2d67..0000000 --- a/client/src/app/test/test.page.html +++ /dev/null @@ -1,68 +0,0 @@ - - - API Route Test Page - - - - - - - Task API Routes - Get Task - Data - POST Task - Data - Update Task - Data - Delete Task - Data - {{taskData}} - - - Answer API Routes - Get Answer - Data - POST Answer - Data - - Update Answer Data - - Delete Answer Data - - {{answerData}} - - - - User API Routes - - Get User Data - - - POST User Data - - - UPDATE User Data - - - DELETE User Data - - {{userData}} - - - Session/Login Data - - Start Session Data - - - Store Session Data - - - Get Session Data - - - - - - - - \ No newline at end of file diff --git a/client/src/app/test/test.page.scss b/client/src/app/test/test.page.scss deleted file mode 100644 index 1194df4..0000000 --- a/client/src/app/test/test.page.scss +++ /dev/null @@ -1,8 +0,0 @@ -/* Navigation Styles */ - -ion-accordion { - font-family: Arial, sans-serif; - font: 16px bold; - color: #f4f4f4; - -} \ No newline at end of file diff --git a/client/src/app/test/test.page.spec.ts b/client/src/app/test/test.page.spec.ts deleted file mode 100644 index 7f1371a..0000000 --- a/client/src/app/test/test.page.spec.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { TestPage } from './test.page'; - -describe('TestPage', () => { - let component: TestPage; - let fixture: ComponentFixture; - - beforeEach(() => { - fixture = TestBed.createComponent(TestPage); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/client/src/app/test/test.page.ts b/client/src/app/test/test.page.ts deleted file mode 100644 index 7717721..0000000 --- a/client/src/app/test/test.page.ts +++ /dev/null @@ -1,228 +0,0 @@ -import { Component, OnInit } from '@angular/core'; -import { TaskDataService } from '../services/task-data.service'; -import { AnswerDataService } from '../services/answer-data.service'; -import { UserDataService } from '../services/user-data.service'; - -@Component({ - selector: 'app-test', - templateUrl: './test.page.html', - styleUrls: ['./test.page.scss'], -}) -export class TestPage implements OnInit { - taskData: any; - formData: any; - answerData: any; - userData: any; - - constructor(private taskDataService: TaskDataService, private answerDataService: AnswerDataService, private userDataService: UserDataService) { } - - getTaskData() { - - this.taskDataService.getData().subscribe(response => { - console.log(response); - this.taskData = JSON.stringify(response); - }); - } - - postTaskData(formData: any) { - if (!formData) { - formData = { - "taskName": "Doodling", - "taskType": "Type A", - "taskTime": "10:00", - "userID": 1 - } - } - - this.taskDataService.postData(formData).subscribe({ - next: response => console.log('Response from server:', response), - error: error => console.error('Error:', error) - }); - - } - - updateTaskData(formData: any) { - if (!formData) { - formData = { - "taskID": 34, - "taskName": "Swimming", - "taskType": "Type B", - "taskTime": "10:00", - "userID": 1 - } - } - - this.taskDataService.updateData(formData).subscribe({ - next: response => console.log('Response from server:', response), - error: error => console.error('Error:', error) - }); - } - - deleteTaskData(formData: any) { - if (!formData) { - formData = { - "taskID": 32 - } - } - - console.log('data' + JSON.stringify(formData)) - - this.taskDataService.deleteData(formData).subscribe({ - next: response => console.log('Response from server:', response), - error: error => console.error('Error:', error) - }); - } - - getAnswerData() { - - this.answerDataService.getData().subscribe(response => { - console.log(response); - this.answerData = JSON.stringify(response); - }); - } - - postAnswerData(formData: any) { - if (!formData) { - formData = { - "answerID": 1, - "taskAnswer_1": 5, - "taskAnswer_2": 5, - "taskAnswer_3": 5, - "taskAnswer_4": 5, - "taskAnswer_5": 5, - "taskAnswer_6": 5, - "taskScore": 30, - "dateTaken": "2023-05-15 11:30:00", - "userID": 1, - "taskID": 1 - } - } - - this.answerDataService.postData(formData).subscribe({ - next: response => console.log('Response from server:', response), - error: error => console.error('Error:', error) - }); - - } - - updateAnswerData(formData: any) { - if (!formData) { - formData = { - "answerID": 16, - "taskAnswer_1": 10, - "taskAnswer_2": 5, - "taskAnswer_3": 5, - "taskAnswer_4": 5, - "taskAnswer_5": 5, - "taskAnswer_6": 5, - "taskScore": 30, - "dateTaken": "2023-05-15 11:30:00", - "userID": 1, - "taskID": 1 - } - } - - - this.answerDataService.updateData(formData).subscribe({ - next: response => console.log('Response from server:', response), - error: error => console.error('Error:', error) - }); - } - - deleteAnswerData(formData: any) { - if (!formData) { - formData = { - "answerID": 19 - } - } - - console.log('data' + JSON.stringify(formData)) - - this.answerDataService.deleteData(formData).subscribe({ - next: response => console.log('Response from server:', response), - error: error => console.error('Error:', error) - }); - } - - getUserData() { - - this.userDataService.getData().subscribe(response => { - console.log(response); - this.userData = JSON.stringify(response); - }); - } - - postUserData(formData: any) { - if (!formData) { - formData = { - "email": "user1@example.com", - "password": "password123" - } - } - - this.userDataService.postData(formData).subscribe({ - next: response => console.log('Response from server:', response), - error: error => console.error('Error:', error) - }); - - } - - updateUserData(formData: any) { - if (!formData) { - formData = { - "userID": 8, - "email": "user8@example.com", - "password": "password123" - } - } - - - this.userDataService.updateData(formData).subscribe({ - next: response => console.log('Response from server:', response), - error: error => console.error('Error:', error) - }); - } - - deleteUserData(formData: any) { - if (!formData) { - formData = { - "userID": 19 - } - } - - console.log('data' + JSON.stringify(formData)) - - this.userDataService.deleteData(formData).subscribe({ - next: response => console.log('Response from server:', response), - error: error => console.error('Error:', error) - }); - } - - - startSession() { - this.userDataService.startSession().subscribe((response: any) => { - if (response.sessionId) { - sessionStorage.setItem('sessionId', response.sessionId); - } - }); - } - - storeData() { - this.userDataService.storeSessionData(); - } - - getData() { - this.userDataService.getSessionData().subscribe((data) => { - console.log(data); - }); - } - - - - - - - - ngOnInit() { - } -} diff --git a/client/src/assets/icon/circuit.png b/client/src/assets/icon/circuit.png new file mode 100644 index 0000000..dff05f2 Binary files /dev/null and b/client/src/assets/icon/circuit.png differ diff --git a/client/src/index.html b/client/src/index.html index 8f5a3a4..411507e 100644 --- a/client/src/index.html +++ b/client/src/index.html @@ -8,12 +8,14 @@ - + - + + + diff --git a/server/api/answer/delete/index.php b/server/api/answer/delete/index.php index f2648a0..a485881 100644 --- a/server/api/answer/delete/index.php +++ b/server/api/answer/delete/index.php @@ -40,6 +40,30 @@ return; } + // Check if session has timed out + $lastLoginTime = strtotime($user['lastLogin']); + $currentTime = time(); + $timeElapsed = $currentTime - $lastLoginTime; + $timeoutThreshold = 3 * 60 * 60; // 3 hours in seconds + + if ($timeElapsed > $timeoutThreshold) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return session timeout message + echo json_encode(array('message' => 'Session Timeout')); + return; + } + + if (($user['session_id'] === 'REVOKED' || empty($user['session_id']))) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return success response + echo json_encode(array('message' => 'Session ID REVOKED')); + return; + } + // Your DELETE query $query = "DELETE FROM $table WHERE answerID = :value1"; diff --git a/server/api/answer/get/index.php b/server/api/answer/get/index.php index 33268d2..ce2e787 100644 --- a/server/api/answer/get/index.php +++ b/server/api/answer/get/index.php @@ -52,6 +52,30 @@ return; } + // Check if session has timed out + $lastLoginTime = strtotime($user['lastLogin']); + $currentTime = time(); + $timeElapsed = $currentTime - $lastLoginTime; + $timeoutThreshold = 3 * 60 * 60; // 3 hours in seconds + + if ($timeElapsed > $timeoutThreshold) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return session timeout message + echo json_encode(array('message' => 'Session Timeout')); + return; + } + + if (($user['session_id'] === 'REVOKED' || empty($user['session_id']))) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return success response + echo json_encode(array('message' => 'Session ID REVOKED')); + return; + } + try { // Retrieve data from the table diff --git a/server/api/answer/index.php b/server/api/answer/index.php index 9fac6d2..41e70ae 100644 --- a/server/api/answer/index.php +++ b/server/api/answer/index.php @@ -14,24 +14,6 @@ die("Database connection failed: " . $e->getMessage()); } -// API endpoint for retrieving data from a table -if ($_SERVER['REQUEST_METHOD'] === 'GET') { - try { - // Retrieve data from the table - $query = "SELECT * FROM $table"; - $stmt = $db->prepare($query); - $stmt->execute(); - $data = $stmt->fetchAll(PDO::FETCH_ASSOC); - - // Return the data as JSON response - header('Content-Type: application/json'); - header('Access-Control-Allow-Origin: *'); // Allow requests from any origin - echo json_encode($data); - } catch (PDOException $e) { - die("Retrieval failed: " . $e->getMessage()); - } -} - // API endpoint for inserting data into a table if ($_SERVER['REQUEST_METHOD'] === 'POST') { sanitizeRequestStrings(); @@ -57,7 +39,28 @@ return; } + if (($user['session_id'] === 'REVOKED' || empty($user['session_id']))) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return success response + echo json_encode(array('message' => 'Session ID REVOKED')); + return; + } + // Check if session has timed out + $lastLoginTime = strtotime($user['lastLogin']); + $currentTime = time(); + $timeElapsed = $currentTime - $lastLoginTime; + $timeoutThreshold = 3 * 60 * 60; // 3 hours in seconds + if ($timeElapsed > $timeoutThreshold) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return session timeout message + echo json_encode(array('message' => 'Session Timeout')); + return; + } // Insert the data into the table $query = "INSERT INTO $table (taskAnswer_1, taskAnswer_2, taskAnswer_3, taskAnswer_4, taskAnswer_5, taskAnswer_6, taskScore, dateTaken, userID, taskID) VALUES (:value2, :value3, :value4, :value5, :value6, :value7, :value8, :value9, :value10, :value11)"; diff --git a/server/api/answer/update/index.php b/server/api/answer/update/index.php index 8162d96..316a36c 100644 --- a/server/api/answer/update/index.php +++ b/server/api/answer/update/index.php @@ -42,6 +42,29 @@ return; } + if (($user['session_id'] === 'REVOKED' || empty($user['session_id']))) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return success response + echo json_encode(array('message' => 'Session ID REVOKED')); + return; + } + // Check if session has timed out + $lastLoginTime = strtotime($user['lastLogin']); + $currentTime = time(); + $timeElapsed = $currentTime - $lastLoginTime; + $timeoutThreshold = 3 * 60 * 60; // 3 hours in seconds + + if ($timeElapsed > $timeoutThreshold) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return session timeout message + echo json_encode(array('message' => 'Session Timeout')); + return; + } + diff --git a/server/api/task/delete/index.php b/server/api/task/delete/index.php index ddb747d..e6392a7 100644 --- a/server/api/task/delete/index.php +++ b/server/api/task/delete/index.php @@ -46,6 +46,30 @@ return; } + if (($user['session_id'] === 'REVOKED' || empty($user['session_id']))) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return success response + echo json_encode(array('message' => 'Session ID REVOKED')); + return; + } + + // Check if session has timed out + $lastLoginTime = strtotime($user['lastLogin']); + $currentTime = time(); + $timeElapsed = $currentTime - $lastLoginTime; + $timeoutThreshold = 3 * 60 * 60; // 3 hours in seconds + + if ($timeElapsed > $timeoutThreshold) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return session timeout message + echo json_encode(array('message' => 'Session Timeout')); + return; + } + // Check if the required parameter is present if (empty($requestData['taskID'])) { diff --git a/server/api/task/get/index.php b/server/api/task/get/index.php index 42dc5da..b4bac08 100644 --- a/server/api/task/get/index.php +++ b/server/api/task/get/index.php @@ -51,6 +51,29 @@ return; } + // Check if session has timed out + $lastLoginTime = strtotime($user['lastLogin']); + $currentTime = time(); + $timeElapsed = $currentTime - $lastLoginTime; + $timeoutThreshold = 3 * 60 * 60; // 3 hours in seconds + + if ($timeElapsed > $timeoutThreshold) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return session timeout message + echo json_encode(array('message' => 'Session Timeout')); + return; + } + + if (($user['session_id'] === 'REVOKED' || empty($user['session_id']))) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return success response + echo json_encode(array('message' => 'Session ID REVOKED')); + return; + } try { // Retrieve data from the table diff --git a/server/api/task/index.php b/server/api/task/index.php index dbe8dfe..d03d9a1 100644 --- a/server/api/task/index.php +++ b/server/api/task/index.php @@ -27,24 +27,6 @@ die("Database connection failed: " . $e->getMessage()); } -// API endpoint for retrieving data from a table -if ($_SERVER['REQUEST_METHOD'] === 'GET') { - try { - // Retrieve data from the table - $query = "SELECT * FROM $table"; - $stmt = $db->prepare($query); - $stmt->execute(); - $data = $stmt->fetchAll(PDO::FETCH_ASSOC); - - // Return the data as JSON response - header('Content-Type: application/json'); - header('Access-Control-Allow-Origin: *'); // Allow requests from any origin - echo json_encode($data); - } catch (PDOException $e) { - die("Retrieval failed: " . $e->getMessage()); - } -} - // API endpoint for inserting data into a table // Check if request method is POST @@ -72,6 +54,29 @@ return; } + if (($user['session_id'] === 'REVOKED' || empty($user['session_id']))) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return success response + echo json_encode(array('message' => 'Session ID REVOKED')); + return; + } + + // Check if session has timed out + $lastLoginTime = strtotime($user['lastLogin']); + $currentTime = time(); + $timeElapsed = $currentTime - $lastLoginTime; + $timeoutThreshold = 3 * 60 * 60; // 3 hours in seconds + + if ($timeElapsed > $timeoutThreshold) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return session timeout message + echo json_encode(array('message' => 'Session Timeout')); + return; + } // Check if required data is provided diff --git a/server/api/task/update/index.php b/server/api/task/update/index.php index a3bf020..a7f8862 100644 --- a/server/api/task/update/index.php +++ b/server/api/task/update/index.php @@ -49,7 +49,29 @@ return; } + // Check if session has timed out + $lastLoginTime = strtotime($user['lastLogin']); + $currentTime = time(); + $timeElapsed = $currentTime - $lastLoginTime; + $timeoutThreshold = 3 * 60 * 60; // 3 hours in seconds + if ($timeElapsed > $timeoutThreshold) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return session timeout message + echo json_encode(array('message' => 'Session Timeout')); + return; + } + + if (($user['session_id'] === 'REVOKED' || empty($user['session_id']))) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return success response + echo json_encode(array('message' => 'Session ID REVOKED')); + return; + } // Update the data in the table $query = "UPDATE $table SET taskName = :value1, taskType = :value2, taskTime = :value3, userID = :value4 WHERE taskID = :id"; diff --git a/server/api/user/auth/index.php b/server/api/user/auth/index.php index 8a22cff..28accc9 100644 --- a/server/api/user/auth/index.php +++ b/server/api/user/auth/index.php @@ -27,7 +27,7 @@ // API endpoint for inserting data into a table if ($_SERVER['REQUEST_METHOD'] === 'POST') { - // sanitizeRequestStrings(); + sanitizeRequestStrings(); // Retrieve data from the request body @@ -66,9 +66,10 @@ // save session id to mysql database in user_table for column session_id $sessionId = session_id(); - $updateQuery = "UPDATE $table SET session_id=:session_id WHERE email=:email"; + $updateQuery = "UPDATE $table SET session_id=:session_id, lastLogin=:lastLogin WHERE email=:email"; $updateStmt = $db->prepare($updateQuery); $updateStmt->bindParam(':session_id', $sessionId); + $updateStmt->bindParam(':lastLogin', date('Y-m-d H:i:s')); $updateStmt->bindParam(':email', $requestData['email']); $updateStmt->execute(); diff --git a/server/api/user/auth/logout.php b/server/api/user/auth/logout.php new file mode 100644 index 0000000..a83486d --- /dev/null +++ b/server/api/user/auth/logout.php @@ -0,0 +1,96 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} catch (PDOException $e) { + die("Database connection failed: " . $e->getMessage()); +} + +header('Content-Type: application/json'); +header('Access-Control-Allow-Origin: *'); // Allow requests from any origin +// Return success response + + +// API endpoint for inserting data into a table +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + + sanitizeRequestStrings(); + + // Retrieve data from the request body + $requestData = $_REQUEST; + + + + // get user email and sessionID + $query = "SELECT * FROM user_table WHERE userID = :userID"; + $stmt = $db->prepare($query); + $stmt->bindParam(':userID', $requestData['userID']); + $stmt->execute(); + $user = $stmt->fetch(PDO::FETCH_ASSOC); + + + + if (!$user) { + header('Content-Type: application/json'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + http_response_code(401); + echo json_encode(['error' => 'No user found for this email.']); + exit(); + } + + // delete session id from database + + // authenticate user with userID and sessionID. + if (isset($requestData['sessionID']) && isset($requestData['userID'])) { + // get user email and sessionID + $query = "SELECT * FROM user_table WHERE userID = :userID"; + $stmt = $db->prepare($query); + $stmt->bindParam(':userID', $requestData['userID']); + $stmt->execute(); + $user = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!($user['session_id'] === $requestData['sessionID'])) { + // Set headers to return a JSON response + header('HTTP/1.1 400 Bad Request'); + header('Access-Control-Allow-Origin: *'); // Allow requests from any origin + // Return success response + echo json_encode(array('message' => 'Session ID Mismatch')); + return; + } + + // save session id to mysql database in user_table for column session_id + $sessionId = 'REVOKED'; + $updateQuery = "UPDATE $table SET session_id=:session_id WHERE userID = :userID"; + $updateStmt = $db->prepare($updateQuery); + $updateStmt->bindParam(':session_id', $sessionId); + $updateStmt->bindParam(':userID', $requestData['userID']); + $updateStmt->execute(); + + + + + echo json_encode(array( + 'message' => 'Logout successful!', + 'sessionID' => $sessionId, + 'Authorization' => 'true', + )); + } +} diff --git a/server/api/user/index.php b/server/api/user/index.php index 5d11026..5e0800d 100644 --- a/server/api/user/index.php +++ b/server/api/user/index.php @@ -14,20 +14,6 @@ die("Database connection failed: " . $e->getMessage()); } -// API endpoint for retrieving data from a table -if ($_SERVER['REQUEST_METHOD'] === 'GET') { - // Retrieve data from the table - $query = "SELECT * FROM $table"; - $stmt = $db->prepare($query); - $stmt->execute(); - $data = $stmt->fetchAll(PDO::FETCH_ASSOC); - - // Return the data as JSON response - header('Content-Type: application/json'); - header('Access-Control-Allow-Origin: *'); // Allow requests from any origin - echo json_encode($data); -} - // API endpoint for inserting data into a table if ($_SERVER['REQUEST_METHOD'] === 'POST') { @@ -50,17 +36,26 @@ session_start(); // save session id to mysql database in user_table for column session_id $sessionId = session_id(); - $updateQuery = "UPDATE $table SET session_id=:session_id WHERE email=:email"; + $updateQuery = "UPDATE $table SET session_id=:session_id, lastLogin=:lastLogin WHERE email=:email"; $updateStmt = $db->prepare($updateQuery); $updateStmt->bindParam(':session_id', $sessionId); + $updateStmt->bindParam(':lastLogin', date('Y-m-d H:i:s')); $updateStmt->bindParam(':email', $requestData['email']); $updateStmt->execute(); + // get user email + $query = "SELECT * FROM $table WHERE email = :email"; + $stmt = $db->prepare($query); + $stmt->bindParam(':email', $requestData['email']); + $stmt->execute(); + $user = $stmt->fetch(PDO::FETCH_ASSOC); + header('Content-Type: application/json'); header('Access-Control-Allow-Origin: *'); // Allow requests from any origin echo json_encode(array( 'message' => 'Data inserted successfully', 'sessionID' => session_id(), - 'Authorization' => 'true' + 'Authorization' => 'true', + 'userID' => $user['userID'] )); } diff --git a/server/api/user/start_session.php b/server/api/user/start_session.php deleted file mode 100644 index a5558d5..0000000 --- a/server/api/user/start_session.php +++ /dev/null @@ -1,19 +0,0 @@ - 'Session Started', 'sessionId' => $sessionId));