/**
* User.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs        :: http://sailsjs.org/#!documentation/models
*/

module.exports = {
  tableName: "sp_user",
  attributes: {
    username: {
      type: 'string',
      required: true,
      unique: true,
      primaryKey: true
    },
    password: {
      type: 'string',
      required: true,
      defaultsTo: 'loljoqpassu'
    },
    token: {
      type: 'string',
      required: true,
      unique: true
    },
    discussions: {
      collection: 'discussion',
      via: 'participants'
    }
  },


  /**
   * Create a new user using the provided inputs,
   * but encrypt the password first.
   *
   * @param  {Object}   inputs
   *                     • username {String}
   *                     • password {String}
   *                     • token {String}
   * @param  {Function} cb
   */

  register: function register(inputs, cb) {
    console.log(JSON.stringify(inputs));
    // Create a user
    User.create({
      username: inputs.username,
      // TODO: But encrypt the password first
      password: inputs.password,
      token: inputs.token
    }, function(err, user) {
      if(err) {
        sails.log(err)
        throw err;
      };
      cb();
    });
    //.exec(cb);
  },



  /**
   * Check validness of a login using the provided inputs.
   * But encrypt the password first.
   *
   * @param  {Object}   inputs
   *                     • username    {String}
   *                     • password {String}
   * @param  {Function} cb
   */

  attemptLogin: function (inputs, cb) {

    User.findOne({
      username: inputs.username,
      // TODO: But encrypt the password first
      password: inputs.password
    })
    .exec(cb);
  },

};

@@ -1785,11 +1785,287 @@
 ;%0A  %7D,%0A%0A
+  authUser: function( req, cb )%7B%0A    if(!req.param(%22username%22)) %7B%0A      return cb(%22Invalid Criteria%22);%0A    %7D%0A%0A    // Check if the user exists%0A    User.findOne(%7B%0A      where: %7Busername: req.param(%22username%22)%7D%0A    %7D, function (err, user)%7B%0A        cb(err, user);%0A    %7D);%0A%0A  %7D%0A%0A%0A%0A
 %7D;%0A

Add authUser method for User model