mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +01:00 
			
		
		
		
	| @@ -1,7 +1,12 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| var async = require('async'), | ||||
| 	fs = require('fs'), | ||||
| 	nconf = require('nconf'), | ||||
| 	winston = require('winston'), | ||||
|  | ||||
| 	db = require('../../database'), | ||||
| 	user = require('../../user'), | ||||
| 	meta = require('../../meta'), | ||||
| 	helpers = require('../helpers'), | ||||
| 	accountHelpers = require('./helpers'); | ||||
| @@ -35,4 +40,46 @@ editController.get = function(req, res, callback) { | ||||
| 	}); | ||||
| }; | ||||
|  | ||||
|  | ||||
| editController.uploadPicture = function (req, res, next) { | ||||
| 	var userPhoto = req.files.files[0]; | ||||
|  | ||||
| 	var updateUid = req.uid; | ||||
|  | ||||
| 	async.waterfall([ | ||||
| 		function(next) { | ||||
| 			user.getUidByUserslug(req.params.userslug, next); | ||||
| 		}, | ||||
| 		function(uid, next) { | ||||
| 			if (parseInt(updateUid, 10) === parseInt(uid, 10)) { | ||||
| 				return next(); | ||||
| 			} | ||||
|  | ||||
| 			user.isAdministrator(req.uid, function(err, isAdmin) { | ||||
| 				if (err) { | ||||
| 					return next(err); | ||||
| 				} | ||||
|  | ||||
| 				if (!isAdmin) { | ||||
| 					return helpers.notAllowed(req, res); | ||||
| 				} | ||||
| 				updateUid = uid; | ||||
| 				next(); | ||||
| 			}); | ||||
| 		}, | ||||
| 		function(next) { | ||||
| 			user.uploadPicture(updateUid, userPhoto, next); | ||||
| 		} | ||||
| 	], function(err, image) { | ||||
| 		fs.unlink(userPhoto.path, function(err) { | ||||
| 			winston.error('unable to delete picture ' + userPhoto.path, err); | ||||
| 		}); | ||||
| 		if (err) { | ||||
| 			return next(err); | ||||
| 		} | ||||
|  | ||||
| 		res.json([{name: userPhoto.name, url: image.url.startsWith('http') ? image.url : nconf.get('relative_path') + image.url}]); | ||||
| 	}); | ||||
| }; | ||||
|  | ||||
| module.exports = editController; | ||||
		Reference in New Issue
	
	Block a user