users_data.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var umDB = require('./umDB');
  2. var usersSchema = new umDB.mongoose.Schema({ account: String, pw: String, name: String });
  3. var usersModel = umDB.mongoose.model('users', usersSchema);
  4. var usersData = function(){};
  5. usersData.prototype.findUser = function(account, pw, controllerFun){
  6. usersModel.find({"account": account, "pw": pw}, function(err, data){
  7. if(data.length){
  8. controllerFun(0, data[0]);
  9. }
  10. else{
  11. controllerFun('用户名或密码错误!', 0);
  12. }
  13. })
  14. };
  15. usersData.prototype.checkAccount = function(account, controllerFun){
  16. usersModel.find({"account": account}, function(err, data){
  17. if(data.length){
  18. controllerFun(data[0]);
  19. }
  20. else{
  21. controllerFun(0);
  22. }
  23. })
  24. };
  25. usersData.prototype.addUser = function(account, pw, name, controllerFun){
  26. var user = new usersModel({account: account, pw: pw, name: name});
  27. user.save(function (err) {
  28. if (err) {
  29. controllerFun(err);
  30. } else {
  31. controllerFun(0);
  32. }
  33. });
  34. };
  35. module.exports = new usersData();