aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar vantezzen <hello@vantezzen.io>2019-10-20 17:44:09 +0200
committerLibravatar vantezzen <hello@vantezzen.io>2019-10-20 17:44:09 +0200
commitf09ebd80b32ee1beac2bfc1de358de14f947bdbc (patch)
tree4c953014d54bcc896a191a877dd4512f8cec9bf2
parentAdd page to transfer user accounts (diff)
downloadferdium-server-f09ebd80b32ee1beac2bfc1de358de14f947bdbc.tar.gz
ferdium-server-f09ebd80b32ee1beac2bfc1de358de14f947bdbc.tar.zst
ferdium-server-f09ebd80b32ee1beac2bfc1de358de14f947bdbc.zip
Implement user settings
-rw-r--r--app/Controllers/Http/UserController.js24
-rw-r--r--database/migrations/1503250034279_user.js1
-rw-r--r--start/routes.js1
3 files changed, 26 insertions, 0 deletions
diff --git a/app/Controllers/Http/UserController.js b/app/Controllers/Http/UserController.js
index 1e67092..3f6103a 100644
--- a/app/Controllers/Http/UserController.js
+++ b/app/Controllers/Http/UserController.js
@@ -146,6 +146,30 @@ class UserController {
146 isSubscriptionOwner: true, 146 isSubscriptionOwner: true,
147 lastname: 'Franz', 147 lastname: 'Franz',
148 locale: 'en-US', 148 locale: 'en-US',
149 ...auth.user.settings || {},
150 });
151 }
152
153 async updateMe({
154 request,
155 response,
156 auth
157 }) {
158 let settings = auth.user.settings || {};
159 if (typeof settings === 'string') {
160 settings = JSON.parse(settings);
161 }
162
163 let newSettings = {
164 ...settings,
165 ...request.all(),
166 }
167
168 auth.user.settings = JSON.stringify(newSettings);
169 await auth.user.save();
170
171 return response.send({
172 status: 'success'
149 }); 173 });
150 } 174 }
151 175
diff --git a/database/migrations/1503250034279_user.js b/database/migrations/1503250034279_user.js
index 5010bec..77f3cee 100644
--- a/database/migrations/1503250034279_user.js
+++ b/database/migrations/1503250034279_user.js
@@ -9,6 +9,7 @@ class UserSchema extends Schema {
9 table.string('username', 80).notNullable(); 9 table.string('username', 80).notNullable();
10 table.string('email', 254).notNullable().unique(); 10 table.string('email', 254).notNullable().unique();
11 table.string('password', 60).notNullable(); 11 table.string('password', 60).notNullable();
12 table.json('settings');
12 table.timestamps(); 13 table.timestamps();
13 }); 14 });
14 } 15 }
diff --git a/start/routes.js b/start/routes.js
index 7243079..5c11f5a 100644
--- a/start/routes.js
+++ b/start/routes.js
@@ -26,6 +26,7 @@ Route.group(() => {
26 26
27 // User info 27 // User info
28 Route.get('me', 'UserController.me').middleware('auth'); 28 Route.get('me', 'UserController.me').middleware('auth');
29 Route.put('me', 'UserController.updateMe').middleware('auth');
29 30
30 // Service info 31 // Service info
31 Route.post('service', 'ServiceController.create').middleware('auth'); 32 Route.post('service', 'ServiceController.create').middleware('auth');