mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-12 22:26:08 -04:00
Update to support optional email register and signin
This commit is contained in:
parent
52772829ce
commit
a73d9ce39e
14 changed files with 180 additions and 16 deletions
|
@ -3,6 +3,7 @@
|
|||
// external modules
|
||||
var md5 = require("blueimp-md5");
|
||||
var Sequelize = require("sequelize");
|
||||
var scrypt = require('scrypt');
|
||||
|
||||
// core
|
||||
var logger = require("../logger.js");
|
||||
|
@ -29,8 +30,30 @@ module.exports = function (sequelize, DataTypes) {
|
|||
},
|
||||
refreshToken: {
|
||||
type: DataTypes.STRING
|
||||
},
|
||||
email: {
|
||||
type: Sequelize.TEXT,
|
||||
validate: {
|
||||
isEmail: true
|
||||
}
|
||||
},
|
||||
password: {
|
||||
type: Sequelize.TEXT,
|
||||
set: function(value) {
|
||||
var hash = scrypt.kdfSync(value, scrypt.paramsSync(0.1)).toString("hex");
|
||||
this.setDataValue('password', hash);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
instanceMethods: {
|
||||
verifyPassword: function(attempt) {
|
||||
if (scrypt.verifyKdfSync(new Buffer(this.password, "hex"), attempt)) {
|
||||
return this;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
classMethods: {
|
||||
associate: function (models) {
|
||||
User.hasMany(models.Note, {
|
||||
|
@ -42,6 +65,9 @@ module.exports = function (sequelize, DataTypes) {
|
|||
constraints: false
|
||||
});
|
||||
},
|
||||
getProfile: function (user) {
|
||||
return user.profile ? User.parseProfile(user.profile) : (user.email ? User.parseProfileByEmail(user.email) : null);
|
||||
},
|
||||
parseProfile: function (profile) {
|
||||
try {
|
||||
var profile = JSON.parse(profile);
|
||||
|
@ -81,6 +107,13 @@ module.exports = function (sequelize, DataTypes) {
|
|||
break;
|
||||
}
|
||||
return photo;
|
||||
},
|
||||
parseProfileByEmail: function (email) {
|
||||
var photoUrl = 'https://www.gravatar.com/avatar/' + md5(email);
|
||||
return {
|
||||
name: email.substring(0, email.lastIndexOf("@")),
|
||||
photo: photoUrl += '?s=96'
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue