aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/user.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-02-18 09:29:59 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-02-18 09:29:59 +0100
commitad4a8a1cca1049f600ebcdce9260c1021cd821a5 (patch)
treeca8ffba899b024d56d1bd7846f61aecae0821c82 /server/models/user.js
parent5d67f289df4a68e35ad7e0af3c601c7db0dc7586 (diff)
downloadPeerTube-ad4a8a1cca1049f600ebcdce9260c1021cd821a5.tar.gz
PeerTube-ad4a8a1cca1049f600ebcdce9260c1021cd821a5.tar.zst
PeerTube-ad4a8a1cca1049f600ebcdce9260c1021cd821a5.zip
Add email to users
Diffstat (limited to 'server/models/user.js')
-rw-r--r--server/models/user.js25
1 files changed, 24 insertions, 1 deletions
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
168function loadByUsernameOrEmail (username, email, callback) {
169 const query = {
170 where: {
171 $or: [ { username }, { email } ]
172 }
173 }
174
175 return this.findOne(query).asCallback(callback)
176}