2018-11-02 00:21:36 +00:00
|
|
|
/**
|
|
|
|
* UserController
|
|
|
|
*
|
|
|
|
* @description :: Server-side logic for managing Users
|
|
|
|
* @help :: See http://links.sailsjs.org/docs/controllers
|
|
|
|
*/
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
create: async function (req, res, next) {
|
2018-11-07 20:06:36 +00:00
|
|
|
const passportHelper = await sails.helpers.passport()
|
2018-11-12 22:12:16 +00:00
|
|
|
passportHelper.protocols.local.register(req.body, function (err, user) {
|
2018-11-20 00:22:41 +00:00
|
|
|
if (err) {
|
|
|
|
return res.status(500).json({
|
|
|
|
error: err.toString()
|
|
|
|
})
|
|
|
|
}
|
2018-11-07 20:06:36 +00:00
|
|
|
res.json(user)
|
|
|
|
})
|
2018-11-02 00:21:36 +00:00
|
|
|
},
|
|
|
|
|
2019-02-04 21:08:45 +00:00
|
|
|
edit: async function (req, res, next) {
|
2018-11-07 20:06:36 +00:00
|
|
|
const passportHelper = await sails.helpers.passport()
|
2018-11-12 22:12:16 +00:00
|
|
|
passportHelper.protocols.local.update(req.body, function (err, user) {
|
2018-11-20 00:22:41 +00:00
|
|
|
if (err) {
|
|
|
|
return res.status(500).json({
|
|
|
|
error: err.toString()
|
|
|
|
})
|
|
|
|
}
|
2018-11-07 20:06:36 +00:00
|
|
|
res.json(user)
|
|
|
|
})
|
2018-11-02 00:21:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
me: function (req, res) {
|
2018-11-07 20:06:36 +00:00
|
|
|
res.json(req.user)
|
2018-11-02 00:21:36 +00:00
|
|
|
}
|
2018-11-07 20:06:36 +00:00
|
|
|
}
|