Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Binding doesn't work on some models possibly with HTTP POST

Open
#27 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
angular, javascript

Research direction

Start by reproducing the register HTTP POST using the shown $sailsBind bindings, then compare the socket updates received for the User and Task models. Inspect the User model associations and UserController.register flow shown in the issue. Done means the binding behavior is explained and User updates work consistently with Task updates, or the required configuration is documented.

Written by the indexing model from the issue text.

Description

This might be an issue with Sails, or my configuration.

However in my controller I am binding:

$sailsBind.bind("user", $scope)
$sailsBind.bind("task", $scope)

When I am using the register function on the controller updates are not being sent. I can see socket messages being pushed to the task object.

the register function is being called via HTTP POST instead of a socket call.

Task works, user does not.

User model:

var User = {
  // Enforce model schema in the case of schemaless databases
  schema: true,

  attributes: {
    groups: {
        collection: 'groups',
        via: 'members',
    required: true
    },
    username  : { type: 'string', unique: true, required: true },
  email     : { type: 'email',  unique: true, required: true },

  passports : { collection: 'Passport', via: 'user' }
    // Groups

  }
};

module.exports = User;

User controller:

/**
 * UserController
 *
 * @description :: Server-side logic for managing Users
 * @help        :: See http://links.sailsjs.org/docs/controllers
 */


module.exports = {

  session: function(req, res) {

    res.json({
      success: true
    });
  },


  //expose a method for angular to be able to see if we are logged in
  isLoggedIn: function(req,res){

    //TODO: make sure that only the clients with the right session get the broadcast
    //sails.sockets.broadcast("authNotification" , "authorized",{socketId: req.socket.id, user: req.user} );    

    res.json({sessionID: req.session.sessionID, roles: req.session.roles, user: req.user} );
    //res.json(req.isAuthenticated() ? {sessionID: req.sessionID, user: req.user} : 0);
  },
  //expose a method for angular to be able to see if we are logged in
  sayHi: function(req,res){
    sails.sockets.broadcast("authNotification" , "message", {message: "onLogin"} );  
    sails.sockets.broadcast("authNotification" , "message", {message: "hello3"} );    
    res.json({result:"sent"});
  },
  sendHello: function(req,res) {
    //req.sessionID
    sails.io.sockets.in('asdf').emit("eventName", {data:true});
    //sails.sockets.broadcast.to("asdf").emit('loggedOut', {loggedOff: 'true'});

    res.json({
        sessionid: req.sessionID,
        message: "sent"
    })

  },
  register: function(req,res){

    //associate group
    Groups.findOrCreate({
      groupName: 'user'
    }, {
      groupName: 'user',
      description: 'Generic user'
    }).exec(function createFindCB(err, userGroup) {
      //Check password for equality
      var password = req.param('password');
      var confirmation = req.param('confirmation');
      //TODO: enfore better passsword enforcement
      if(!password){
        res.json({err: { message: "You must enter a password" }});
      } else if (password == confirmation){
        var userObj = {
          username: req.param('username'),
          email: req.param('email'),
          groups: [userGroup.id]
        };

        //Create user
        User.create(userObj, function userCreated(err, user) {
          if (err) {
            res.json({
              err: err
            });
          } else {
            //Associate passport ( password )
            //TODO: include other authentication mechanisms
            Passport.create({
              protocol: 'local',
              password: password,
              user: user.id
            }, function (err, passport) {
              if (err){
                User.destroy(user.id, function deleteCB(deleteErr){
                  sails.log(deleteErr);
                });
                res.json({err:err});
                console.log(err);              
              } else {
                res.json({success: true});
              }
            });

          }
        });
      } else {
        res.json({err: { message: "Passwords do not match" }});
      }

    });

  }

};
Dominant language
JavaScript
Stars
135
Forks
23
PR merge metrics
No merged PRs in 30d

Getting set up

We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from diegopamio/angular-sails-bind

All issues in diegopamio/angular-sails-bind

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.