+ user.save(function (err, createdUser) {
+ if (err) return next(err)
+
+ return res.type('json').status(204).end()
+ })
+}
+
+function getUserInformation (req, res, next) {
+ User.loadByUsername(res.locals.oauth.token.user.username, function (err, user) {
+ if (err) return next(err)
+
+ return res.json(user.toFormatedJSON())
+ })
+}
+
+function listUsers (req, res, next) {
+ User.list(function (err, usersList) {
+ if (err) return next(err)
+
+ res.json(getFormatedUsers(usersList))
+ })
+}
+
+function removeUser (req, res, next) {
+ waterfall([
+ function getUser (callback) {
+ User.loadById(req.params.id, callback)
+ },
+
+ function getVideos (user, callback) {
+ Video.listOwnedByAuthor(user.username, function (err, videos) {
+ return callback(err, user, videos)
+ })
+ },
+
+ function removeVideosFromDB (user, videos, callback) {
+ each(videos, function (video, callbackEach) {
+ video.remove(callbackEach)
+ }, function (err) {
+ return callback(err, user, videos)
+ })
+ },
+
+ function sendInformationToFriends (user, videos, callback) {
+ videos.forEach(function (video) {
+ const params = {
+ name: video.name,
+ magnetUri: video.magnetUri
+ }