Skip to content

Commit

Permalink
Fix error session is display
Browse files Browse the repository at this point in the history
  • Loading branch information
LuongXuanNhat committed Jan 24, 2024
1 parent 081dc14 commit f53ead3
Show file tree
Hide file tree
Showing 13 changed files with 394 additions and 295 deletions.
4 changes: 2 additions & 2 deletions docs/index.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

13 changes: 1 addition & 12 deletions src/app/account/account/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { FormBuilder, Validators} from '@angular/forms'
import { ToastrService} from 'ngx-toastr'
import { AuthService } from '../../../service/auth.service';
import { Router } from '@angular/router';
import { JwtHelperService } from '@auth0/angular-jwt';
import { UserService } from '../../../service/user.service';
import {MatDialog, MAT_DIALOG_DATA, MatDialogRef, MatDialogModule} from '@angular/material/dialog';
import { ForgetpassComponent } from '../../forgetpass/forgetpass.component';
Expand All @@ -18,7 +17,7 @@ import { DataService } from 'src/app/service/datashare/data.service';
})
export class LoginComponent {
constructor (private builder: FormBuilder, private toastr: ToastrService,private userService: UserService,
private service: AuthService, private router: Router,private jwtHelper: JwtHelperService
private service: AuthService, private router: Router
,private dialog: MatDialog, private sessionService: SessionService, private location: Location,
private dataService: DataService, ){
}
Expand All @@ -39,16 +38,6 @@ export class LoginComponent {
const resultObj = res.resultObj;
if(res.isSuccessed){
this.sessionService.setToken(resultObj);
const decodedToken = this.jwtHelper.decodeToken(res.resultObj);
const email = decodedToken['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress'];
const role = decodedToken['http://schemas.microsoft.com/ws/2008/06/identity/claims/role'];
const name = decodedToken['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname'];
const id = decodedToken['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier'];
// Lưu thông tin vào sessionStorage
this.sessionService.setEmail(email);
this.sessionService.setName(name);
this.sessionService.setRole(role);
this.sessionService.setUserId(id);
this.userService.GetImage().subscribe(
(data: any) => {
if(data !== ''){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export class ChangeemailComponent {
(res: any) => {
const resultObj = res.resultObj;
this.toastr.success('Vui lòng nhập mã xác nhận được gửi đến email của bạn','Thay đổi email thành công');
this.sessionService.setEmail(this.email);
this.sessionService.setName(this.email);
this.sessionService.setToken(resultObj);

this.emailcurrent = this.email;
Expand Down
73 changes: 42 additions & 31 deletions src/app/exam/createexam/createexam.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,91 +8,102 @@ import { PublicserviceService } from 'src/app/service/publicservice.service';
@Component({
selector: 'app-createexam',
templateUrl: './createexam.component.html',
styleUrls: ['./createexam.component.css']
styleUrls: ['./createexam.component.css'],
})
export class CreateexamComponent {
questionId: string = '';
selectedFile: File | null = null;
fileName: string = '';
progessing: boolean = false;
createExamForm = this._formBuilder.group({
Title: ['', [Validators.required, Validators.maxLength(255), Validators.minLength(10)]],
Description: ['',[Validators.required, Validators.maxLength(500)]],
Title: [
'',
[
Validators.required,
Validators.maxLength(255),
Validators.minLength(10),
],
],
Description: ['', [Validators.required, Validators.maxLength(500)]],
Document: [null, Validators.required],
Time: [null, Validators.required]
Time: [null, Validators.required],
});

constructor(private _formBuilder: FormBuilder, public service: PublicserviceService,
private router: Router, private toastr: ToastrService, private dialogRef: MatDialogRef<CreateexamComponent>,

) {


}
constructor(
private _formBuilder: FormBuilder,
public service: PublicserviceService,
private router: Router,
private toastr: ToastrService,
private dialogRef: MatDialogRef<CreateexamComponent>
) {}
toggleProgressing(): void {
this.fileName = '';
setTimeout(() => {
this.progessing = true;
}, 1000)
}, 1000);
}
onFileSelected(input: any): void {
const file = input?.files[0];
if (file && this.isValidFileType(file)) {
if(this.checkSize(file)){
if (this.checkSize(file)) {
this.progessing = false;
return;
}


this.createExamForm.get('Document')?.setValue(file);
this.progessing = false;
this.fileName = file.name;
} else {
this.progessing = false;
this.selectedFile = null;
this.toastr.warning('Vui lòng chọn đúng file: PDF hoặc DOCX');
this.toastr.warning('Vui lòng chọn đúng file: DOCX');
}
}
onFileInputBlur(): void {
this.progessing = false;
this.progessing = false;
}
private isValidFileType(file: File): boolean {
const allowedTypes = ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'];
const allowedTypes = [
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
];

return allowedTypes.includes(file.type);
}
CreateExam(){
CreateExam() {
const formData = new FormData();
const createExam = this.createExamForm;
var time = createExam.get('Time')?.value;

formData.append('Title', createExam.get('Title')?.value?.trim() || '');
formData.append('Description', createExam.get('Description')?.value?.trim() || '');
formData.append(
'Description',
createExam.get('Description')?.value?.trim() || ''
);
formData.append('File', createExam.get('Document')?.value || '');
formData.append('WorkTime', time || '30');

this.service.CreateExam(formData).subscribe(
(data: any) => {
if(data.isSuccessed){
if (data.isSuccessed) {
this.dialogRef.close();
this.toastr.success("Tạo bài thi thành công");
this.toastr.success('Tạo bài thi thành công');
} else {
this.toastr.error("Lỗi: " + data.message);
this.toastr.error('Lỗi: ' + data.message);
}
}, (error: any) => {
this.toastr.error("Lỗi: "+ error);
},
(error: any) => {
this.toastr.error('Lỗi: ' + error);
}
)
);
}
checkSize(file: any):boolean {
const fileSize = file.size;
const maxSize = 8 * 1024 * 1024;
checkSize(file: any): boolean {
const fileSize = file.size;
const maxSize = 8 * 1024 * 1024;

if (fileSize > maxSize) {
this.toastr.warning('Kích thước file không được vượt quá 8MB.');
return true;
}
}
return false;
}

}
4 changes: 2 additions & 2 deletions src/app/exam/examdetail/examdetail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
</div>
<div>
<div style="text-align: center;">
<h5>
<h1>
{{ exam.title }}
</h5>
</h1>
</div>
<div class="mt-1">
<span class="use-space">
Expand Down
Loading

0 comments on commit f53ead3

Please sign in to comment.