daily pastebin goal
12%
SHARE
TWEET

sql

a guest Jan 25th, 2016 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var connection = require('../connection.js');
  2. // var collection = connection.get('users');
  3. var validator = require('validator');
  4. var sha1 = require('sha1');
  5.  
  6. function userServiceUpdate() {
  7. }
  8.  
  9. // userService.prototype.getUsers = function(callback) {
  10. //  var users = collection.find({});
  11. //  users.success(function(d) {
  12. //      console.log(d);
  13. //      var json = {
  14. //          users: d,
  15. //          response: "success"
  16. //      }
  17.  
  18. //      callback(json);
  19. //  });
  20. // }
  21.  
  22. userServiceUpdate.prototype.updateUser = function(subusername, subpassword, subemail, subfname, sublname, substudno, subgender, submajor, subyear, subsection, subcontactno, callback) {
  23.  
  24.     console.log("================= START userService updateUser ==================")
  25.  
  26.     var users;
  27.     email = validator.normalizeEmail(subemail);
  28.     valEmail = validator.isEmail(email);
  29.     valUsername = validator.isAlphanumeric(subusername)&&validator.isLength(subusername, 5, 15);
  30.     valPassword = validator.isLength(subpassword, 6, 30);
  31.  
  32.     if(valEmail&&valUsername&&valPassword) {
  33.         var params = [subusername, sha1(subpassword), subemail, subfname, sublname, substudno, subgender, submajor, subyear, subsection, subcontactno];
  34.         connection.query("UPDATE user (username, password, email, fname, lname, studno, gender, major, year, section, contactno) VALUES (?,?,?,?,?,?,?,?,?,?,?)", params, function(err, results) {
  35.             if (err) {
  36.                 console.log(err);
  37.                 callback(false);
  38.             } else {
  39.                 console.log(subusername + " Added to database");
  40.                 callback(true);
  41.             }
  42.         });
  43.     }
  44. }
  45.  
  46. module.exports = userServiceUpdate;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top