@semapps/auth 0.4.0-alpha.0 → 0.4.0-alpha.4

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 CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@semapps/auth",
3
- "version": "0.4.0-alpha.0",
3
+ "version": "0.4.0-alpha.4",
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.0",
9
- "@semapps/triplestore": "0.4.0-alpha.0",
8
+ "@semapps/mime-types": "0.4.0-alpha.4",
9
+ "@semapps/triplestore": "0.4.0-alpha.4",
10
10
  "bcrypt": "^5.0.1",
11
11
  "express-session": "^1.17.0",
12
12
  "jsonwebtoken": "^8.5.1",
@@ -22,5 +22,5 @@
22
22
  "publishConfig": {
23
23
  "access": "public"
24
24
  },
25
- "gitHead": "1c0962ddc0bc571bcbdd4af58efc72a2569889ef"
25
+ "gitHead": "2ba923a2a0799a03a99cbe9af67f0a1b3bdda139"
26
26
  }
@@ -54,11 +54,10 @@ module.exports = {
54
54
  async verify(ctx) {
55
55
  const { username, password } = ctx.params;
56
56
 
57
- const accounts = await this._find(ctx, {
58
- query: {
59
- username
60
- }
61
- });
57
+ // If the username includes a @, assume it is an email
58
+ const query = username.includes('@') ? { email: username } : { username };
59
+
60
+ const accounts = await this._find(ctx, { query });
62
61
 
63
62
  if (accounts.length > 0) {
64
63
  const passwordMatch = await this.comparePassword(password, accounts[0].hashedPassword);
@@ -100,7 +99,7 @@ module.exports = {
100
99
  methods: {
101
100
  async isValidUsername(ctx, username) {
102
101
  // Ensure the username has no space or special characters
103
- if (!/^[a-zA-Z0-9\-_.]+$/.exec(username)) {
102
+ if (!/^[a-z0-9\-_.]+$/.exec(username)) {
104
103
  throw new Error('username.invalid');
105
104
  }
106
105
 
@@ -10,11 +10,15 @@ module.exports = {
10
10
 
11
11
  for (let user of results['ldp:contains']) {
12
12
  if (user[emailPredicate]) {
13
- await ctx.call('auth.account.create', {
14
- email: user[emailPredicate],
15
- username: user[usernamePredicate],
16
- webId: user.id
17
- });
13
+ try {
14
+ await ctx.call('auth.account.create', {
15
+ email: user[emailPredicate],
16
+ username: user[usernamePredicate],
17
+ webId: user.id
18
+ });
19
+ } catch (e) {
20
+ console.log(`Unable to create account for user ${user.id}. Error message: ${e.message}`);
21
+ }
18
22
  } else {
19
23
  console.log('No email found for user ' + user.id);
20
24
  }