import { Entity } from "../entity/model/entity" ; import { DatabaseEntity } from "../entity/database-entity.decorator" ; import { DatabaseField } from "../entity/database-field.decorator" ; import * as CryptoJS from "crypto-js" ; /**
 * Entity representing a User object including password.
 *
 * Note that in addition to the User Entity there also is a "regular" CouchDB user with the same name and password
 * in the CouchDB _users database which is used for remote database authentication.
 */ @ DatabaseEntity ( "User" ) export class User extends Entity { /** username used for login and identification */ @ DatabaseField ( ) name : string ; /** settings for the mat-paginator for tables
     * pageSizeOptions is set in the corresponding html of the component,
     * pageSize is stored persistently in the database and
     * pageIndex is saved only temporarily for the session
     */ @ DatabaseField ( ) paginatorSettingsPageSize : any = { } ; public paginatorSettingsPageIndex : any = { } ; /** password for webdav account (encrypted) */ @ DatabaseField ( ) private cloudPasswordEnc : any ; /** username for webdav account */ @ DatabaseField ( ) public cloudUserName : string ; /** password for webdav account (plaintext, decrypted during runtime from user.cloudPasswordEnc, not written to db) */ public cloudPasswordDec : any ; /** base folder for webdav, all actions of the app will happen relative to this as the root folder */ @ DatabaseField ( ) public cloudBaseFolder : string = "/aam-digital/" ; param givenPassword return public decryptCloudPassword ( givenPassword ) { if ( ! this . cloudPasswordEnc ) { return ; } this . cloudPasswordDec = CryptoJS . AES . decrypt ( this . cloudPasswordEnc . toString ( ) , givenPassword ) . toString ( CryptoJS . enc . Utf8 ) ; return this . cloudPasswordDec ; } param blobPassword param givenPassword public setCloudPassword ( blobPassword , givenPassword ) { this . cloudPasswordDec = blobPassword ; this . cloudPasswordEnc = CryptoJS . AES . encrypt ( blobPassword , givenPassword ) . toString ( ) ; } toString ( ) { return this . name ; } }