diff --git a/public/templates/footer.tpl b/public/templates/footer.tpl index 6d09ca3b16..dd3de05b00 100644 --- a/public/templates/footer.tpl +++ b/public/templates/footer.tpl @@ -17,7 +17,8 @@ latest_user = document.getElementById('latest_user'), active_users = document.getElementById('active_users'), user_label = document.getElementById('user_label'), - active_record = document.getElementById('active_record'); + active_record = document.getElementById('active_record'), + right_menu = document.getElementById('right-menu'); socket.emit('user.count', {}); socket.on('user.count', function(data) { @@ -44,14 +45,30 @@ }); socket.emit('api:user.get', { fields: ['username', 'picture'] }); socket.on('api:user.get', function(data) { - var gravatar = document.createElement('img'), - name = document.createElement('span'); + if (data.uid > 0) { + var gravatar = document.createElement('img'), + name = document.createElement('span') + logoutEl = document.createElement('li'); - name.innerHTML = data['username']; - gravatar.src = data['picture']; + logoutEl.innerHTML = 'Log out'; - user_label.appendChild(gravatar); - user_label.appendChild(name); + name.innerHTML = data['username']; + gravatar.src = data['picture']; + + user_label.innerHTML = ''; + user_label.appendChild(gravatar); + user_label.appendChild(name); + right_menu.appendChild(logoutEl); + } else { + var registerEl = document.createElement('li'), + loginEl = document.createElement('li'); + + registerEl.innerHTML = 'Register'; + loginEl.innerHTML = 'Login'; + + right_menu.appendChild(registerEl); + right_menu.appendChild(loginEl); + } }); }()); diff --git a/public/templates/header.tpl b/public/templates/header.tpl index a22c9e7e0a..1f517a7b4f 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -167,12 +167,12 @@ diff --git a/src/user.js b/src/user.js index 6be93a4e99..1610352477 100644 --- a/src/user.js +++ b/src/user.js @@ -10,7 +10,9 @@ var config = require('../config.js'), User.get = function(uid, fields) { if (uid > 0) { var keys = [], - returnData = {}, + returnData = { + uid: uid + }, removeEmail = false; if (!(fields instanceof Array)) fields = ['username', 'email'];