Added basic password service

Signed-off-by: Marius David Wieschollek's avatarMarius David Wieschollek <passwords.public@mdns.eu>
parent 3408a0f6
......@@ -57,6 +57,7 @@ import ServiceUnavailableError from "../Exception/Http/ServiceUnavailableError";
import GatewayTimeoutError from "../Exception/Http/GatewayTimeoutError";
import BaseClassLoader from "./BaseClassLoader";
import ModelService from "../Services/ModelService";
import PasswordService from "../Services/PasswordService";
export default class DefaultClassLoader extends BaseClassLoader {
......@@ -123,8 +124,9 @@ export default class DefaultClassLoader extends BaseClassLoader {
keychain : {
csev1: CSEv1Keychain
},
service : {
model: () => { return new ModelService(this); }
service : {
model : () => { return new ModelService(this); },
password: () => { return new PasswordService(this.getInstance('api')); }
},
cache : {
cache: Cache
......
export default class PasswordService {
/**
*
* @param {BaseApi} api
*/
constructor(api) {
this._api = api;
}
/**
*
* @param {Boolean} [numbers=null]
* @param {Boolean} [special=null]
* @param {Number} [strength=null]
* @returns {Promise<{password: String, words: String[], strength: Number, numbers: Boolean, special: Boolean}>}
*/
async generate(numbers = null, special = null, strength = null) {
let request = this._api.getRequest().setPath('1.0/service/password');
if(numbers !== null || special !== null || strength !== null) {
let data = {};
if(numbers !== null) data.numbers = numbers;
if(special !== null) data.special = special;
if(strength !== null && strength >= 0 && strength <= 4) data.strength = parseInt(strength);
request.setData(data);
}
let response = await request.send();
return response.getData();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment