Refactoring and code cleanup
This commit is contained in:
4
app.js
4
app.js
@ -55,8 +55,8 @@ app.get('/signup', user.getSignup);
|
|||||||
app.post('/signup', user.postSignup);
|
app.post('/signup', user.postSignup);
|
||||||
|
|
||||||
app.get('/account', passportConf.isAuthenticated, user.getAccount);
|
app.get('/account', passportConf.isAuthenticated, user.getAccount);
|
||||||
app.post('/account/profile', passportConf.isAuthenticated, user.postAccountProfile);
|
app.post('/account/profile', passportConf.isAuthenticated, user.postAccountProfileTab);
|
||||||
app.post('/account/settings', passportConf.isAuthenticated, user.postAccountSettings);
|
app.post('/account/settings', passportConf.isAuthenticated, user.postAccountSettingsTab);
|
||||||
app.post('/account/delete', passportConf.isAuthenticated, user.postDeleteAccount);
|
app.post('/account/delete', passportConf.isAuthenticated, user.postDeleteAccount);
|
||||||
app.get('/account/unlink/:provider', passportConf.isAuthenticated, user.getOauthUnlink);
|
app.get('/account/unlink/:provider', passportConf.isAuthenticated, user.getOauthUnlink);
|
||||||
|
|
||||||
|
@ -5,6 +5,9 @@ var mongoose = require('mongoose'),
|
|||||||
// Import models
|
// Import models
|
||||||
var User = require('../models/User');
|
var User = require('../models/User');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /account
|
||||||
|
*/
|
||||||
exports.getAccount = function(req, res) {
|
exports.getAccount = function(req, res) {
|
||||||
res.render('account', {
|
res.render('account', {
|
||||||
title: 'Account Management',
|
title: 'Account Management',
|
||||||
@ -13,8 +16,10 @@ exports.getAccount = function(req, res) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.postAccountProfile = function(req, res) {
|
/**
|
||||||
console.log(req.body.gender);
|
* POST /account#profile
|
||||||
|
*/
|
||||||
|
exports.postAccountProfileTab = function(req, res) {
|
||||||
User.findById(req.user.id, function(err, user) {
|
User.findById(req.user.id, function(err, user) {
|
||||||
user.profile.name = req.body.name || '';
|
user.profile.name = req.body.name || '';
|
||||||
user.profile.email = req.body.email || '';
|
user.profile.email = req.body.email || '';
|
||||||
@ -28,12 +33,10 @@ exports.postAccountProfile = function(req, res) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// todo: change to change postPassword
|
/**
|
||||||
exports.postAccountSettings = function(req, res) {
|
* POST /account#settings
|
||||||
console.log('okay!!');
|
*/
|
||||||
// TODO: change url on tab change in account.jade
|
exports.postAccountSettingsTab = function(req, res) {
|
||||||
// Check if password matches confirm password
|
|
||||||
|
|
||||||
if (req.body.password !== req.body.confirmPassword) {
|
if (req.body.password !== req.body.confirmPassword) {
|
||||||
req.flash('messages', 'Passwords do not match');
|
req.flash('messages', 'Passwords do not match');
|
||||||
return res.redirect('/account');
|
return res.redirect('/account');
|
||||||
@ -48,14 +51,11 @@ exports.postAccountSettings = function(req, res) {
|
|||||||
res.redirect('/account');
|
res.redirect('/account');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: add new field "Existing password"
|
|
||||||
// TODO: validate if all passwords are matching
|
|
||||||
//TODO: change user's password
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /account/delete
|
||||||
|
*/
|
||||||
exports.postDeleteAccount = function(req, res) {
|
exports.postDeleteAccount = function(req, res) {
|
||||||
User.remove({ _id: req.user.id }, function(err) {
|
User.remove({ _id: req.user.id }, function(err) {
|
||||||
req.logout();
|
req.logout();
|
||||||
|
@ -8,7 +8,7 @@ block content
|
|||||||
|
|
||||||
ul.nav.nav-tabs#myTab
|
ul.nav.nav-tabs#myTab
|
||||||
li.active
|
li.active
|
||||||
a(href='#basic', data-toggle='tab') Basic Info
|
a(href='#profile', data-toggle='tab') Profile
|
||||||
li
|
li
|
||||||
a(href='#settings', data-toggle='tab') Settings
|
a(href='#settings', data-toggle='tab') Settings
|
||||||
.tab-content
|
.tab-content
|
||||||
|
@ -9,15 +9,10 @@ html
|
|||||||
|
|
||||||
title #{title} - Starter Template for Bootstrap
|
title #{title} - Starter Template for Bootstrap
|
||||||
|
|
||||||
link(href='/css/lib/animate.css', rel='stylesheet')
|
|
||||||
link(href='/css/lib/jasny-bootstrap.css', rel='stylesheet')
|
|
||||||
link(href='/css/lib/font-awesome.min.css', rel='stylesheet')
|
link(href='/css/lib/font-awesome.min.css', rel='stylesheet')
|
||||||
//link(href='/css/lib/bootstrap.min.css', rel='stylesheet')
|
|
||||||
//link(href='/css/themes/flat-ui.min.css', rel='stylesheet')
|
|
||||||
link(href='/css/styles.css', rel='stylesheet')
|
link(href='/css/styles.css', rel='stylesheet')
|
||||||
|
|
||||||
script(src='/js/lib/jquery.js')
|
script(src='/js/lib/jquery.js')
|
||||||
script(src='/js/lib/jasny-bootstrap.js')
|
|
||||||
script(src='/js/lib/jquery.dataTables.min.js')
|
script(src='/js/lib/jquery.dataTables.min.js')
|
||||||
script(src='/js/lib/bootstrap.js')
|
script(src='/js/lib/bootstrap.js')
|
||||||
script(src='/js/main.js')
|
script(src='/js/main.js')
|
||||||
|
Reference in New Issue
Block a user