github.com/readium/readium-lcp-server@v0.0.0-20240101192032-6e95190e99f1/frontend/manage/app/user/user.service.ts (about) 1 import { Injectable } from '@angular/core'; 2 import { Http } from '@angular/http'; 3 4 import 'rxjs/add/operator/toPromise'; 5 import * as jsSHA from 'jssha'; 6 7 import { User } from './user'; 8 9 import { CrudService } from '../crud/crud.service'; 10 11 declare var Config: any; // this comes from the autogenerated config.js file 12 13 @Injectable() 14 export class UserService extends CrudService<User> { 15 constructor (http: Http) { 16 super(); 17 this.http = http; 18 this.baseUrl = Config.frontend.url + '/api/v1/users'; 19 } 20 21 decode(jsonObj: any): User { 22 return { 23 id: jsonObj.id, 24 uuid: jsonObj.uuid, 25 name: jsonObj.name, 26 email: jsonObj.email, 27 password: jsonObj.password, 28 clearPassword: null, 29 hint: jsonObj.hint 30 } 31 } 32 33 encode(obj: User): any { 34 let jsonObj = { 35 id: obj.id, 36 uuid: obj.uuid, 37 name: obj.name, 38 email: obj.email, 39 password: obj.password, 40 hint: obj.hint 41 }; 42 43 if (obj.clearPassword == null) { 44 // No password change 45 return jsonObj; 46 } 47 48 // Hash password 49 let jsSHAObject:jsSHA.jsSHA = new jsSHA("SHA-256", "TEXT"); 50 jsSHAObject.update(obj.clearPassword); 51 jsonObj['password'] = jsSHAObject.getHash("HEX"); 52 return jsonObj; 53 } 54 }