mirror of
https://github.com/wassname/HackFlowy.git
synced 2026-07-30 11:50:41 +08:00
Auth- Added Back-end Logic
removed personal details
This commit is contained in:
+10
-27
@@ -1,29 +1,12 @@
|
||||
//(not being used yet)
|
||||
var mongoose = require('mongoose');
|
||||
|
||||
var crypto = require('crypto')
|
||||
var db = require('../lib/db');
|
||||
var UserSchema = new db.Schema({
|
||||
username : {type: String, unique: true}
|
||||
, password : String
|
||||
})
|
||||
var MyUser = db.mongoose.model('User', UserSchema);
|
||||
// Exports
|
||||
module.exports.addUser = addUser;
|
||||
// Add user to database
|
||||
function addUser(username, password, callback) {
|
||||
var instance = new MyUser();
|
||||
instance.username = username;
|
||||
instance.password = encryptPassword(password);
|
||||
instance.save(function (err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
}
|
||||
else {
|
||||
callback(null, instance);
|
||||
var userSchema = mongoose.Schema({
|
||||
google : {
|
||||
id : String,
|
||||
token : String,
|
||||
email : String,
|
||||
name : String
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function encryptPassword(plainText) {
|
||||
return crypto.createHash('md5').update(plainText).digest('hex');
|
||||
}
|
||||
});
|
||||
// create the model for users and expose it to our app
|
||||
module.exports = mongoose.model('User', userSchema);
|
||||
Reference in New Issue
Block a user