# 22nd August Report
## Progress
Time: **08:55**
Event: Entering the lab
---
### Create session login service to check login status
Time: **10:28**
- The purpose is to block repairman to access certain pages with check repairman login status.
- If repairman has logged in (**true**) he can only access Home page, Report Repair page, Profile page, and Detail modal page.
- If repairman hasn't logged in (**false**) he can only access Login page, Register page, Forgot Password page, and Reset Password page.
- Basically this service will prevent the repairman to access pages which he can't enter after login and vice versa when after log out or hasn't login yet.
- Create the new service and in **login-session.service.ts**.
```typescript=
import { Injectable } from '@angular/core';
import { PreferenceManagerService } from '../PreferenceManager/preference-manager.service';
import { StaticVariables } from 'src/app/classes/StaticVariables/static-variables';
import { NavController } from '@ionic/angular';
@Injectable({
providedIn: 'root'
})
export class LoginSessionService {
constructor(
private pref: PreferenceManagerService,
private navCtrl: NavController
) { }
async checkLoginStatus () {
let email = await this.pref.getData(StaticVariables.KEY__LOGIN_EMPLOYEE_EMAIL);
let id = await this.pref.getData(StaticVariables.KEY__LOGIN_EMPLOYEE_ID);
if (
email !== "" && email !== null && email !== undefined &&
id !== "" && id !== null && id !== undefined
) {
return true;
} else {
return false;
}
}
async blockToAuthPages () {
if (await this.checkLoginStatus())
this.navCtrl.navigateForward(['home']);
}
async blockToInternalPages () {
if (!await this.checkLoginStatus())
this.navCtrl.navigateForward(['login'])
}
}
```
- In **line16-27**, `checkLoginStatus()` perform as the checker which fetch the repairman's email address and employee ID from Preference, it will return true if **both of them** are present and false if not.
- In **line 29-38**, `blockToAuthPages()` get return value from previous function and route the user to Home page, on the other hand `blockToInternalPages()` route the user to Login page.
---
### Implement session system to restrict pages with some status
Time: **13:25**
- Implement the service into the correct pages:
- `blockToInternalPages()` for:
- Home page
- Profile page
- Report Repair page
- Detail modal page
- `blockToAuthPages()` for:
- Login page
- Register page
- Forgot Password page
- Reset Password page
---
- Example to implement `blockToInternalPages()`:
```typescript=
export class ProfilePage implements OnInit {
constructor(
private chk: LoginSessionService
) { }
ionViewDidEnter () {
this.chk.blockToInternalPages();
}
}
```
Result:
<center>
<img src="https://raw.githubusercontent.com/aru1702/images/master/ntust-documentation/49-01.gif" style="max-width: 250px">
</center>
- Example to implement `blockToAuthPages()`:
```typescript=
export class LoginPage implements OnInit {
constructor(
private chk: LoginSessionService
) { }
ionViewDidEnter () {
this.chk.blockToAuthPages();
}
}
```
Result:
<center>
<img src="https://raw.githubusercontent.com/aru1702/images/master/ntust-documentation/49-02.gif" style="max-width: 250px">
</center>
- To sum up:
- Repairman cannot perform any authentication, like login or register, once he has been logged in.
- Repairman cannot access the main pages, like Home or Profile page, if he hasn't logged in yet.
- To get out from login session/remove login status, repairman can do either reset his browser/PWA app or perform LOG OUT from Profile page.
---
## Conclusion
- Create a service to handle login session, the purpose is to block the access of repairman when the login status (already logged in) is valid/invalid.
- This service will prevent the repairman to access authentication pages, like login or register, once he has been logged in, and also prevent to access main pages, like Home or Profile page, if he hasn't logged in yet.
- With using service, every pages in Repairman App only have to call the correct function to prevent the repairman to access wrong pages.
---
Time: **18:00**
Event: Leaving the lab
###### tags: `on-intern`