diff options
author | Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com> | 2021-07-05 19:47:47 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-05 19:47:47 +0530 |
commit | 96938cd6dd10e77e96d4ab34b6f64a349254d98d (patch) | |
tree | 68c9f814980e5cab5614d2c2816330a406749899 /app/Controllers/Http/UserController.js | |
parent | Change main license holder to Ferdi and remove one existing in docker directory (diff) | |
parent | Bump set-getter from 0.1.0 to 0.1.1 (diff) | |
download | ferdium-server-96938cd6dd10e77e96d4ab34b6f64a349254d98d.tar.gz ferdium-server-96938cd6dd10e77e96d4ab34b6f64a349254d98d.tar.zst ferdium-server-96938cd6dd10e77e96d4ab34b6f64a349254d98d.zip |
Merge branch 'master' into master
Diffstat (limited to 'app/Controllers/Http/UserController.js')
-rw-r--r-- | app/Controllers/Http/UserController.js | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/app/Controllers/Http/UserController.js b/app/Controllers/Http/UserController.js index e367d99..0d768a9 100644 --- a/app/Controllers/Http/UserController.js +++ b/app/Controllers/Http/UserController.js | |||
@@ -48,9 +48,11 @@ class UserController { | |||
48 | // Validate user input | 48 | // Validate user input |
49 | const validation = await validateAll(request.all(), { | 49 | const validation = await validateAll(request.all(), { |
50 | firstname: 'required', | 50 | firstname: 'required', |
51 | lastname: 'required', | ||
51 | email: 'required|email|unique:users,email', | 52 | email: 'required|email|unique:users,email', |
52 | password: 'required', | 53 | password: 'required', |
53 | }); | 54 | }); |
55 | |||
54 | if (validation.fails()) { | 56 | if (validation.fails()) { |
55 | return response.status(401).send({ | 57 | return response.status(401).send({ |
56 | message: 'Invalid POST arguments', | 58 | message: 'Invalid POST arguments', |
@@ -59,7 +61,7 @@ class UserController { | |||
59 | }); | 61 | }); |
60 | } | 62 | } |
61 | 63 | ||
62 | const data = request.only(['firstname', 'email', 'password']); | 64 | const data = request.only(['firstname', 'lastname', 'email', 'password']); |
63 | 65 | ||
64 | // Create user in DB | 66 | // Create user in DB |
65 | let user; | 67 | let user; |
@@ -68,6 +70,7 @@ class UserController { | |||
68 | email: data.email, | 70 | email: data.email, |
69 | password: data.password, | 71 | password: data.password, |
70 | username: data.firstname, | 72 | username: data.firstname, |
73 | lastname: data.lastname, | ||
71 | }); | 74 | }); |
72 | } catch (e) { | 75 | } catch (e) { |
73 | return response.status(401).send({ | 76 | return response.status(401).send({ |
@@ -149,13 +152,13 @@ class UserController { | |||
149 | email: auth.user.email, | 152 | email: auth.user.email, |
150 | emailValidated: true, | 153 | emailValidated: true, |
151 | features: {}, | 154 | features: {}, |
152 | firstname: 'Franz', | 155 | firstname: auth.user.username, |
153 | id: '82c1cf9d-ab58-4da2-b55e-aaa41d2142d8', | 156 | id: '82c1cf9d-ab58-4da2-b55e-aaa41d2142d8', |
154 | isPremium: true, | 157 | isPremium: true, |
155 | isSubscriptionOwner: true, | 158 | isSubscriptionOwner: true, |
156 | lastname: 'Franz', | 159 | lastname: auth.user.lastname, |
157 | locale: 'en-US', | 160 | locale: 'en-US', |
158 | ...settings || {}, | 161 | ...settings || {}, |
159 | }); | 162 | }); |
160 | } | 163 | } |
161 | 164 | ||
@@ -174,6 +177,7 @@ class UserController { | |||
174 | ...request.all(), | 177 | ...request.all(), |
175 | }; | 178 | }; |
176 | 179 | ||
180 | // eslint-disable-next-line no-param-reassign | ||
177 | auth.user.settings = JSON.stringify(newSettings); | 181 | auth.user.settings = JSON.stringify(newSettings); |
178 | await auth.user.save(); | 182 | await auth.user.save(); |
179 | 183 | ||
@@ -185,13 +189,13 @@ class UserController { | |||
185 | email: auth.user.email, | 189 | email: auth.user.email, |
186 | emailValidated: true, | 190 | emailValidated: true, |
187 | features: {}, | 191 | features: {}, |
188 | firstname: 'Franz', | 192 | firstname: auth.user.username, |
189 | id: '82c1cf9d-ab58-4da2-b55e-aaa41d2142d8', | 193 | id: '82c1cf9d-ab58-4da2-b55e-aaa41d2142d8', |
190 | isPremium: true, | 194 | isPremium: true, |
191 | isSubscriptionOwner: true, | 195 | isSubscriptionOwner: true, |
192 | lastname: 'Franz', | 196 | lastname: auth.user.lastname, |
193 | locale: 'en-US', | 197 | locale: 'en-US', |
194 | ...newSettings || {}, | 198 | ...newSettings || {}, |
195 | }, | 199 | }, |
196 | status: [ | 200 | status: [ |
197 | 'data-updated', | 201 | 'data-updated', |
@@ -246,6 +250,7 @@ class UserController { | |||
246 | email, | 250 | email, |
247 | password: hashedPassword, | 251 | password: hashedPassword, |
248 | username: 'Franz', | 252 | username: 'Franz', |
253 | lastname: 'Franz', | ||
249 | }); | 254 | }); |
250 | 255 | ||
251 | 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.'); | 256 | 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.'); |
@@ -258,12 +263,19 @@ class UserController { | |||
258 | let token; | 263 | let token; |
259 | try { | 264 | try { |
260 | const basicToken = btoa(`${email}:${hashedPassword}`); | 265 | const basicToken = btoa(`${email}:${hashedPassword}`); |
266 | const loginBody = { | ||
267 | isZendeskLogin: false, | ||
268 | }; | ||
261 | 269 | ||
262 | const rawResponse = await fetch(`${base}auth/login`, { | 270 | const rawResponse = await fetch(`${base}auth/login`, { |
263 | method: 'POST', | 271 | method: 'POST', |
272 | body: JSON.stringify(loginBody), | ||
264 | headers: { | 273 | headers: { |
265 | Authorization: `Basic ${basicToken}`, | 274 | Authorization: `Basic ${basicToken}`, |
266 | 'User-Agent': userAgent, | 275 | 'User-Agent': userAgent, |
276 | 'Content-Type': 'application/json', | ||
277 | accept: '*/*', | ||
278 | 'x-franz-source': 'Web', | ||
267 | }, | 279 | }, |
268 | }); | 280 | }); |
269 | const content = await rawResponse.json(); | 281 | const content = await rawResponse.json(); |
@@ -301,6 +313,7 @@ class UserController { | |||
301 | email: userInf.email, | 313 | email: userInf.email, |
302 | password: hashedPassword, | 314 | password: hashedPassword, |
303 | username: userInf.firstname, | 315 | username: userInf.firstname, |
316 | lastname: userInf.lastname, | ||
304 | }); | 317 | }); |
305 | } catch (e) { | 318 | } catch (e) { |
306 | const errorMessage = `Could not create your user in our system.\nError: ${e}`; | 319 | const errorMessage = `Could not create your user in our system.\nError: ${e}`; |