-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: move editable-text to proper folder * feat: add digital signatures * v0.19.14 * fix: export SignatureService * v0.19.15 * fix: export SignatureService from public_api * v0.19.16 * feat: add signature helpers * v0.19.17 * feat(signature): take now-timestamp * v0.19.18 * refactor(signature): don't require UserDetailService * v0.19.19 * feat(branch): add upper secondary check method * 0.19.20 * Revert "feat(branch): add upper secondary check method" This reverts commit fbf473f. * chore: prettier * build(deps): bump prettier * 0.19.21
- Loading branch information
1 parent
4714923
commit d2bf588
Showing
8 changed files
with
84 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...pp/editable-text/editable-text.service.ts → ...es/editable-text/editable-text.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Injectable } from "@angular/core"; | ||
import { | ||
SerializedSignature, | ||
SignatureMetadata, | ||
UserDetail, | ||
} from "@boklisten/bl-model"; | ||
import { UserDetailService } from "../../document-services/user-detail/user-detail.service"; | ||
import { BL_CONFIG } from "../../bl-connect/bl-config"; | ||
import { BlDocumentService } from "../../document/bl-document.service"; | ||
import { CachedDocumentService } from "../../document/cached-document.service"; | ||
|
||
@Injectable() | ||
export class SignatureService extends BlDocumentService<SerializedSignature> { | ||
constructor( | ||
private cachedDocumentService: CachedDocumentService, | ||
private _userDetailService: UserDetailService | ||
) { | ||
super(cachedDocumentService); | ||
this.setCollection(BL_CONFIG.collection.signature); | ||
} | ||
|
||
public base64EncodeImage(signatureImage: Buffer): string { | ||
return signatureImage.toString("base64"); | ||
} | ||
|
||
public async hasValidSignature( | ||
userDetail: UserDetail, | ||
now: Date | ||
): Promise<boolean> { | ||
if (userDetail.signatures.length === 0) { | ||
return false; | ||
} | ||
|
||
const latestSignature = await this.getById(userDetail.signatures[0]); | ||
if (this.isSignatureExpired(latestSignature, now)) { | ||
return false; | ||
} | ||
|
||
return ( | ||
this._userDetailService.isUnderage(userDetail, now) === | ||
latestSignature.signedByGuardian | ||
); | ||
} | ||
|
||
public isSignatureExpired( | ||
signature: SignatureMetadata, | ||
now: Date | ||
): boolean { | ||
if (!signature.creationTime) { | ||
return true; | ||
} | ||
const oldestAllowedSignatureTime = new Date( | ||
now.getFullYear(), | ||
now.getMonth() - SignatureMetadata.NUM_MONTHS_VALID, | ||
now.getDate() | ||
); | ||
return signature.creationTime < oldestAllowedSignatureTime; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters