|
@@ -25,6 +25,7 @@ module.exports = function(crowi) {
|
|
|
username: { type: String },
|
|
username: { type: String },
|
|
|
email: { type: String, required: true },
|
|
email: { type: String, required: true },
|
|
|
password: String,
|
|
password: String,
|
|
|
|
|
+ apiToken: String,
|
|
|
status: { type: Number, required: true, default: STATUS_ACTIVE },
|
|
status: { type: Number, required: true, default: STATUS_ACTIVE },
|
|
|
createdAt: { type: Date, default: Date.now },
|
|
createdAt: { type: Date, default: Date.now },
|
|
|
admin: { type: Boolean, default: 0 }
|
|
admin: { type: Boolean, default: 0 }
|
|
@@ -58,6 +59,13 @@ module.exports = function(crowi) {
|
|
|
return hasher.digest('hex');
|
|
return hasher.digest('hex');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function generateApiToken (user) {
|
|
|
|
|
+ var hasher = crypto.createHash('sha256');
|
|
|
|
|
+ hasher.update((new Date).getTime() + user._id);
|
|
|
|
|
+
|
|
|
|
|
+ return hasher.digest('base64');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
userSchema.methods.isPasswordSet = function() {
|
|
userSchema.methods.isPasswordSet = function() {
|
|
|
if (this.password) {
|
|
if (this.password) {
|
|
|
return true;
|
|
return true;
|
|
@@ -96,6 +104,22 @@ module.exports = function(crowi) {
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ userSchema.methods.updateApiToken = function(callback) {
|
|
|
|
|
+ var self = this;
|
|
|
|
|
+
|
|
|
|
|
+ self.apiToken = generateApiToken(this);
|
|
|
|
|
+ return new Promise(function(resolve, reject) {
|
|
|
|
|
+ self.save(function(err, userData) {
|
|
|
|
|
+ if (err) {
|
|
|
|
|
+ return reject(err);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return resolve(userData);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
userSchema.methods.updateImage = function(image, callback) {
|
|
userSchema.methods.updateImage = function(image, callback) {
|
|
|
this.image = image;
|
|
this.image = image;
|
|
|
this.save(function(err, userData) {
|
|
this.save(function(err, userData) {
|