{"action":"opened","issue":{"url":"https://api.github.com/repos/tarlepp/angular-sailsjs-boilerplate/issues/100","labels_url":"https://api.github.com/repos/tarlepp/angular-sailsjs-boilerplate/issues/100/labels{/name}","comments_url":"https://api.github.com/repos/tarlepp/angular-sailsjs-boilerplate/issues/100/comments","events_url":"https://api.github.com/repos/tarlepp/angular-sailsjs-boilerplate/issues/100/events","html_url":"https://github.com/tarlepp/angular-sailsjs-boilerplate/issues/100","id":113241613,"number":100,"title":"Creating a new (local) user and passport.","user":{"login":"Hanifb","id":3097453,"avatar_url":"https://avatars.githubusercontent.com/u/3097453?v=3","gravatar_id":"","url":"https://api.github.com/users/Hanifb","html_url":"https://github.com/Hanifb","followers_url":"https://api.github.com/users/Hanifb/followers","following_url":"https://api.github.com/users/Hanifb/following{/other_user}","gists_url":"https://api.github.com/users/Hanifb/gists{/gist_id}","starred_url":"https://api.github.com/users/Hanifb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hanifb/subscriptions","organizations_url":"https://api.github.com/users/Hanifb/orgs","repos_url":"https://api.github.com/users/Hanifb/repos","events_url":"https://api.github.com/users/Hanifb/events{/privacy}","received_events_url":"https://api.github.com/users/Hanifb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-25T18:21:45Z","updated_at":"2015-10-25T18:21:45Z","closed_at":null,"body":"So, i started to do a little digging while trying to get a grip about Facebook integration and found out that one main issue is that the boilerplate does not have any (sane) logic for creating a local user.\r\n\r\nThis is the intended logic for creating a local user, any user creation has to be made by an authenticated user with two steps.\r\n1. One creating the user with a POST to /User\r\n2. Do an /auth/local/connect request with a password\r\n\r\nNumber 1 is pretty straightforward, number 2 gets tricky, because the Passport.protocol.local.connect requires a User model to be attached to the request object. This is not done anywhere.\r\n\r\nOne way of creating this logic is adding a custom register method in AuthController, attach the newly created user to the request object and call the Passport service. But the Passport Service looks for params like :provider and :action, overriding these params with hardcode seems hacky.\r\n\r\nSo this is what i managed too cook up. Opinions? Worth making a PL on?\r\n\r\n    //Add this in the beginning of AuthController.js \r\n    var actionUtil = require('../../node_modules/sails/lib/hooks/blueprints/actionUtil');\r\n\r\n    register: function(req, res){\r\n\r\n        var data = actionUtil.parseValues(req);\r\n\r\n        User.create(data).exec(function(err, user){\r\n            if(err) return res.negotiate(err);\r\n            if(!user) return res.notFound(\"User not found\"); //This should never happen\r\n\r\n            req.user = user;\r\n            req.params.action = \"connect\";\r\n            sails.services['passport'].callback(req,res,function(err, user){\r\n                if(err) return res.negotiate(err);\r\n                res.ok(user);\r\n            });\r\n        });\r\n    },\r\n\r\nDont forget to add this in routes.js\r\n\r\n    'POST /auth/local/register': 'AuthController.register',"}}