Переглянути джерело

Fixed Show.vue with new role user property

theflametrooper 8 роки тому
батько
коміт
4a8384c9eb

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

@@ -176,7 +176,7 @@ module.exports = {
 					data: {
 						_id: account._id,
 						username: account.username,
-						admin: account.admin,
+						role: account.role,
 						email: account.email.address,
 						password: '',
 						createdAt: account.createdAt,

+ 2 - 4
backend/logic/io.js

@@ -100,11 +100,9 @@ module.exports = {
 							if (err2 && err2 !== true) {
 								socket.emit('ready', false);
 							} else if (userSession) {
-								db.models.user.findOne({_id: userSession.userId}, (err, user) => {
+								db.models.user.findOne({ _id: userSession.userId }, (err, user) => {
 									let role = 'default';
-									if (user) {
-										role = user.role;
-									}
+									if (user) role = user.role;
 									socket.emit('ready', true, role);
 								});
 							} else {

+ 4 - 4
frontend/components/User/Show.vue

@@ -5,8 +5,8 @@
 			<img class="avatar" src="https://avatars2.githubusercontent.com/u/11198912?v=3&s=460"/>
 			<h2 class="has-text-centered">@{{user.username}}</h2>
 			<div class="admin-functionality">
-				<a class="button is-small is-info is-outlined" @click="changeRank('admin')" v-if="!user.admin">Promote to Admin</a>
-				<a class="button is-small is-danger is-outlined" @click="changeRank('user')" v-else>Demote to User</a>
+				<a class="button is-small is-info is-outlined" @click="changeRank('admin')" v-if="user.role == 'default'">Promote to Admin</a>
+				<a class="button is-small is-danger is-outlined" @click="changeRank('default')" v-else>Demote to User</a>
 			</div>
 			<nav class="level">
 				<div class="level-item has-text-centered">
@@ -46,9 +46,9 @@
 		},
 		methods: {
 			changeRank(newRank) {
-				this.socket.emit('users.update', this.user._id, 'admin', ((newRank == 'admin') ? true : false), res => {
+				this.socket.emit('users.update', this.user._id, 'role', ((newRank == 'admin') ? 'admin' : 'default'), 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);
+					else this.user.role = newRank; Toast.methods.addToast(`User ${this.$route.params.username}'s rank has been changed to: ${newRank}`, 2000);
 				});
 			}
 		},

+ 1 - 1
frontend/main.js

@@ -17,10 +17,10 @@ let router = new VueRouter({ history: true });
 let _this = this;
 
 lofig.folder = '../config/default.json';
-
 lofig.get('socket.url', function(res) {
 	let socket = window.socket = io(window.location.protocol + '//' + res);
 	socket.on("ready", (status, role) => {
+		console.log(status, role)
 		auth.data(status, role);
 	});
 });