Browse Source

Added Promote/Demote buttons on /u/ route

theflametrooper 8 years ago
parent
commit
6f83e8ef59
2 changed files with 7 additions and 4 deletions
  1. 2 1
      backend/logic/actions/users.js
  2. 5 3
      frontend/components/User/Show.vue

+ 2 - 1
backend/logic/actions/users.js

@@ -174,6 +174,7 @@ module.exports = {
 				return cb({
 					status: 'success',
 					data: {
+						_id: account._id,
 						username: account.username,
 						admin: account.admin,
 						email: account.email.address,
@@ -210,7 +211,7 @@ module.exports = {
         db.models.user.findOne({ _id: user_id }, (err, user) => {
             if (err) throw err;
             else if (!user) cb({ status: 'error', message: 'Invalid User ID' });
-            else if (user[property] && user[property] !== value) {
+            else if (user[property] !== undefined && user[property] !== value) {
                 if (property == 'services.password.password') {
                     bcrypt.compare(user[property], value, (err, res) => {
                         if (err) throw err;

+ 5 - 3
frontend/components/User/Show.vue

@@ -46,8 +46,10 @@
 		},
 		methods: {
 			changeRank(newRank) {
-				console.log(rank);
-				Toast.methods.addToast(`User ${this.$route.params.username}'s rank has been changed to: ${rank}`, 2000);
+				this.socket.emit('users.update', this.user._id, 'admin', ((newRank == 'admin') ? true : false), res => {
+					if (res.status == 'error') Toast.methods.addToast(res.message, 2000);
+					else Toast.methods.addToast(`User ${this.$route.params.username}'s rank has been changed to: ${newRank}`, 2000);
+				});
 			}
 		},
 		ready: function() {
@@ -56,7 +58,7 @@
 				if (!!_this.$parent.socket) {
 					_this.socket = _this.$parent.socket;
 					_this.socket.emit('users.findByUsername', _this.$route.params.username, res => {
-						if (res.status == 'error') this.$router.go('/*');
+						if (res.status == 'error') this.$router.go('/404');
 						else _this.user = res.data; _this.isUser = true;
 					});
 					clearInterval(socketInterval);