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.post('/signup', user.postSignup);
app.get('/account', passportConf.ensureAuthenticated, user.account);
app.get('/admin', passportConf.ensureAuthenticated, passportConf.ensureAdmin(), user.getAdmin);
app.get('/account', passportConf.ensureAuthenticated, user.getAccount);
app.post('/account/profile', passportConf.ensureAuthenticated, user.postAccountProfile);
app.post('/account/settings', passportConf.ensureAuthenticated, user.postAccountSettings);
app.get('/partials/:name', home.partials);
app.get('/api', api.apiBrowser);

View File

@ -5,7 +5,7 @@ var mongoose = require('mongoose'),
// Import models
var User = require('../models/User');
exports.account = function(req, res) {
exports.getAccount = function(req, res) {
res.render('account', {
title: 'Account Management',
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
*/

View File

@ -9,33 +9,25 @@ block content
a(href='#settings', data-toggle='tab') Settings
.tab-content
#basic.tab-pane.fade.active.in
form.form-horizontal(role='form', method='POST')
form.form-horizontal(action='/account/profile', method='POST')
.form-group
label.col-sm-2.control-label(for='name') Name
.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
label.col-sm-2.control-label(for='email') Email
.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
label.col-sm-2.control-label(for='location') Location
.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
label.col-sm-2.control-label(for='website') Website
.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
label.col-sm-2.control-label(for='twitter') Twitter
.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
label.col-sm-2.control-label(for='profilePicture') Profile Picture
.col-sm-8
.btn.btn-danger.google Use Google
.btn.btn-primary.facebook Use Facebook