@semapps/auth 0.4.0-alpha.31 → 0.4.0-alpha.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/services/account.js +39 -0
- package/services/auth.local.js +14 -3
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@semapps/auth",
|
3
|
-
"version": "0.4.0-alpha.
|
3
|
+
"version": "0.4.0-alpha.32",
|
4
4
|
"description": "Authentification module for SemApps",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"author": "Virtual Assembly",
|
7
7
|
"dependencies": {
|
8
|
-
"@semapps/mime-types": "0.4.0-alpha.
|
9
|
-
"@semapps/triplestore": "0.4.0-alpha.
|
8
|
+
"@semapps/mime-types": "0.4.0-alpha.32",
|
9
|
+
"@semapps/triplestore": "0.4.0-alpha.32",
|
10
10
|
"bcrypt": "^5.0.1",
|
11
11
|
"express-session": "^1.17.0",
|
12
12
|
"jsonwebtoken": "^8.5.1",
|
@@ -24,5 +24,5 @@
|
|
24
24
|
"publishConfig": {
|
25
25
|
"access": "public"
|
26
26
|
},
|
27
|
-
"gitHead": "
|
27
|
+
"gitHead": "67a882b414a80501533025843d2982a7da0afac2"
|
28
28
|
}
|
package/services/account.js
CHANGED
@@ -134,6 +134,45 @@ module.exports = {
|
|
134
134
|
});
|
135
135
|
|
136
136
|
return resetPasswordToken;
|
137
|
+
},
|
138
|
+
async findSettingsByWebId(ctx) {
|
139
|
+
const { webId } = ctx.meta;
|
140
|
+
const account = await ctx.call('auth.account.findByWebId', { webId });
|
141
|
+
|
142
|
+
return {
|
143
|
+
email: account['email'],
|
144
|
+
preferredLocale: account['preferredLocale']
|
145
|
+
};
|
146
|
+
},
|
147
|
+
async updateAccountSettings(ctx) {
|
148
|
+
const { currentPassword, email, newPassword } = ctx.params;
|
149
|
+
const { webId } = ctx.meta;
|
150
|
+
const account = await ctx.call('auth.account.findByWebId', { webId });
|
151
|
+
const passwordMatch = await this.comparePassword(currentPassword, account.hashedPassword);
|
152
|
+
let params = {};
|
153
|
+
|
154
|
+
if (!passwordMatch) {
|
155
|
+
throw new Error('auth.account.invalid_password');
|
156
|
+
}
|
157
|
+
|
158
|
+
if (newPassword) {
|
159
|
+
const hashedPassword = await this.hashPassword(newPassword);
|
160
|
+
params = { ...params, hashedPassword };
|
161
|
+
}
|
162
|
+
|
163
|
+
if (email !== account['email']) {
|
164
|
+
const existing = await ctx.call('auth.account.findByEmail', { email });
|
165
|
+
if (existing) {
|
166
|
+
throw new Error('email.already.exists');
|
167
|
+
}
|
168
|
+
|
169
|
+
params = { ...params, email };
|
170
|
+
}
|
171
|
+
|
172
|
+
return await this._update(ctx, {
|
173
|
+
'@id': account['@id'],
|
174
|
+
...params
|
175
|
+
});
|
137
176
|
}
|
138
177
|
},
|
139
178
|
methods: {
|
package/services/auth.local.js
CHANGED
@@ -149,11 +149,22 @@ const AuthLocalService = {
|
|
149
149
|
}
|
150
150
|
};
|
151
151
|
|
152
|
+
const accountSettingsRoute = {
|
153
|
+
path: '/auth/account',
|
154
|
+
aliases: {
|
155
|
+
'GET /': 'auth.account.findSettingsByWebId',
|
156
|
+
'POST /': 'auth.account.updateAccountSettings'
|
157
|
+
},
|
158
|
+
authorization: true
|
159
|
+
};
|
160
|
+
|
161
|
+
const routes = [loginRoute, resetPasswordRoute, setNewPasswordRoute, accountSettingsRoute];
|
162
|
+
|
152
163
|
if (this.settings.registrationAllowed) {
|
153
|
-
return [
|
154
|
-
} else {
|
155
|
-
return [loginRoute, resetPasswordRoute, setNewPasswordRoute];
|
164
|
+
return [...routes, signupRoute];
|
156
165
|
}
|
166
|
+
|
167
|
+
return routes;
|
157
168
|
}
|
158
169
|
}
|
159
170
|
};
|