From 695f02eb498dfafa63771e5b30d44e6821762e1e Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 7 May 2018 09:53:20 +0530 Subject: [PATCH] Add signup --- index.js | 21 +++++++++++++++++++-- model/document.js | 8 +++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 10a3804f..fea81439 100644 --- a/index.js +++ b/index.js @@ -218,10 +218,27 @@ module.exports = { token: res.token } - return; + return res; } - return await response.text(); + return response; + }, + + async signup(email, fullName, password) { + let response = await fetch(this.getServerURL() + '/api/signup', { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ email, fullName, password }) + }); + + if (response.status === 200) { + return await response.json(); + } + + return response; }, getServerURL() { diff --git a/model/document.js b/model/document.js index b00c4ac5..03798860 100644 --- a/model/document.js +++ b/model/document.js @@ -111,9 +111,15 @@ module.exports = class BaseDocument extends Observable { // set standard values on server-side only if (frappe.isServer) { let now = (new Date()).toISOString(); - if (!this.submitted) this.submitted = 0; + if (!this.submitted) { + this.submitted = 0; + } + if (!this.owner) { this.owner = frappe.session.user; + } + + if (!this.creation) { this.creation = now; }