Skip to content

Commit

Permalink
made awesome changes
Browse files Browse the repository at this point in the history
  • Loading branch information
abarnhard committed Sep 3, 2014
1 parent fb540d3 commit 42e5cf8
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 16 deletions.
14 changes: 14 additions & 0 deletions app/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports.login = function(req, res){

exports.logout = function(req, res){
req.logout();
req.flash('notice', 'See you later');
res.redirect('/');
};

Expand All @@ -25,3 +26,16 @@ exports.create = function(req, res){
});
};

exports.profile = function(req, res){
res.render('users/show-profile');
};

exports.edit = function(req, res){
res.render('users/edit-profile');
};

exports.update = function(req, res){
User.update(req.user, req.body, function(){
res.redirect('/profile');
})
};
9 changes: 3 additions & 6 deletions app/lib/security.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
'use strict';

exports.locals = function(req, res, next){
res.locals.user = req.user;
res.locals.user = req.user;
res.locals.flash = {};

var keys = Object.keys(req.session.flash || {});
res.locals.flash = {};
keys.forEach(function(key){
res.locals.flash[key] = [];
req.session.flash[key].forEach(function(msg){
res.locals.flash[key].push(req.flash(key));
});
res.locals.flash[key] = req.flash(key);
});

next();
Expand Down
22 changes: 20 additions & 2 deletions app/models/user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

var bcrypt = require('bcrypt'),
Mongo = require('mongodb');
Mongo = require('mongodb'),
_ = require('underscore-contrib');

function User(){
}
Expand All @@ -12,7 +13,11 @@ Object.defineProperty(User, 'collection', {

User.findById = function(id, cb){
var _id = Mongo.ObjectID(id);
User.collection.findOne({_id:_id}, cb);
User.collection.findOne({_id:_id}, function(err, obj){
var user = Object.create(User.prototype);
user = _.extend(user, obj);
cb(err, user);
});
};

User.register = function(o, cb){
Expand All @@ -32,5 +37,18 @@ User.localAuthenticate = function(email, password, cb){
});
};

User.update = function(user, data, cb){
// console.log('***Post Body:', data);
Object.keys(data).forEach(function(key){
data[key] = data[key].trim();
if(data[key]){
user[key] = data[key];
}
});
// console.log('*** Updated User:', user);
User.collection.save(user, cb);
};


module.exports = User;

3 changes: 3 additions & 0 deletions app/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module.exports = function(app, express){

app.use(security.bounce);
app.delete('/logout', users.logout);
app.get('/profile', users.profile);
app.get('/profile/edit', users.edit);
app.put('/profile', users.update);

console.log('Express: Routes Loaded');
};
Expand Down
2 changes: 1 addition & 1 deletion app/static/css/style.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
body{background-image:url(/img/bg/vichy/vichy.png)}
body{background-image:url(/img/bg/vichy/vichy.png)}.photo{height:350px;width:350px;background-size:cover}
5 changes: 5 additions & 0 deletions app/static/css/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ body{
background-image: url(/img/bg/vichy/vichy.png);
}

.photo {
height: 350px;
width: 350px;
background-size: cover;
}
12 changes: 6 additions & 6 deletions app/views/shared/flash.jade
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
- if(flash.error)
each error in flash.error || []
.alert.alert-danger.alert-dismissible(role='alert')
button.close(type="button", data-dismiss="alert")
span(aria-hidden="true") ×
span.sr-only Close
strong Warning!  
span= flash.error
- if(flash.notice)
span= error
each notice in flash.notice || []
.alert.alert-info.alert-dismissible(role='alert')
button.close(type="button", data-dismiss="alert")
span(aria-hidden="true") ×
span.sr-only Close
strong Notice!  
span= flash.notice
- if(flash.success)
span= notice
each success in flash.success || []
.alert.alert-success.alert-dismissible(role='alert')
button.close(type="button", data-dismiss="alert")
span(aria-hidden="true") ×
span.sr-only Close
strong Success!  
span= flash.success
span= success
2 changes: 1 addition & 1 deletion app/views/shared/nav.jade
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
.collapse.navbar-collapse#bs-navbar-collapse
ul.nav.navbar-nav.navbar-right
if user
li: a.fa.fa-space-shuttle(href='/profile')   Profile
li
form.navbar-form(method='post', action='/logout')
.form-group
input(type='hidden', name='_method', value='delete')
button.btn.btn-danger= user.email
else
//- li: a(href='/register'): i.fa.fa-user.fa-2x   Register
li: a.fa.fa-user.fa-2x(href='/register')   Register
li: a.fa.fa-rocket.fa-2x(href='/login')   Login

20 changes: 20 additions & 0 deletions app/views/users/edit-profile.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
extends ../shared/template
block content
h2 Edit Profile
.row
.col-xs-6
form(role='form', method='post', action='/profile')
input(type='hidden', name='_method', value='put')
.form-group
label(for='email') Email
input.form-control#email(type='email', name='email', value=user.email)
.form-group
label(for='photo') Photo
input.form-control#photo(type='text', name='photo', value=user.photo, placeholder='http://somepic.jpg')
.form-group
label(for='age') Age
input.form-control#age(type='text', name='age', value=user.age)
button.btn.btn-primary(type='submit') Submit
.col-xs-6

block scripts
28 changes: 28 additions & 0 deletions app/views/users/show-profile.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
extends ../shared/template
block content
h2 Profile
.panel.panel-default
.panel-body
.row
.col-xs-6
h3= user.name
.col-xs-6
h5: a(href='/profile/edit') Update Profile
.row
.col-xs-6
table.table.table-bordered
tbody
tr
td Email
td= user.email
tr
td Age
td= user.age
.col-xs-6
.row
.col-xs-12
if user.photo
.photo(style='background-image:url(#{user.photo});')

block scripts

0 comments on commit 42e5cf8

Please sign in to comment.