Work on account channels interface; Start work on /account/profile
This commit is contained in:
parent
5fe5dd440e
commit
ead38a9d35
5 changed files with 231 additions and 41 deletions
|
|
@ -167,15 +167,14 @@ function handleChangeEmail(req, res) {
|
|||
* Handles a GET request for /account/channels
|
||||
*/
|
||||
function handleAccountChannelPage(req, res) {
|
||||
res.send(500);
|
||||
return;
|
||||
logRequest(req);
|
||||
var loginName = false;
|
||||
if (req.cookies.auth) {
|
||||
loginName = req.cookies.auth.split(':')[0];
|
||||
}
|
||||
|
||||
if (loginName) {
|
||||
dbchannels.listUserChannels(loginName, function (err, channels) {
|
||||
db.channels.listUserChannels(loginName, function (err, channels) {
|
||||
sendJade(res, 'account-channels', {
|
||||
loggedIn: true,
|
||||
loginName: loginName,
|
||||
|
|
@ -194,8 +193,6 @@ function handleAccountChannelPage(req, res) {
|
|||
* Handles a POST request to modify a user's channels
|
||||
*/
|
||||
function handleAccountChannel(req, res) {
|
||||
res.send(500);
|
||||
return;
|
||||
logRequest(req);
|
||||
var action = req.body.action;
|
||||
switch(action) {
|
||||
|
|
@ -215,26 +212,162 @@ function handleAccountChannel(req, res) {
|
|||
* Handles a request to register a new channel
|
||||
*/
|
||||
function handleNewChannel(req, res) {
|
||||
res.send(500);
|
||||
logRequest(req);
|
||||
|
||||
var name = req.body.name;
|
||||
if (typeof name !== 'string') {
|
||||
res.send(400);
|
||||
return;
|
||||
}
|
||||
|
||||
var loginName = false;
|
||||
if (req.cookies.auth) {
|
||||
loginName = req.cookies.auth.split(':')[0];
|
||||
} else {
|
||||
sendJade(res, 'account-channels', {
|
||||
loggedIn: false,
|
||||
channels: []
|
||||
});
|
||||
return;
|
||||
}
|
||||
db.users.verifyAuth(req.cookies.auth, function (err, user) {
|
||||
if (err) {
|
||||
sendJade(res, 'account-channels', {
|
||||
loggedIn: false,
|
||||
channels: [],
|
||||
newChannelError: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
db.channels.register(name, user.name, function (err, channel) {
|
||||
db.channels.listUserChannels(loginName, function (err2, channels) {
|
||||
sendJade(res, 'account-channels', {
|
||||
loggedIn: true,
|
||||
loginName: loginName,
|
||||
channels: err2 ? [] : channels,
|
||||
newChannelError: err ? err : undefined
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a request to delete a new channel
|
||||
*/
|
||||
function handleDeleteChannel(req, res) {
|
||||
logRequest(req);
|
||||
|
||||
var name = req.body.name;
|
||||
if (typeof name !== 'string') {
|
||||
res.send(400);
|
||||
return;
|
||||
}
|
||||
|
||||
var loginName = false;
|
||||
if (req.cookies.auth) {
|
||||
loginName = req.cookies.auth.split(':')[0];
|
||||
} else {
|
||||
sendJade(res, 'account-channels', {
|
||||
loggedIn: false,
|
||||
channels: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
db.users.verifyAuth(req.cookies.auth, function (err, user) {
|
||||
if (err) {
|
||||
sendJade(res, 'account-channels', {
|
||||
loggedIn: false,
|
||||
channels: [],
|
||||
deleteChannelError: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
db.channels.lookup(name, function (err, channel) {
|
||||
if (channel.owner !== user.name && user.global_rank < 255) {
|
||||
db.channels.listUserChannels(loginName, function (err2, channels) {
|
||||
sendJade(res, 'account-channels', {
|
||||
loggedIn: true,
|
||||
loginName: loginName,
|
||||
channels: err2 ? [] : channels,
|
||||
deleteChannelError: 'You do not have permission to delete this channel'
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
db.channels.drop(name, function (err) {
|
||||
db.channels.listUserChannels(loginName, function (err2, channels) {
|
||||
sendJade(res, 'account-channels', {
|
||||
loggedIn: true,
|
||||
loginName: loginName,
|
||||
channels: err2 ? [] : channels,
|
||||
deleteChannelError: err ? err : undefined
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a GET request for /account/profile
|
||||
*/
|
||||
function handleAccountProfilePage(req, res) {
|
||||
logRequest(req);
|
||||
|
||||
var loginName = false;
|
||||
if (req.cookies.auth) {
|
||||
loginName = req.cookies.auth.split(':')[0];
|
||||
} else {
|
||||
sendJade(res, 'account-profile', {
|
||||
loggedIn: false,
|
||||
profileImage: '',
|
||||
profileText: ''
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
db.users.getProfile(loginName, function (err, profile) {
|
||||
if (err) {
|
||||
sendJade(res, 'account-profile', {
|
||||
loggedIn: true,
|
||||
loginName: loginName,
|
||||
profileError: err,
|
||||
profileImage: '',
|
||||
profileText: ''
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
sendJade(res, 'account-profile', {
|
||||
loggedIn: true,
|
||||
loginName: loginName,
|
||||
profileImage: profile.image,
|
||||
profileText: profile.text,
|
||||
profileError: false
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a POST request to edit a profile
|
||||
*/
|
||||
function handleAccountProfile(req, res) {
|
||||
res.send(500);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Initializes the module
|
||||
*
|
||||
* @param app - The Express server to initialize
|
||||
* Initialize the module
|
||||
*/
|
||||
init: function (app) {
|
||||
app.get('/account/edit', handleAccountEditPage);
|
||||
app.post('/account/edit', handleAccountEdit);
|
||||
app.get('/account/channels', handleAccountChannelPage);
|
||||
app.post('/account/channels', handleAccountChannel);
|
||||
app.get('/account/profile', handleAccountProfilePage);
|
||||
app.post('/account/profile', handleAccountProfile);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue