Implemented password verification
This commit is contained in:
parent
7f742dac63
commit
690fe5289f
@ -6,13 +6,24 @@
|
|||||||
<p class="text-md text-center text-gray-600 mb-6">Access your files quickly and securely</p>
|
<p class="text-md text-center text-gray-600 mb-6">Access your files quickly and securely</p>
|
||||||
<div class="bg-white shadow-lg rounded-lg p-6 flex flex-col items-center justify-center">
|
<div class="bg-white shadow-lg rounded-lg p-6 flex flex-col items-center justify-center">
|
||||||
<img class="w-56 mt-6 mb-6" src="./assets/cloud-arrow-down-solid.svg">
|
<img class="w-56 mt-6 mb-6" src="./assets/cloud-arrow-down-solid.svg">
|
||||||
<input type="text" class="input input-bordered text-center w-full max-w-md mb-6" placeholder="Enter download code/link" [(ngModel)]="inputFileId"/>
|
<input type="text" class="input input-bordered text-center w-full max-w-md mb-6" placeholder="Enter download code/link"
|
||||||
<input
|
[(ngModel)]="inputFileId"
|
||||||
*ngIf="downloadInfo && downloadInfo.passwordProtected && downloadInfo.downloadable"
|
(keydown.enter)="requestDownload()"/>
|
||||||
type="password" class="input input-bordered text-center w-full max-w-md mb-6" placeholder="Enter file password..." [(ngModel)]="filePassword"/>
|
|
||||||
|
|
||||||
|
<div class="mb-6 w-full flex flex-col items-center justify-center">
|
||||||
|
<input
|
||||||
|
*ngIf="downloadInfo && downloadInfo.passwordProtected && downloadInfo.downloadable"
|
||||||
|
[ngClass]="{'input-error': passwordWrong}"
|
||||||
|
type="password"
|
||||||
|
class="input input-bordered text-center w-full max-w-md"
|
||||||
|
placeholder="Enter file password..."
|
||||||
|
[(ngModel)]="filePassword"/>
|
||||||
|
<div class="label" *ngIf="passwordWrong">
|
||||||
|
<span class="label-text-alt text-red-500">Password wrong | Check capslock</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button class="btn btn-primary w-full max-w-md flex justify-center items-center mb-4" (click)="requestDownload()">
|
<button class="btn btn-primary w-full max-w-md flex justify-center items-center mb-4 mt-3" (click)="requestDownload()">
|
||||||
Download
|
Download
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
|
@ -2,7 +2,7 @@ import {Component, ElementRef, ViewChild} from '@angular/core';
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import {DevelopmentStore} from "../../store/DevelopmentStore";
|
import {DevelopmentStore} from "../../store/DevelopmentStore";
|
||||||
import {FormsModule} from "@angular/forms";
|
import {FormsModule} from "@angular/forms";
|
||||||
import {DecimalPipe, NgIf} from "@angular/common";
|
import {DecimalPipe, NgClass, NgIf} from "@angular/common";
|
||||||
import funfacts from "../../assets/funfacts";
|
import funfacts from "../../assets/funfacts";
|
||||||
import {RouterLink} from "@angular/router";
|
import {RouterLink} from "@angular/router";
|
||||||
|
|
||||||
@ -13,7 +13,8 @@ import {RouterLink} from "@angular/router";
|
|||||||
FormsModule,
|
FormsModule,
|
||||||
NgIf,
|
NgIf,
|
||||||
DecimalPipe,
|
DecimalPipe,
|
||||||
RouterLink
|
RouterLink,
|
||||||
|
NgClass
|
||||||
],
|
],
|
||||||
templateUrl: './download.component.html',
|
templateUrl: './download.component.html',
|
||||||
styleUrl: './download.component.scss'
|
styleUrl: './download.component.scss'
|
||||||
@ -22,7 +23,7 @@ export class DownloadComponent {
|
|||||||
|
|
||||||
@ViewChild('download_not_possible') download_not_possible: ElementRef<HTMLDialogElement> | undefined;
|
@ViewChild('download_not_possible') download_not_possible: ElementRef<HTMLDialogElement> | undefined;
|
||||||
|
|
||||||
inputFileId: string = "2402171";
|
inputFileId: string = "2402183";
|
||||||
fileId: string = "";
|
fileId: string = "";
|
||||||
filePassword: string = "";
|
filePassword: string = "";
|
||||||
fileName: string = "";
|
fileName: string = "";
|
||||||
@ -33,6 +34,7 @@ export class DownloadComponent {
|
|||||||
waitingForPassword: boolean = false;
|
waitingForPassword: boolean = false;
|
||||||
downloadProgress: number = 0;
|
downloadProgress: number = 0;
|
||||||
downloadDuration: string = "";
|
downloadDuration: string = "";
|
||||||
|
passwordWrong: boolean = false;
|
||||||
|
|
||||||
funfact: string = "";
|
funfact: string = "";
|
||||||
|
|
||||||
@ -44,6 +46,12 @@ export class DownloadComponent {
|
|||||||
|
|
||||||
requestDownload() {
|
requestDownload() {
|
||||||
|
|
||||||
|
if(this.waitingForPassword) {
|
||||||
|
console.log("Requesting download with password");
|
||||||
|
this.downloadFile();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log(this.inputFileId);
|
console.log(this.inputFileId);
|
||||||
this.fileId = this.inputFileId; // TODO: Implement link extraction logic
|
this.fileId = this.inputFileId; // TODO: Implement link extraction logic
|
||||||
|
|
||||||
@ -61,6 +69,7 @@ export class DownloadComponent {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(this.downloadInfo?.passwordProtected) {
|
else if(this.downloadInfo?.passwordProtected) {
|
||||||
|
this.waitingForPassword = true;
|
||||||
console.log("Password protected");
|
console.log("Password protected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,7 +123,7 @@ export class DownloadComponent {
|
|||||||
this.fileDownloadStarted = true;
|
this.fileDownloadStarted = true;
|
||||||
axios({
|
axios({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: this.developmentStore.getBaseUrl() + 'api/v1/download?fileId=' + this.fileId,
|
url: this.developmentStore.getBaseUrl() + 'api/v1/download?fileId=' + this.fileId + '&password=' + this.filePassword,
|
||||||
responseType: 'arraybuffer',
|
responseType: 'arraybuffer',
|
||||||
headers: {
|
headers: {
|
||||||
'Access-Control-Allow-Origin': '*', // Allow CORS
|
'Access-Control-Allow-Origin': '*', // Allow CORS
|
||||||
@ -163,9 +172,15 @@ export class DownloadComponent {
|
|||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
this.fileDownloadStarted = false;
|
||||||
|
this.wrongPassword();
|
||||||
console.error('Error during download request:', error);
|
console.error('Error during download request:', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private wrongPassword() {
|
||||||
|
this.passwordWrong = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
interface DownloadInfo {
|
interface DownloadInfo {
|
||||||
downloadable: boolean;
|
downloadable: boolean;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user