diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/author.js | 4 | ||||
-rw-r--r-- | server/models/pod.js | 5 | ||||
-rw-r--r-- | server/models/user.js | 25 |
3 files changed, 31 insertions, 3 deletions
diff --git a/server/models/author.js b/server/models/author.js index f036193c8..34b013097 100644 --- a/server/models/author.js +++ b/server/models/author.js | |||
@@ -84,7 +84,9 @@ function findOrCreateAuthor (name, podId, userId, transaction, callback) { | |||
84 | if (transaction) query.transaction = transaction | 84 | if (transaction) query.transaction = transaction |
85 | 85 | ||
86 | this.findOrCreate(query).asCallback(function (err, result) { | 86 | this.findOrCreate(query).asCallback(function (err, result) { |
87 | if (err) return callback(err) | ||
88 | |||
87 | // [ instance, wasCreated ] | 89 | // [ instance, wasCreated ] |
88 | return callback(err, result[0]) | 90 | return callback(null, result[0]) |
89 | }) | 91 | }) |
90 | } | 92 | } |
diff --git a/server/models/pod.js b/server/models/pod.js index 575ebbc61..79afb737a 100644 --- a/server/models/pod.js +++ b/server/models/pod.js | |||
@@ -35,7 +35,10 @@ module.exports = function (sequelize, DataTypes) { | |||
35 | }, | 35 | }, |
36 | email: { | 36 | email: { |
37 | type: DataTypes.STRING(400), | 37 | type: DataTypes.STRING(400), |
38 | allowNull: false | 38 | allowNull: false, |
39 | validate: { | ||
40 | isEmail: true | ||
41 | } | ||
39 | } | 42 | } |
40 | }, | 43 | }, |
41 | { | 44 | { |
diff --git a/server/models/user.js b/server/models/user.js index 6cb9eec3f..35a98dd6b 100644 --- a/server/models/user.js +++ b/server/models/user.js | |||
@@ -32,6 +32,13 @@ module.exports = function (sequelize, DataTypes) { | |||
32 | } | 32 | } |
33 | } | 33 | } |
34 | }, | 34 | }, |
35 | email: { | ||
36 | type: DataTypes.STRING, | ||
37 | allowNull: false, | ||
38 | validate: { | ||
39 | isEmail: true | ||
40 | } | ||
41 | }, | ||
35 | role: { | 42 | role: { |
36 | type: DataTypes.ENUM(values(constants.USER_ROLES)), | 43 | type: DataTypes.ENUM(values(constants.USER_ROLES)), |
37 | allowNull: false | 44 | allowNull: false |
@@ -42,6 +49,10 @@ module.exports = function (sequelize, DataTypes) { | |||
42 | { | 49 | { |
43 | fields: [ 'username' ], | 50 | fields: [ 'username' ], |
44 | unique: true | 51 | unique: true |
52 | }, | ||
53 | { | ||
54 | fields: [ 'email' ], | ||
55 | unique: true | ||
45 | } | 56 | } |
46 | ], | 57 | ], |
47 | classMethods: { | 58 | classMethods: { |
@@ -52,7 +63,8 @@ module.exports = function (sequelize, DataTypes) { | |||
52 | list, | 63 | list, |
53 | listForApi, | 64 | listForApi, |
54 | loadById, | 65 | loadById, |
55 | loadByUsername | 66 | loadByUsername, |
67 | loadByUsernameOrEmail | ||
56 | }, | 68 | }, |
57 | instanceMethods: { | 69 | instanceMethods: { |
58 | isPasswordMatch, | 70 | isPasswordMatch, |
@@ -88,6 +100,7 @@ function toFormatedJSON () { | |||
88 | return { | 100 | return { |
89 | id: this.id, | 101 | id: this.id, |
90 | username: this.username, | 102 | username: this.username, |
103 | email: this.email, | ||
91 | role: this.role, | 104 | role: this.role, |
92 | createdAt: this.createdAt | 105 | createdAt: this.createdAt |
93 | } | 106 | } |
@@ -151,3 +164,13 @@ function loadByUsername (username, callback) { | |||
151 | 164 | ||
152 | return this.findOne(query).asCallback(callback) | 165 | return this.findOne(query).asCallback(callback) |
153 | } | 166 | } |
167 | |||
168 | function loadByUsernameOrEmail (username, email, callback) { | ||
169 | const query = { | ||
170 | where: { | ||
171 | $or: [ { username }, { email } ] | ||
172 | } | ||
173 | } | ||
174 | |||
175 | return this.findOne(query).asCallback(callback) | ||
176 | } | ||