1234567891011121314151617181920212223242526272829303132333435363738394041 |
- var umDB = require('./umDB');
- var usersSchema = new umDB.mongoose.Schema({ account: String, pw: String, name: String });
- var usersModel = umDB.mongoose.model('users', usersSchema);
- var usersData = function(){};
- usersData.prototype.findUser = function(account, pw, controllerFun){
- usersModel.find({"account": account, "pw": pw}, function(err, data){
- if(data.length){
- controllerFun(0, data[0]);
- }
- else{
- controllerFun('用户名或密码错误!', 0);
- }
- })
- };
- usersData.prototype.checkAccount = function(account, controllerFun){
- usersModel.find({"account": account}, function(err, data){
- if(data.length){
- controllerFun(data[0]);
- }
- else{
- controllerFun(0);
- }
- })
- };
- usersData.prototype.addUser = function(account, pw, name, controllerFun){
- var user = new usersModel({account: account, pw: pw, name: name});
- user.save(function (err) {
- if (err) {
- controllerFun(err);
- } else {
- controllerFun(0);
- }
- });
- };
- module.exports = new usersData();
|