User profile information is now successfully saved and retrieved back on account profile page

This commit is contained in:
Sahat Yalkabov
2013-12-05 23:53:14 -05:00
parent 69f41c296a
commit 4d92ad9d16
3 changed files with 29 additions and 17 deletions

6
app.js
View File

@ -50,8 +50,10 @@ app.get('/logout', user.logout);
app.get('/signup', user.getSignup); app.get('/signup', user.getSignup);
app.post('/signup', user.postSignup); app.post('/signup', user.postSignup);
app.get('/account', passportConf.ensureAuthenticated, user.account); app.get('/account', passportConf.ensureAuthenticated, user.getAccount);
app.get('/admin', passportConf.ensureAuthenticated, passportConf.ensureAdmin(), user.getAdmin); app.post('/account/profile', passportConf.ensureAuthenticated, user.postAccountProfile);
app.post('/account/settings', passportConf.ensureAuthenticated, user.postAccountSettings);
app.get('/partials/:name', home.partials); app.get('/partials/:name', home.partials);
app.get('/api', api.apiBrowser); app.get('/api', api.apiBrowser);

View File

@ -5,7 +5,7 @@ var mongoose = require('mongoose'),
// Import models // Import models
var User = require('../models/User'); var User = require('../models/User');
exports.account = function(req, res) { exports.getAccount = function(req, res) {
res.render('account', { res.render('account', {
title: 'Account Management', title: 'Account Management',
user: req.user, user: req.user,
@ -13,6 +13,24 @@ exports.account = function(req, res) {
}); });
}; };
exports.postAccountProfile = function(req, res) {
User.findById(req.user.id, function(err, user) {
user.profile.name = req.body.name || '';
user.profile.email = req.body.email || '';
user.profile.location = req.body.location || '';
user.profile.website = req.body.website || '';
user.profile.picture = req.body.picture || '';
user.save(function(err) {
res.redirect('/account');
});
});
};
exports.postAccountSettings = function(req, res) {
console.log('okay!!');
};
/** /**
* GET /login * GET /login
*/ */

View File

@ -9,33 +9,25 @@ block content
a(href='#settings', data-toggle='tab') Settings a(href='#settings', data-toggle='tab') Settings
.tab-content .tab-content
#basic.tab-pane.fade.active.in #basic.tab-pane.fade.active.in
form.form-horizontal(role='form', method='POST') form.form-horizontal(action='/account/profile', method='POST')
.form-group .form-group
label.col-sm-2.control-label(for='name') Name label.col-sm-2.control-label(for='name') Name
.col-sm-4 .col-sm-4
input.form-control(type='text', name='name', id='name') input.form-control(type='text', name='name', id='name', value='#{user.profile.name}')
.form-group .form-group
label.col-sm-2.control-label(for='email') Email label.col-sm-2.control-label(for='email') Email
.col-sm-4 .col-sm-4
input.form-control(type='email', name='email', id='email') input.form-control(type='email', name='email', id='email', value='#{user.profile.email}')
.form-group .form-group
label.col-sm-2.control-label(for='location') Location label.col-sm-2.control-label(for='location') Location
.col-sm-4 .col-sm-4
input.form-control(type='text', name='location', id='location') input.form-control(type='text', name='location', id='location', value='#{user.profile.location}')
.form-group .form-group
label.col-sm-2.control-label(for='website') Website label.col-sm-2.control-label(for='website') Website
.col-sm-4 .col-sm-4
input.form-control(type='text', name='website', id='website') input.form-control(type='text', name='website', id='website', value='#{user.profile.website}')
.form-group .form-group
label.col-sm-2.control-label(for='twitter') Twitter label.col-sm-2.control-label(for='profilePicture') Profile Picture
.col-sm-4
input.form-control(type='text', name='twitter', id='twitter')
.form-group
label.col-sm-2.control-label(for='linkedin') LinkedIn URL
.col-sm-4
input.form-control(type='text', name='linkedin', id='linkedin')
.form-group
label.col-sm-2.control-label(for='profilePicture') Profile picture
.col-sm-8 .col-sm-8
.btn.btn-danger.google Use Google .btn.btn-danger.google Use Google
.btn.btn-primary.facebook Use Facebook .btn.btn-primary.facebook Use Facebook