river-of-ebooks/api/controllers/UserController.js

40 lines
888 B
JavaScript
Raw Normal View History

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) {
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) {
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
}