diff options
author | 2019-10-18 21:18:20 +0200 | |
---|---|---|
committer | 2019-10-18 21:18:20 +0200 | |
commit | dd1374a9d91780935ff360002b14560228cbae4b (patch) | |
tree | 13e59f0e5f0a2cdb776fed232969b6ccbb405cd4 /src/server | |
parent | Fix lint (diff) | |
download | ferdium-app-dd1374a9d91780935ff360002b14560228cbae4b.tar.gz ferdium-app-dd1374a9d91780935ff360002b14560228cbae4b.tar.zst ferdium-app-dd1374a9d91780935ff360002b14560228cbae4b.zip |
Allow import data from different servers
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/app/Controllers/Http/UserController.js | 18 | ||||
-rw-r--r-- | src/server/resources/views/import.edge | 3 |
2 files changed, 11 insertions, 10 deletions
diff --git a/src/server/app/Controllers/Http/UserController.js b/src/server/app/Controllers/Http/UserController.js index ee6a82702..be7ebe5fe 100644 --- a/src/server/app/Controllers/Http/UserController.js +++ b/src/server/app/Controllers/Http/UserController.js | |||
@@ -10,8 +10,8 @@ const fetch = require('node-fetch'); | |||
10 | const uuid = require('uuid/v4'); | 10 | const uuid = require('uuid/v4'); |
11 | const crypto = require('crypto'); | 11 | const crypto = require('crypto'); |
12 | 12 | ||
13 | const franzRequest = (route, method, auth) => new Promise((resolve, reject) => { | 13 | const apiRequest = (url, route, method, auth) => new Promise((resolve, reject) => { |
14 | const base = 'https://api.franzinfra.com/v1/'; | 14 | const base = url + '/v1/'; |
15 | const user = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Ferdi/5.3.0-beta.1 Chrome/69.0.3497.128 Electron/4.2.4 Safari/537.36'; | 15 | const user = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Ferdi/5.3.0-beta.1 Chrome/69.0.3497.128 Electron/4.2.4 Safari/537.36'; |
16 | 16 | ||
17 | try { | 17 | try { |
@@ -102,6 +102,7 @@ class UserController { | |||
102 | const validation = await validateAll(request.all(), { | 102 | const validation = await validateAll(request.all(), { |
103 | email: 'required|email', | 103 | email: 'required|email', |
104 | password: 'required', | 104 | password: 'required', |
105 | server: 'required', | ||
105 | }); | 106 | }); |
106 | if (validation.fails()) { | 107 | if (validation.fails()) { |
107 | let errorMessage = 'There was an error while trying to import your account:\n'; | 108 | let errorMessage = 'There was an error while trying to import your account:\n'; |
@@ -120,15 +121,12 @@ class UserController { | |||
120 | const { | 121 | const { |
121 | email, | 122 | email, |
122 | password, | 123 | password, |
124 | server, | ||
123 | } = request.all(); | 125 | } = request.all(); |
124 | 126 | ||
125 | const hashedPassword = crypto.createHash('sha256').update(password).digest('base64'); | 127 | const hashedPassword = crypto.createHash('sha256').update(password).digest('base64'); |
126 | 128 | ||
127 | if (Env.get('CONNECT_WITH_FRANZ') == 'false') { // eslint-disable-line eqeqeq | 129 | const base = server + '/v1/'; |
128 | return response.send('Your account has been created but due to this server\'s configuration, we could not import your Franz account data.\n\nIf you are the server owner, please set CONNECT_WITH_FRANZ to true to enable account imports.'); | ||
129 | } | ||
130 | |||
131 | const base = 'https://api.franzinfra.com/v1/'; | ||
132 | const userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Ferdi/5.3.0-beta.1 Chrome/69.0.3497.128 Electron/4.2.4 Safari/537.36'; | 130 | const userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Ferdi/5.3.0-beta.1 Chrome/69.0.3497.128 Electron/4.2.4 Safari/537.36'; |
133 | 131 | ||
134 | // Try to get an authentication token | 132 | // Try to get an authentication token |
@@ -162,7 +160,7 @@ class UserController { | |||
162 | // Get user information | 160 | // Get user information |
163 | let userInf = false; | 161 | let userInf = false; |
164 | try { | 162 | try { |
165 | userInf = await franzRequest('me', 'GET', token); | 163 | userInf = await apiRequest(server, 'me', 'GET', token); |
166 | } catch (e) { | 164 | } catch (e) { |
167 | const errorMessage = `Could not get your user info from Franz. Please check your credentials or try again later.\nError: ${e}`; | 165 | const errorMessage = `Could not get your user info from Franz. Please check your credentials or try again later.\nError: ${e}`; |
168 | return response.status(401).send(errorMessage); | 166 | return response.status(401).send(errorMessage); |
@@ -176,7 +174,7 @@ class UserController { | |||
176 | 174 | ||
177 | // Import services | 175 | // Import services |
178 | try { | 176 | try { |
179 | const services = await franzRequest('me/services', 'GET', token); | 177 | const services = await apiRequest(server, 'me/services', 'GET', token); |
180 | 178 | ||
181 | for (const service of services) { | 179 | for (const service of services) { |
182 | // Get new, unused uuid | 180 | // Get new, unused uuid |
@@ -201,7 +199,7 @@ class UserController { | |||
201 | 199 | ||
202 | // Import workspaces | 200 | // Import workspaces |
203 | try { | 201 | try { |
204 | const workspaces = await franzRequest('workspace', 'GET', token); | 202 | const workspaces = await apiRequest(server, 'workspace', 'GET', token); |
205 | 203 | ||
206 | for (const workspace of workspaces) { | 204 | for (const workspace of workspaces) { |
207 | let workspaceId; | 205 | let workspaceId; |
diff --git a/src/server/resources/views/import.edge b/src/server/resources/views/import.edge index f7b52b179..561021a0c 100644 --- a/src/server/resources/views/import.edge +++ b/src/server/resources/views/import.edge | |||
@@ -10,6 +10,9 @@ | |||
10 | <label for="password">Password</label><br /> | 10 | <label for="password">Password</label><br /> |
11 | <input type="password" name="password" placeholder="********" required><br /> | 11 | <input type="password" name="password" placeholder="********" required><br /> |
12 | 12 | ||
13 | <label for="server">API Server to import from</label><br /> | ||
14 | <input type="text" name="server" value="https://api.franzinfra.com" required><br /> | ||
15 | |||
13 | <button type="submit" id="submitbutton">Import Franz account</button> | 16 | <button type="submit" id="submitbutton">Import Franz account</button> |
14 | </form> | 17 | </form> |
15 | @endsection | 18 | @endsection |