Hooking up Angular to Profile.jade

This commit is contained in:
terakilobyte
2015-01-06 00:52:30 -05:00
parent be22449d25
commit 41a1bc37c3
4 changed files with 25 additions and 15 deletions

1
app.js
View File

@ -250,6 +250,7 @@ app.get(
);
app.all('/account', passportConf.isAuthenticated);
app.get('/account', userController.getAccount);
app.get('/account/api', userController.getAccountAngular);
app.post('/account/profile', userController.postUpdateProfile);
app.post('/account/password', userController.postUpdatePassword);
app.post('/account/delete', userController.postDeleteAccount);

View File

@ -145,12 +145,28 @@ exports.getAccount = function(req, res) {
title: 'Manage your Free Code Camp Account',
challenges: c,
ch: req.user.challengesHash,
moment: moment,
moment: moment
});
});
};
/**
* Angular API Call
*/
exports.getAccountAngular = function(req, res) {
Challenge.find({}, null, { sort: { challengeNumber: 1 } }, function(err, c) {
if (err) {
console.error('Challenge err: ', err);
next(err);
}
res.json({
user: req.user
});
});
};
/**
* GET /users/:username
* Public Profile page.

View File

@ -45,12 +45,9 @@ $(document).ready(function() {
var profileValidation = angular.module('profileValidation',[]);
profileValidation.controller('profileValidationController', ['$scope', '$http',
function($scope, $http) {
$http.get('/account').success(function(data) {
console.log('============');
console.log(data);
console.log('============');
$http.get('/account/api').success(function(data) {
$scope.user = data.user;
console.log($scope.user);
});
//$scope.user = user;
}
]);

View File

@ -8,19 +8,15 @@ block content
.form-group
label.col-sm-3.col-sm-offset-2.control-label(for='name') Name
.col-sm-4
input.form-control(type='text', name='name', id='name', value='#{user.profile.name}')
.form-group
label.col-sm-3.col-sm-offset-2.control-label(for='name') Name
.col-sm-4
input.form-control(type='text', placeholder='Name', name='name', ng-model='user.name', ng-minlength='3', ng-maxlength='20', required='required', ng-focus='ng-focus', id='name', value='{{user.name}}')
input.form-control(type='text', placeholder='Name', name='name', ng-model='user.profile.name', ng-minlength='3', ng-maxlength='20', required='required', ng-focus='ng-focus', id='name', value='{{user.profile.name}}')
.form-group
label.col-sm-3.col-sm-offset-2.control-label(for='username') Username (use letters, numbers, underscore) *
.col-sm-4
input.form-control(type='text', name='username', id='username', value='#{user.profile.username}')
input.form-control(type='text', name='username', id='username', ng-model='user.profile.username', value='{{user.profile.username}}')
.form-group
label.col-sm-3.col-sm-offset-2.control-label(for='email') Email *
.col-sm-4
input.form-control(type='email', name='email', id='email', value='#{user.email}')
input.form-control(type='email', name='email', id='email', ng-model='user.email', value= '{{user.email}}')
.form-group
label.col-sm-3.col-sm-offset-2.control-label(for='location') Location
.col-sm-4
@ -28,9 +24,9 @@ block content
.form-group
label.col-sm-3.col-sm-offset-2.control-label(for='email') Twitter Handle
.col-sm-4
input.form-control(type='text', name='twitterHandle', id='twitterHandle', ng-model="user.twitterHandle" value='#{user.profile.twitterHandle}')
input.form-control(type='text', name='twitterHandle', id='twitterHandle', ng-model="user.profile.twitterHandle" value='#{user.profile.twitterHandle}')
span
{{user.twitterHandle}}
{{user.profile.twitterHandle}}
.form-group
label.col-sm-3.col-sm-offset-2.control-label(for='email') Github Profile Link
.col-sm-4