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.get('/account', passportConf.isAuthenticated, user.getAccount);
|
||||
app.post('/account/profile', passportConf.isAuthenticated, user.postAccountProfile);
|
||||
app.post('/account/settings', passportConf.isAuthenticated, user.postAccountSettings);
|
||||
app.post('/account/profile', passportConf.isAuthenticated, user.postAccountProfileTab);
|
||||
app.post('/account/settings', passportConf.isAuthenticated, user.postAccountSettingsTab);
|
||||
app.post('/account/delete', passportConf.isAuthenticated, user.postDeleteAccount);
|
||||
app.get('/account/unlink/:provider', passportConf.isAuthenticated, user.getOauthUnlink);
|
||||
|
||||
|
@ -5,6 +5,9 @@ var mongoose = require('mongoose'),
|
||||
// Import models
|
||||
var User = require('../models/User');
|
||||
|
||||
/**
|
||||
* GET /account
|
||||
*/
|
||||
exports.getAccount = function(req, res) {
|
||||
res.render('account', {
|
||||
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.profile.name = req.body.name || '';
|
||||
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) {
|
||||
console.log('okay!!');
|
||||
// TODO: change url on tab change in account.jade
|
||||
// Check if password matches confirm password
|
||||
|
||||
/**
|
||||
* POST /account#settings
|
||||
*/
|
||||
exports.postAccountSettingsTab = function(req, res) {
|
||||
if (req.body.password !== req.body.confirmPassword) {
|
||||
req.flash('messages', 'Passwords do not match');
|
||||
return res.redirect('/account');
|
||||
@ -48,14 +51,11 @@ exports.postAccountSettings = function(req, res) {
|
||||
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) {
|
||||
User.remove({ _id: req.user.id }, function(err) {
|
||||
req.logout();
|
||||
|
@ -8,7 +8,7 @@ block content
|
||||
|
||||
ul.nav.nav-tabs#myTab
|
||||
li.active
|
||||
a(href='#basic', data-toggle='tab') Basic Info
|
||||
a(href='#profile', data-toggle='tab') Profile
|
||||
li
|
||||
a(href='#settings', data-toggle='tab') Settings
|
||||
.tab-content
|
||||
|
@ -9,15 +9,10 @@ html
|
||||
|
||||
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/bootstrap.min.css', rel='stylesheet')
|
||||
//link(href='/css/themes/flat-ui.min.css', rel='stylesheet')
|
||||
link(href='/css/styles.css', rel='stylesheet')
|
||||
|
||||
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/bootstrap.js')
|
||||
script(src='/js/main.js')
|
||||
|
Reference in New Issue
Block a user