Commit 4d7c10e4 authored by achinta's avatar achinta

change: login in system

parent f1c552fe
...@@ -13,8 +13,8 @@ export const verifyRoleGuard: CanActivateFn = ( ...@@ -13,8 +13,8 @@ export const verifyRoleGuard: CanActivateFn = (
const requiredRoles: string[] = route.data['roles'] as string[]; const requiredRoles: string[] = route.data['roles'] as string[];
const userRole: string = localStorage.getItem('role')||''; const userRole: string = localStorage.getItem('role')||'';
// console.log('requiredRoles=>',requiredRoles); console.log('requiredRoles=>',requiredRoles);
// console.log('userRole=>',userRole); console.log('userRole=>',userRole);
// return true; // return true;
if( userRole && isRoleValid(requiredRoles, userRole) ) return true; if( userRole && isRoleValid(requiredRoles, userRole) ) return true;
......
...@@ -3,7 +3,9 @@ export interface UserProfile { ...@@ -3,7 +3,9 @@ export interface UserProfile {
name: string; name: string;
project_id: number; project_id: number;
role_name: string; role_name: string;
user_id: number; user_id: string;
user_type: string; user_type: string;
username: string; username: string;
phone: string;
logged_id: string
} }
...@@ -2,59 +2,68 @@ ...@@ -2,59 +2,68 @@
<div class="top_yellow_line"></div> <div class="top_yellow_line"></div>
<div class="logo_section"> <div class="logo_section">
<img class="login_logo" [ngSrc]="loggedSchoolLogo" alt="Logo" width="80" height="80" /> <img class="login_logo" [ngSrc]="loggedSchoolLogo" alt="Logo" width="80" height="80" />
<p>La Martiniere for Girls</p> <p> {{schoolHeader}} </p>
</div> </div>
<div class="top_blue_line"></div> <div class="top_blue_line"></div>
<div class="NumberOtp"> <div class="NumberOtp">
<div class="login_outer"> <div class="login_outer">
<div class="phone_section"> <div class="phone_section">
<form class="login_form" [formGroup]="loginForm">
<h5>Welcome</h5> <h5>Welcome</h5>
<p>Enter your username and password to continue</p> <mat-radio-group aria-label="Select an option" formControlName="role">
<mat-radio-button value="student">Student</mat-radio-button>
<mat-radio-button value="EDITOR">Teacher</mat-radio-button>
</mat-radio-group>
<p>Enter your username and password to continue</p>
<form class="login_form" [formGroup]="loginForm">
<div class="mat_input_container"> <div class="mat_input_container" [ngClass]="{'d-none': otpSend}" >
<mat-form-field class="full_width"> <mat-form-field class="full_width">
<span class="material-symbols-outlined" matPrefix> <span class="material-symbols-outlined" matPrefix>
person person
</span> </span>
<input class="inputStyle" matInput placeholder="{{ 'Enter your number' }}" #input formControlName="email" /> <input class="inputStyle" matInput placeholder="{{ 'Enter your number' }}" #input
formControlName="phoneNo" />
</mat-form-field> </mat-form-field>
<ng-container <ng-container
*ngIf="loginForm.controls.email.invalid && loginForm.controls.email.dirty || loginForm.controls.email.invalid && loginForm.controls.email.touched"> *ngIf="loginForm.controls.phoneNo.invalid && loginForm.controls.phoneNo.dirty || loginForm.controls.phoneNo.invalid && loginForm.controls.phoneNo.touched">
<span class="error_text" *ngIf="loginForm.controls.email.hasError('required')">This field is required <span class="error_text" *ngIf="loginForm.controls.phoneNo.hasError('required')">This field is
</span> required</span>
<span class="error_text" *ngIf="loginForm.controls.phoneNo.hasError('pattern')">Phone number must be 10
digits.</span>
</ng-container> </ng-container>
</div> </div>
<app-rounded-button-full-width [buttonText]="'Send otp'" [enableThrottling]="true"
(onClickEventEmitter)="sendOtp()" [ngClass]="{'d-none': otpSend}"/>
<div class="mat_input_container"> <div class="mat_input_container" [ngClass]="{'d-none': !otpSend}" >
<mat-form-field class="full_width"> <mat-form-field class="full_width">
<span class="material-symbols-outlined" matPrefix> lock </span> <span class="material-symbols-outlined" matPrefix> lock </span>
<input matInput placeholder="{{ 'Enter your OTP' }}" [type]="hidePassword ? 'password' : 'text'" <input matInput placeholder="{{ 'Enter OTP' }}" [type]="hidePassword ? 'password' : 'text'"
formControlName="password" /> formControlName="otp" />
<span class="material-symbols-outlined pointer" matSuffix (click)="hidePassword = !hidePassword"> <span class="material-symbols-outlined pointer" matSuffix (click)="hidePassword = !hidePassword">
{{ hidePassword ? "visibility_off" : "visibility" }} {{ hidePassword ? "visibility_off" : "visibility" }}
</span> </span>
<!-- <mat-hint *ngIf="!passwordInput.value">Enter your password</mat-hint> --> <!-- <mat-hint *ngIf="!passwordInput.value">Enter your password</mat-hint> -->
</mat-form-field> </mat-form-field>
<ng-container <ng-container
*ngIf="loginForm.controls.password.invalid && loginForm.controls.password.dirty || loginForm.controls.password.invalid && loginForm.controls.password.touched"> *ngIf="loginForm.controls.otp.invalid && loginForm.controls.otp.dirty || loginForm.controls.otp.invalid && loginForm.controls.otp.touched">
<span class="error_text" *ngIf="loginForm.controls.password.hasError('required')">Password is required <span class="error_text" *ngIf="loginForm.controls.otp.hasError('required')">Otp is required</span>
</span> <span class="error_text" *ngIf="loginForm.controls.otp.hasError('pattern')">OTP must be 4 digits</span>
</ng-container> </ng-container>
</div> </div>
<app-rounded-button-full-width [buttonText]="'Sign in'" [buttonIconName]="'login'" [enableThrottling]="true" <app-rounded-button-full-width [buttonText]="'Sign in'" [buttonIconName]="'login'" [enableThrottling]="true"
(onClickEventEmitter)="authenticate()" /> (onClickEventEmitter)="authenticate()" [ngClass]="{'d-none': !otpSend}" />
</form> </form>
<div class="error_txt" *ngIf="errorMessage"> <!-- <div class="error_txt" *ngIf="errorMessage">
<!-- <span class="api_error_message">{{errorMessage}}</span> -->
<span class="api_error_message">fdgsgs</span> <span class="api_error_message">fdgsgs</span>
</div> </div> -->
</div> </div>
</div> </div>
</div> </div>
......
...@@ -151,4 +151,8 @@ ...@@ -151,4 +151,8 @@
bottom: -7px; bottom: -7px;
} }
} }
}
.d-none{
display: none;
} }
\ No newline at end of file
...@@ -13,69 +13,112 @@ import { AbstractControl, FormControl, FormGroup, ReactiveFormsModule, Validator ...@@ -13,69 +13,112 @@ import { AbstractControl, FormControl, FormGroup, ReactiveFormsModule, Validator
import { TransmissionMessageHandlerService } from '../../raintree/transmission-message-handler/transmission-message-handler'; import { TransmissionMessageHandlerService } from '../../raintree/transmission-message-handler/transmission-message-handler';
import { UserProfile } from '../interface/user-profile'; import { UserProfile } from '../interface/user-profile';
import { ToasterService } from '../../component-library/toaster/toaster.service'; import { ToasterService } from '../../component-library/toaster/toaster.service';
import { UrlConfigService } from '../../portal/service/url-config.service';
import { DataSourceService } from '../../portal/service/data-source.service';
import { MatRadioModule } from '@angular/material/radio';
import { RoleMapperService } from '../../mappers/role-mapper.service';
import { SendOtpService } from '../service/send-otp.service';
@Component({ @Component({
selector: 'app-login', selector: 'app-login',
imports: [ imports: [
NgOptimizedImage, NgOptimizedImage,
RouterModule, RouterModule,
RoundedButtonFullWidthComponent, RoundedButtonFullWidthComponent,
MatFormFieldModule, MatFormFieldModule,
MatInputModule, MatInputModule,
CommonModule, CommonModule,
ReactiveFormsModule ReactiveFormsModule,
], MatRadioModule
templateUrl: './login.component.html', ],
styleUrl: './login.component.scss' templateUrl: './login.component.html',
styleUrl: './login.component.scss'
}) })
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
public errorMessage: string = ''; public errorMessage: string = '';
public loggedSchoolLogo:string = ''; public loggedSchoolLogo: string = '';
public schoolHeader: string = '';
public otpSend:boolean = false;
constructor( constructor(
private _toaster:ToasterService, private _toaster: ToasterService,
private _authService: AuthService, private _authService: AuthService,
private _authTransmissionService: AuthTransmissionService, private _authTransmissionService: AuthTransmissionService,
private _urlConfig: UrlConfigService,
private _optService:SendOtpService,
private _transmissionMessageHandler: TransmissionMessageHandlerService) { private _transmissionMessageHandler: TransmissionMessageHandlerService) {
} }
public hidePassword: boolean = true; public hidePassword: boolean = true;
public loginForm = new FormGroup({ public loginForm = new FormGroup({
email: new FormControl('', [Validators.required]), phoneNo: new FormControl('6290861931', [
password: new FormControl('', [Validators.required]), Validators.required,
Validators.pattern(/^\d{10}$/)
]),
otp: new FormControl('1234', [
Validators.required,
Validators.pattern(/^\d{4}$/)
]),
role: new FormControl('student', [Validators.required])
}); });
public ngOnInit(): void { public ngOnInit(): void {
this.loggedSchoolLogo = this._authService.getLoggedSchoolLogo(); this.loggedSchoolLogo = this._authService.getLoggedSchoolLogo();
this.schoolHeader = this._authService.getSchoolHeader()
} }
public authenticate(): void { public authenticate(): void {
if (this.loginForm.invalid) return; if (this.loginForm.invalid) return;
let loginFormPayload: Auth = this.loginForm.value as Auth; // let loginFormPayload: Auth = this.loginForm.value as Auth;
if(!this._optService.matchOtp(Number(this.loginForm.value.otp))){
this._toaster.error('Otp is not matched');
this.otpSend = !this.otpSend;
return;
}
this._authTransmissionService.getAuthToken( this._getUserDetails();
}
private _autoLogin(userInfo:any){
let loginFormPayload = {
'email':'achinta@hotmail.com',
'password':'P@$$w0rd'
}
this._authTransmissionService.getAuthToken(
TransmissionMapperService.LOGIN_TRANSMISSION_URL, TransmissionMapperService.LOGIN_TRANSMISSION_URL,
loginFormPayload, loginFormPayload,
() => { }, () => { },
() => { }, () => { },
(response: RaintreeResponse) => { (response: RaintreeResponse) => {
if (this._transmissionMessageHandler.hasError(response)) { if (this._transmissionMessageHandler.hasError(response)) {
this.errorMessage = response['message']; this.errorMessage = response['message'];
console.log(this.errorMessage); console.log(this.errorMessage);
return; return;
}; };
let user_data = {
apiKey: `${response['data'].apiKey}`,
name: `${userInfo.name['en']}`,
project_id: response['data'].project_id,
role_name: `${this.loginForm.value.role}`,
user_id: response['data'].user_id,
user_type: response['data'].user_type,
username: `${userInfo.name['en']}`,
phone:`${userInfo.phone['en']}`,
logged_id: `${userInfo.id}`
}
this._authService.storeJwtTokenInLocalStorage(response['data'].apiKey); this._authService.storeJwtTokenInLocalStorage(response['data'].apiKey);
// this._getUserProfile(); // this._getUserProfile();
this._authService.prepareLoginProcess(response['data']); this._authService.prepareLoginProcess(user_data);
this._toaster.success('Successfully Logged in','Done') this._toaster.success('Successfully Logged in','Done')
}, },
...@@ -88,23 +131,69 @@ export class LoginComponent implements OnInit { ...@@ -88,23 +131,69 @@ export class LoginComponent implements OnInit {
); );
} }
private _getUserProfile(): void { // private _getUserProfile(): void {
this._authTransmissionService.getUserProfile( // this._authTransmissionService.getUserProfile(
TransmissionMapperService.USER_PROFILE_TRANSMISSION_URL, // TransmissionMapperService.USER_PROFILE_TRANSMISSION_URL,
// () => { },
// (response) => { },
// (response: UserProfile) => {
// if (!response) {
// this.errorMessage = 'something went wrong';
// return;
// };
// this._authService.prepareLoginProcess(response);
// },
// () => { }, () => { }
// )
// }
private _getUserDetails() {
this._authTransmissionService.getUser(
TransmissionMapperService.GET_TRANSMISSION_URL + this._urlConfig.generateDatasourceConfigUrl({
aggregationOnUniqueFld: false,
datasourceId: `${this.loginForm.get('role')?.value === RoleMapperService.TEACHER_ROLE ? DataSourceService.TEACHER_DATA_SOURCE_ID : DataSourceService.STUDENT_DATA_SOURCE_ID}`,
dontIncludeForeignKey: false,
expand: true,
access: 'PUBLIC',
isUniqueValueRequiredForFieldToDisplay: false,
language: "en",
limit: 100,
orderBy: "DESC",
page: 1,
fieldName: "user_name",
operators: "eq",
fieldValues: `${this.loginForm.get('phoneNo')?.value}`,
// this.authService.localStorageGetItemByKey("user_id"),
}),
() => { }, () => { },
(response) => { }, (response) => { },
(response: UserProfile) => { (response: RaintreeResponse) => {
if (!response) { let userInfo = response['data'].themeDataSourceFields[0];
this.errorMessage = 'something went wrong';
if(!userInfo) {
this._toaster.error('Invalid user','Ok');
return; return;
}; }
this._authService.prepareLoginProcess(response); this._autoLogin(userInfo);
}, },
() => { }, () => { } (error) => {
console.log(error);
},
() => { }
) )
}
public sendOtp(): void {
this.otpSend = this._optService.sendOtp(Number(this.loginForm.value.phoneNo));
// console.log(otp);
// this.otpSend = !this.otpSend;
} }
} }
...@@ -4,6 +4,8 @@ import { isPlatformBrowser } from '@angular/common'; ...@@ -4,6 +4,8 @@ import { isPlatformBrowser } from '@angular/common';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { RequestMapperService } from '../../mappers/request-mapper.service'; import { RequestMapperService } from '../../mappers/request-mapper.service';
import { LogoutService } from '../../portal/navigation/service/logout.service'; import { LogoutService } from '../../portal/navigation/service/logout.service';
import { Student } from '../../portal/portal-dashboard/interface/students';
import { RoleMapperService } from '../../mappers/role-mapper.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
...@@ -25,13 +27,13 @@ export class AuthService { ...@@ -25,13 +27,13 @@ export class AuthService {
} }
public prepareLoginProcess(userProfileData: UserProfile): void { public prepareLoginProcess(userProfileData: UserProfile): void {
this._setProfileInformationInLocalStorage(userProfileData); this._setProfileInformationInLocalStorage(userProfileData);
if (this.isBrowser) { if (this.isBrowser) {
localStorage.setItem('isLoggedIn', 'true'); localStorage.setItem('isLoggedIn', 'true');
// TODO: This is for temporary // TODO: This is for temporary
if(userProfileData.role_name === 'Teacher') { if(userProfileData.role_name === RoleMapperService.TEACHER_ROLE) {
localStorage.setItem('role', 'EDITOR'); localStorage.setItem('role', 'EDITOR');
} else{ } else{
...@@ -48,10 +50,10 @@ export class AuthService { ...@@ -48,10 +50,10 @@ export class AuthService {
localStorage.setItem('userProfile', JSON.stringify(userProfileData)); localStorage.setItem('userProfile', JSON.stringify(userProfileData));
} }
public localStorageGetItemByKey(key: string): string{ public localStorageGetItemByKey(key: string): string {
const localStorageItem = JSON.parse(localStorage.getItem('userProfile')!); const localStorageItem = JSON.parse(localStorage.getItem('userProfile')!);
return localStorageItem[key] || ''; return localStorageItem[key] || '';
} }
...@@ -60,13 +62,24 @@ export class AuthService { ...@@ -60,13 +62,24 @@ export class AuthService {
return this.localStorageGetItemByKey('role_name'); return this.localStorageGetItemByKey('role_name');
} }
public getLoggedSchoolLogo(): string{ public getLoggedSchoolLogo(): string {
let logged_school = localStorage.getItem('logged_school'); let logged_school = localStorage.getItem('logged_school');
let logo = ''; let logo = '';
if(logged_school === 'boys') logo = './assets/image/b_logo.png'; if (logged_school === 'boys') logo = './assets/image/b_logo.png';
if(logged_school === 'girls') logo = './assets/image/g_logo.png'; if (logged_school === 'girls') logo = './assets/image/g_logo.png';
return logo; return logo;
} }
public getSchoolHeader(){
let logged_school = localStorage.getItem('logged_school');
let text = ''
if (logged_school === 'boys') text = 'La Martiniere for Boys';
if (logged_school === 'girls') text = 'La Martiniere for Girls';
return text;
}
public getUserName() {
return this.localStorageGetItemByKey('phone');
}
} }
import { TestBed } from '@angular/core/testing';
import { SendOtpService } from './send-otp.service';
describe('SendOtpService', () => {
let service: SendOtpService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(SendOtpService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import { inject, Injectable } from '@angular/core';
import { ToasterService } from '../../component-library/toaster/toaster.service';
import { RequestMapperService } from '../../mappers/request-mapper.service';
import { AuthTransmissionService } from '../../raintree/transmission/auth-transmission.service';
import { RaintreeResponse } from '../../raintree/interface/raintree-response';
@Injectable({
providedIn: 'root'
})
export class SendOtpService {
constructor() { }
private _toaster = inject(ToasterService);
private _authTransmissionService = inject(AuthTransmissionService);
private _otp: number = 0;
public sendOtp(phone: number): boolean {
this._otp = Math.floor(1000 + Math.random() * 9000);
let otpUrl = RequestMapperService.OTP_URL;
this._otp = 1234;
const makeOtpUrl = otpUrl
.replace("[NUMBER]", String(phone))
.replace("[OTP]", String(this._otp))
console.log(makeOtpUrl);
// this._prepareToSendOtp(makeOtpUrl);
// https://103.229.250.200/smpp/sendsms?username=lmccao&password=sms@2023&to=6290861931&from=LMCCAO&text=7556%20is%20the%20OTP%20to%20create%20new%20password.%20For%20any%20assistance,%20please%20call%20033-4040-6607.%0A%0ABursar-cum-Assistant%20Secretary,%0ALa%20Martiniere%20Schools
this._toaster.success('Otp send successfully', 'Ok')
return true;
}
public matchOtp(otpByUser: number): boolean {
return this._otp === otpByUser;
}
private _prepareToSendOtp(url: string) {
this._authTransmissionService.executeBasicGet(
url,
() => { },
() => { },
(response) => {
console.log(response);
},
(error) => {
console.log(error);
},
() => { }
);
}
}
...@@ -16,13 +16,13 @@ ...@@ -16,13 +16,13 @@
</button> </button>
</ng-container> </ng-container>
<ng-container *ngIf="item =='edit' && authService.getUserRole() !== 'Parent'"> <ng-container *ngIf="item =='edit' && authService.getUserRole() !== 'student'">
<button class="view_button d_inline_block width_auto " (click)="edit(element)"> <button class="view_button d_inline_block width_auto " (click)="edit(element)">
<span class="material-symbols-outlined">edit</span> <span class="material-symbols-outlined">edit</span>
</button> </button>
</ng-container> </ng-container>
<ng-container *ngIf="item =='delete' && authService.getUserRole() !== 'Parent'"> <ng-container *ngIf="item =='delete' && authService.getUserRole() !== 'student'">
<button class="view_button d_inline_block width_auto " (click)="delete(element)"> <button class="view_button d_inline_block width_auto " (click)="delete(element)">
<span class="material-symbols-outlined">delete</span> <span class="material-symbols-outlined">delete</span>
</button> </button>
......
...@@ -28,4 +28,9 @@ export class RequestMapperService { ...@@ -28,4 +28,9 @@ export class RequestMapperService {
public static readonly PROFILE_URL: string = 'profile'; public static readonly PROFILE_URL: string = 'profile';
public static readonly CHANGE_PASSWORD_URL: string = 'update-password'; public static readonly CHANGE_PASSWORD_URL: string = 'update-password';
// Otp url
public static readonly OTP_URL: string = 'https://103.229.250.200/smpp/sendsms?username=lmccao&password=sms@2023&to=[NUMBER]&from=LMCCAO&text=[OTP]%20is%20the%20OTP%20to%20create%20new%20password.%20For%20any%20assistance,%20please%20call%20033-4040-6607.%0A%0ABursar-cum-Assistant%20Secretary,%0ALa%20Martiniere%20Schools';
} }
...@@ -8,7 +8,7 @@ export class RoleMapperService { ...@@ -8,7 +8,7 @@ export class RoleMapperService {
// NOTE:: this will be same value which is come from backend role // NOTE:: this will be same value which is come from backend role
public static readonly TEACHER_ROLE: string = 'EDITOR'; public static readonly TEACHER_ROLE: string = 'EDITOR';
public static readonly STUDENT_ROLE: string = 'Parent'; public static readonly STUDENT_ROLE: string = 'student';
public static get getAllRole(): string[] { public static get getAllRole(): string[] {
return [ return [
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
(emitView)="emitViewFromTable($event)" /> (emitView)="emitViewFromTable($event)" />
</div> </div>
<div class="add_btn" *ngIf="authService.getUserRole() !== 'Parent'"> <div class="add_btn" *ngIf="authService.getUserRole() !== 'student'">
<app-square-button [buttonIcon]="'add'" (emitSquareButtonClick)="addAssignment()" /> <app-square-button [buttonIcon]="'add'" (emitSquareButtonClick)="addAssignment()" />
</div> </div>
<!-- <app-mat-confirm-dialog /> --> <!-- <app-mat-confirm-dialog /> -->
\ No newline at end of file
...@@ -21,6 +21,6 @@ export interface Assignment { ...@@ -21,6 +21,6 @@ export interface Assignment {
section_details?: LocalizedField; section_details?: LocalizedField;
subject_subject_name?: LocalizedField; subject_subject_name?: LocalizedField;
class_subject_subject_txt?: LocalizedField; class_subject_subject_txt?: LocalizedField;
assigned_by_teacher: LocalizedField; assigned_by: LocalizedField;
} }
...@@ -180,7 +180,7 @@ export class ManageComponent { ...@@ -180,7 +180,7 @@ export class ManageComponent {
page:1, page:1,
fieldName: "subject_teacher,section", fieldName: "subject_teacher,section",
operators: "eq,eq", operators: "eq,eq",
fieldValues: `${this._auth.localStorageGetItemByKey("user_id")},${sectionId}` fieldValues: `${this._auth.localStorageGetItemByKey("logged_id")},${sectionId}`
}), }),
() => { }, () => { },
(response) => { }, (response) => { },
...@@ -216,7 +216,7 @@ export class ManageComponent { ...@@ -216,7 +216,7 @@ export class ManageComponent {
page: 1, page: 1,
fieldName: "teacher", fieldName: "teacher",
operators: "eq", operators: "eq",
fieldValues: this._auth.localStorageGetItemByKey("user_id") fieldValues: this._auth.localStorageGetItemByKey("logged_id")
}), }),
() => { }, () => { },
(response) => { }, (response) => { },
...@@ -269,10 +269,10 @@ export class ManageComponent { ...@@ -269,10 +269,10 @@ export class ManageComponent {
beng: `${this.assignmentForm.value.subject}`, beng: `${this.assignmentForm.value.subject}`,
hindi: `${this.assignmentForm.value.subject}`, hindi: `${this.assignmentForm.value.subject}`,
}, },
assigned_by_teacher: { assigned_by: {
en: `${this._auth.localStorageGetItemByKey('user_id')}`, en: `${this._auth.localStorageGetItemByKey('logged_id')}`,
beng: `${this._auth.localStorageGetItemByKey('user_id')}`, beng: `${this._auth.localStorageGetItemByKey('logged_id')}`,
hindi: `${this._auth.localStorageGetItemByKey('user_id')}`, hindi: `${this._auth.localStorageGetItemByKey('logged_id')}`,
}, },
session: { session: {
en: `${DataSourceService.SESSION_ID}`, en: `${DataSourceService.SESSION_ID}`,
...@@ -320,10 +320,10 @@ export class ManageComponent { ...@@ -320,10 +320,10 @@ export class ManageComponent {
beng: `${this.assignmentForm.value.subject}`, beng: `${this.assignmentForm.value.subject}`,
hindi: `${this.assignmentForm.value.subject}`, hindi: `${this.assignmentForm.value.subject}`,
}, },
assigned_by_teacher: { assigned_by: {
en: `${this._auth.localStorageGetItemByKey('user_id')}`, en: `${this._auth.localStorageGetItemByKey('logged_id')}`,
beng: `${this._auth.localStorageGetItemByKey('user_id')}`, beng: `${this._auth.localStorageGetItemByKey('logged_id')}`,
hindi: `${this._auth.localStorageGetItemByKey('user_id')}`, hindi: `${this._auth.localStorageGetItemByKey('logged_id')}`,
}, },
session: { session: {
en: '86af4d6b5675a82df4581f00c67f0c7f', en: '86af4d6b5675a82df4581f00c67f0c7f',
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
/> />
</div> </div>
<div class="add_btn" *ngIf="authService.getUserRole() !== 'Parent'"> <div class="add_btn" *ngIf="authService.getUserRole() !== 'student'">
<app-square-button <app-square-button
[buttonIcon]="'add'" [buttonIcon]="'add'"
(emitSquareButtonClick)="addExam()" (emitSquareButtonClick)="addExam()"
......
...@@ -10,16 +10,23 @@ export interface Students extends Data { ...@@ -10,16 +10,23 @@ export interface Students extends Data {
export interface Student { export interface Student {
id: string; id: string;
name: LocalizedField; name: LocalizedField;
parent_user: LocalizedField; user_name: LocalizedField;
class: LocalizedField; class: LocalizedField;
class_className: LocalizedField;
section_details: LocalizedField;
section: LocalizedField; section: LocalizedField;
section_class: LocalizedField;
section_class_className: LocalizedField;
section_class_details: LocalizedField;
email: LocalizedField; email: LocalizedField;
phone: LocalizedField; phone: LocalizedField;
address: LocalizedField; address: LocalizedField;
user_type: LocalizedField;
school: LocalizedField; school: LocalizedField;
school_school_Name: LocalizedField; school_school_Name: LocalizedField;
class_details: LocalizedField; class_details: LocalizedField;
section_details: LocalizedField; dob: LocalizedField;
fathers_name: LocalizedField;
mothers_name: LocalizedField;
reg_no: LocalizedField;
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<div class="portal_dashboard_container"> <div class="portal_dashboard_container">
<div class="portal_dashboard_inner"> <div class="portal_dashboard_inner">
<div class="portal_card_container"> <div class="portal_card_container">
@if (authService.getUserRole() === 'Parent') { @if (authService.getUserRole() === 'student') {
<div class="student_dropdown"> <div class="student_dropdown">
<mat-form-field class="full_width"> <mat-form-field class="full_width">
<mat-label >Select Student</mat-label> <mat-label >Select Student</mat-label>
......
...@@ -14,6 +14,7 @@ import { DropDown } from '../../component-library/dropdown/interface/drop-down'; ...@@ -14,6 +14,7 @@ import { DropDown } from '../../component-library/dropdown/interface/drop-down';
import { Student } from './interface/students'; import { Student } from './interface/students';
import { Dropdown } from '../../component-library/dropdown/interface/dropdown'; import { Dropdown } from '../../component-library/dropdown/interface/dropdown';
import { TeacherTransmissionService } from '../../raintree/transmission/teacher-transmission.service'; import { TeacherTransmissionService } from '../../raintree/transmission/teacher-transmission.service';
import { RoleMapperService } from '../../mappers/role-mapper.service';
@Component({ @Component({
selector: 'app-portal-dashboard', selector: 'app-portal-dashboard',
...@@ -54,8 +55,11 @@ export class PortalDashboardComponent implements OnInit { ...@@ -54,8 +55,11 @@ export class PortalDashboardComponent implements OnInit {
public ngOnInit(): void { public ngOnInit(): void {
(this.authService.getUserRole() === 'Parent') && this._getStudentByParentId(); // (this.authService.getUserRole() === 'Parent') && this._getStudentByParentId();
(this.authService.getUserRole() === 'Teacher') && this._getTeacherDetails(); (this.authService.getUserRole() === RoleMapperService.TEACHER_ROLE) && this._getTeacherDetails();
(this.authService.getUserRole() === RoleMapperService.STUDENT_ROLE) && this._getStudentByParentId();
} }
...@@ -65,8 +69,46 @@ export class PortalDashboardComponent implements OnInit { ...@@ -65,8 +69,46 @@ export class PortalDashboardComponent implements OnInit {
this._setSetStudentInfoInLocalStorage(selectedStudentInfo as Student); this._setSetStudentInfoInLocalStorage(selectedStudentInfo as Student);
} }
// FOR STUDENT LOGIN
private _getStudentByPhone() {
this.studentTransmission.getStudents(
TransmissionMapperService.GET_TRANSMISSION_URL + this._urlConfig.generateDatasourceConfigUrl({
aggregationOnUniqueFld: false,
datasourceId:DataSourceService.STUDENT_DATA_SOURCE_ID ,
dontIncludeForeignKey: false,
expand: true,
access:'PUBLIC',
isUniqueValueRequiredForFieldToDisplay: false,
language: "en",
limit: 100,
orderBy: "DESC",
page: 1,
fieldName: "user_name",
operators: "eq",
fieldValues: `${this.authService.getUserName()}`,
}),
() => { },
(response) => { },
(response: RaintreeResponse) => {
this.students = response['data'].themeDataSourceFields;
this.selectedStudent = this.students[0].id;
this._setSetStudentInfoInLocalStorage(this.students[0]);
},
(error) => {
console.log(error);
},
() => { }
)
}
// FOR PARENT LOGIN // FOR PARENT LOGIN
private _getStudentByParentId() { private _getStudentByParentId() {
this.studentTransmission.getStudents( this.studentTransmission.getStudents(
...@@ -81,9 +123,9 @@ export class PortalDashboardComponent implements OnInit { ...@@ -81,9 +123,9 @@ export class PortalDashboardComponent implements OnInit {
orderBy: "ASC", orderBy: "ASC",
page: 1, page: 1,
roleBasedFiltering: true, roleBasedFiltering: true,
fieldName: "parent_user", fieldName: "user_name",
operators: "eq", operators: "eq",
fieldValues: this.authService.localStorageGetItemByKey("user_id") fieldValues: `${this.authService.getUserName()}`
}), }),
() => { }, () => { },
(response) => { }, (response) => { },
...@@ -137,9 +179,9 @@ export class PortalDashboardComponent implements OnInit { ...@@ -137,9 +179,9 @@ export class PortalDashboardComponent implements OnInit {
orderBy: "ASC", orderBy: "ASC",
page: 1, page: 1,
roleBasedFiltering: true, roleBasedFiltering: true,
fieldName: "user", fieldName: "user_name",
operators: "eq", operators: "eq",
fieldValues: this.authService.localStorageGetItemByKey("user_id") fieldValues: `${this.authService.getUserName()}`
}), }),
() => { }, () => { },
(response) => { }, (response) => { },
......
...@@ -188,7 +188,7 @@ export class ManageComponent { ...@@ -188,7 +188,7 @@ export class ManageComponent {
page: 1, page: 1,
fieldName: "teacher", fieldName: "teacher",
operators: "eq", operators: "eq",
fieldValues: this._auth.localStorageGetItemByKey("user_id") fieldValues: this._auth.localStorageGetItemByKey("logged_id")
}), }),
() => { }, () => { },
(response) => { }, (response) => { },
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
/> />
</div> </div>
<div class="add_btn" *ngIf="authService.getUserRole() !== 'Parent'"> <div class="add_btn" *ngIf="authService.getUserRole() !== 'student'">
<app-square-button <app-square-button
[buttonIcon]="'add'" [buttonIcon]="'add'"
(emitSquareButtonClick)="addRoutine()" (emitSquareButtonClick)="addRoutine()"
......
import { inject, Injectable } from '@angular/core'; import { inject, Injectable } from '@angular/core';
import { AuthService } from '../../auth/service/auth.service'; import { AuthService } from '../../auth/service/auth.service';
import { DataSourceService } from './data-source.service'; import { DataSourceService } from './data-source.service';
import { RoleMapperService } from '../../mappers/role-mapper.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
...@@ -21,11 +22,11 @@ export class UrlConfigService { ...@@ -21,11 +22,11 @@ export class UrlConfigService {
switch (type) { switch (type) {
case 'assignment': case 'assignment':
if (this.authService.getUserRole() === 'Teacher') { if (this.authService.getUserRole() === RoleMapperService.TEACHER_ROLE) {
fieldName = "assigned_by_teacher"; fieldName = "assigned_by";
} else if (this.authService.getUserRole() === 'Parent') { } else if (this.authService.getUserRole() === RoleMapperService.STUDENT_ROLE) {
fieldName = "school,section_class,section"; fieldName = "school,section_class,section";
...@@ -33,11 +34,11 @@ export class UrlConfigService { ...@@ -33,11 +34,11 @@ export class UrlConfigService {
break; break;
case 'routine': case 'routine':
if (this.authService.getUserRole() === 'Teacher') { if (this.authService.getUserRole() === RoleMapperService.TEACHER_ROLE) {
fieldName = "session,school,section_teacher"; fieldName = "session,school,section_teacher";
} else if (this.authService.getUserRole() === 'Parent') { } else if (this.authService.getUserRole() === RoleMapperService.STUDENT_ROLE) {
fieldName = "section,session,school"; fieldName = "section,session,school";
} }
...@@ -55,11 +56,11 @@ export class UrlConfigService { ...@@ -55,11 +56,11 @@ export class UrlConfigService {
switch (type) { switch (type) {
case 'assignment': case 'assignment':
if (this.authService.getUserRole() === 'Teacher') { if (this.authService.getUserRole() === RoleMapperService.TEACHER_ROLE) {
fieldOperator = 'eq'; fieldOperator = 'eq';
} else if (this.authService.getUserRole() === 'Parent') { } else if (this.authService.getUserRole() === RoleMapperService.STUDENT_ROLE) {
fieldOperator = 'eq,eq,eq'; fieldOperator = 'eq,eq,eq';
...@@ -67,11 +68,11 @@ export class UrlConfigService { ...@@ -67,11 +68,11 @@ export class UrlConfigService {
break; break;
case 'routine': case 'routine':
if (this.authService.getUserRole() === 'Teacher') { if (this.authService.getUserRole() === RoleMapperService.TEACHER_ROLE) {
fieldOperator = "eq,eq,eq"; fieldOperator = "eq,eq,eq";
} else if (this.authService.getUserRole() === 'Parent') { } else if (this.authService.getUserRole() === RoleMapperService.STUDENT_ROLE) {
fieldOperator = "eq,eq,eq"; fieldOperator = "eq,eq,eq";
} }
...@@ -89,11 +90,11 @@ export class UrlConfigService { ...@@ -89,11 +90,11 @@ export class UrlConfigService {
switch (type) { switch (type) {
case 'assignment': case 'assignment':
if (this.authService.getUserRole() === 'Teacher') { if (this.authService.getUserRole() === RoleMapperService.TEACHER_ROLE) {
fieldValues = `${this.authService.localStorageGetItemByKey('user_id')}`; fieldValues = `${this.authService.localStorageGetItemByKey('logged_id')}`;
} else if (this.authService.getUserRole() === 'Parent') { } else if (this.authService.getUserRole() === RoleMapperService.STUDENT_ROLE) {
fieldValues = `${localStorage.getItem('student_school_id')},${localStorage.getItem('student_class_id')},${localStorage.getItem('student_section_id')}`; fieldValues = `${localStorage.getItem('student_school_id')},${localStorage.getItem('student_class_id')},${localStorage.getItem('student_section_id')}`;
...@@ -101,11 +102,11 @@ export class UrlConfigService { ...@@ -101,11 +102,11 @@ export class UrlConfigService {
break; break;
case 'routine': case 'routine':
if (this.authService.getUserRole() === 'Teacher') { if (this.authService.getUserRole() === RoleMapperService.TEACHER_ROLE) {
fieldValues = `${DataSourceService.SESSION_ID},${localStorage.getItem('school_id')},${this.authService.localStorageGetItemByKey('user_id')}`; fieldValues = `${DataSourceService.SESSION_ID},${localStorage.getItem('school_id')},${this.authService.localStorageGetItemByKey('logged_id')}`;
} else if (this.authService.getUserRole() === 'Parent') { } else if (this.authService.getUserRole() === RoleMapperService.STUDENT_ROLE) {
fieldValues = `${localStorage.getItem('student_section_id')},${DataSourceService.SESSION_ID},${localStorage.getItem('student_school_id')}`; fieldValues = `${localStorage.getItem('student_section_id')},${DataSourceService.SESSION_ID},${localStorage.getItem('student_school_id')}`;
} }
......
...@@ -56,6 +56,7 @@ export class AuthTransmissionService extends TransmissionService { ...@@ -56,6 +56,7 @@ export class AuthTransmissionService extends TransmissionService {
true true
) )
} }
public changePassword( public changePassword(
url: string, url: string,
...@@ -79,4 +80,24 @@ export class AuthTransmissionService extends TransmissionService { ...@@ -79,4 +80,24 @@ export class AuthTransmissionService extends TransmissionService {
) )
} }
public getUser(
url: string,
onPreExecute: () => void,
onPostExecute: (response: RaintreeResponse) => void,
onSuccess: (response: RaintreeResponse) => void,
onFailure: (error: string) => void,
onComplete: () => void
): void {
this.executePostPayload(
url,
{},
onPreExecute,
onPostExecute,
onSuccess,
onFailure,
onComplete,
false
);
}
} }
...@@ -25,13 +25,16 @@ export class TransmissionService { ...@@ -25,13 +25,16 @@ export class TransmissionService {
onPostExecute: (response: string) => void, onPostExecute: (response: string) => void,
onSuccess: (response: string) => void, onSuccess: (response: string) => void,
onFailure: (error: string) => void, onFailure: (error: string) => void,
onComplete: () => void onComplete: () => void,
requiresAuthentication = false
): void { ): void {
onPreExecute(); onPreExecute();
this._http this._http
.get<RaintreeResponse>(url, { .get<RaintreeResponse>(url, {
headers: this._jwt.injectToken(url), headers: requiresAuthentication
? this._jwt.injectToken(url)
: undefined,
}) })
.pipe(catchError(this._httpErrorHandler.intercept)) .pipe(catchError(this._httpErrorHandler.intercept))
.subscribe( .subscribe(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment