Skip to content

Commit

Permalink
updated profile form; reordered files
Browse files Browse the repository at this point in the history
  • Loading branch information
smithy545 committed Jul 21, 2016
1 parent 4d89d55 commit 71a0da0
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 31 deletions.
4 changes: 4 additions & 0 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,8 @@ a {
.reu-search-list li {
background-color: rgba(0,0,0,0.1);
padding: 10px;
}

a.topbar-name {
float: right;
}
3 changes: 2 additions & 1 deletion routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var Application = require('../models/application');
var apps = express.Router();

apps.get('/', function(req, res) {
//console.log(req.user);
var ctx = {
user: req.user,
tb_highlighted: 'apps',
Expand All @@ -18,7 +19,7 @@ apps.get('/', function(req, res) {
}, function(err, apps) {
if(err) throw err;
ctx.applications = apps;
return res.render('application', ctx);
return res.render('application/view', ctx);
});
});
});
Expand Down
3 changes: 2 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ router.post('/sign-up', passport.authenticate('local-signup', {

// process the login form
router.post('/login', passport.authenticate('local-login', {
successRedirect : '/profile', // redirect to the secure profile section
successRedirect : '/home', // redirect to the secure profile section
failureRedirect : '/login', // redirect back to the signup page if there is an error
failureFlash : true // allow flash messages
}));
Expand All @@ -35,6 +35,7 @@ router.use(isLoggedIn);
/* GET home page. */
router.get('/home', function(req, res) {
var ctx = {
user: req.user,
tb_highlighted: "dashboard",
};

Expand Down
42 changes: 28 additions & 14 deletions routes/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,56 @@ profile.get('/', function(req, res) {
user: req.user,
tb_highlighted: 'profile',
};
res.render('profile', ctx);
res.render('profile/edit', ctx);
});

profile.get('/edit', function(req, res) {
var ctx = {
user: req.user,
tb_highlighted: 'profile',
};
res.render('edit-profile', ctx);
res.render('profile/edit', ctx);
});

profile.post('/edit', function(req, res) {
var ctx = {
user: req.user,
tb_highlighted: 'profile',
};
if(req.body.email != req.user.local.email) {
if(validator.isEmail(req.body.email)) {
User.findByIdAndUpdate(req.user._id, { $set: { 'local.email': req.body.email }}, function (err, user) {
if (err) throw err;
});
} else {
ctx.flash = { type: 'invalid', message: 'Invalid email' };
return res.render('edit-profile', ctx);

var form = req.body;
User.findById(req.user._id, function(err, user) {
if(err) {
console.log(err);
ctx.flash = { type: 'invalid', message: 'User lookup error'};
return res.render('profile/edit', ctx);
}

if(form.email && form.email != req.user.local.email) {
if(validator.isEmail(form.email)) {
user.local.email = form.email;
} else {
ctx.flash = { type: 'invalid', message: 'Invalid email' };
return res.render('edit-profile', ctx);
}
} if(form.first_name) {
user.profile.first_name = form.first_name;
} if(form.last_name) {
user.profile.last_name = form.last_name;
}
}

ctx.flash = { type: 'success', message: "Profile updated successfully!" };
res.render('profile', ctx);
user.save();
ctx.flash = { type: 'success', message: "Profile updated successfully!" };
res.render('profile/edit', ctx);
});
});

profile.get('/setup', function(req, res) {
var ctx = {
user: req.user,
tb_highlighted: 'profile',
};
res.render('setup-profile', ctx);
res.render('profile/setup', ctx);
});


Expand Down
6 changes: 3 additions & 3 deletions routes/reu.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ reu.get('/', function(req, res) {
user: req.user,
tb_highlighted: 'reu',
};
res.render('reu', ctx);
res.render('reu/search', ctx);
});

reu.post('/search', function(req, res) {
Expand All @@ -30,10 +30,10 @@ reu.post('/search', function(req, res) {
if(err) {
console.log(err);
ctx.results = [];
return res.render('reu', ctx);
return res.render('reu/search', ctx);
}
ctx.results = reus;
return res.render('reu', ctx);
return res.render('reu/search', ctx);
});
});

Expand Down
8 changes: 5 additions & 3 deletions views/application.jade → views/application/view.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends layout
extends ../layout

block title
title Applications
Expand All @@ -11,6 +11,8 @@ block content
- } else {
ul.application-list
each app in applications
li
p= app
- if(app.status != "unsubmitted"){
li
p= app
- }
- }
2 changes: 1 addition & 1 deletion views/home.jade
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ block title
block content
ul.application-list
- if(applications.length == 0) {
p You have no current applications
p You have no submitted applications
a(href="/reu") Click here to search for new Research Experience opportunites
- } else {
ul.application-list
Expand Down
3 changes: 2 additions & 1 deletion views/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ html
a(href="/reu" id="reu") REUs
ul(class="nav navbar-nav navbar-right")
li
//.topbar-name= user.profile.first_name + " " + user.profile.last_name
a(href="/logout") Logout
div.container.main-outer
div.row.main-inner
Expand All @@ -36,7 +37,7 @@ html
script(src="/javascripts/bootstrap.min.js")
script(src="/javascripts/init.js")
script.
var highlighted = $("##{tb_highlighted}");
var highlighted = $("#{tb_highlighted}");
highlighted.attr("class", "tb-highlighted");

block script
20 changes: 16 additions & 4 deletions views/edit-profile.jade → views/profile/edit.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends layout
extends ../layout

block title
title Profile
Expand All @@ -23,9 +23,22 @@ block content
=flash.message
- }
- }

a.btn.btn-primary(href="https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=77tgqz6flgej2j&redirect_uri=http%3A%2F%2Freu-apply.com%2Fauth%2Flinkedin%2Fcallback&state=0928354") Update from LinkedIn

br
br

div.content-container(id="personal")
p personal stuff ;)
form(method="post")
fieldset.form-group
label(for="editFirstName") First Name
input.form-control(id="editFirstName" name="first_name" type="text" value=user.profile.first_name)
fieldset.form-group
label(for="editLastName") Last Name
input.form-control(id="editLastName" name="last_name" type="text" value=user.profile.last_name)
button.btn.btn-primary(type="submit") Save


div.content-container(id="education" hidden)
p academic stuff
Expand All @@ -39,5 +52,4 @@ block content
label(for="editEmail") Email
input.form-control(id="editEmail" name="email" type="email" value="#{user.local.email}")
button.btn.btn-primary(type="submit") Save
br
a.btn.btn-primary(href="https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=77tgqz6flgej2j&redirect_uri=http%3A%2F%2Freu-apply.com%2Fauth%2Flinkedin%2Fcallback&state=0928354") Update from LinkedIn
br
2 changes: 1 addition & 1 deletion views/setup-profile.jade → views/profile/setup.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends layout
extends ../layout

block content
p You can grab from linkedIn
Expand Down
2 changes: 1 addition & 1 deletion views/profile.jade → views/profile/view.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends layout
extends ../layout

block title
title Profile
Expand Down
2 changes: 1 addition & 1 deletion views/reu.jade → views/reu/search.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends layout
extends ../layout

block title
title REU
Expand Down

0 comments on commit 71a0da0

Please sign in to comment.