Browse files

Show errors for profile edits above the form, fixes #264

  • Loading branch information...
1 parent 306e614 commit 2dc81efeecd54653a498d9f3c2b5b8bda4748141 @robertkowalski committed Apr 14, 2013
Showing with 10 additions and 7 deletions.
  1. +6 −7 routes/profile-edit.js
  2. +4 −0 templates/profile-edit.ejs
View
13 routes/profile-edit.js
@@ -25,7 +25,7 @@ function profileEdit (req, res) {
function saveThenShow (data, req, res) {
if (!data.name) {
- return res.error(new Error('name is required'), 400)
+ return show(req, res, 'name is required')
}
// get the user's own profile
@@ -59,8 +59,7 @@ function saveThenShow (data, req, res) {
prof.roles = []
if (!(prof.email && prof.email.match(/^.+@.+\..+$/))) {
- var er = new Error('Email must be an email address')
- return res.error(er, 400)
+ return show(req, res, 'Email must be an email address')
}
var pu = '/_users/' + prof._id
@@ -87,7 +86,7 @@ function saveThenShow (data, req, res) {
}
// get the profile and show it on a form, maybe with a message
-function show (req, res) {
+function show (req, res, err) {
req.model.load('profile', req)
req.model.end(function (er, m) {
var profile = m.profile
@@ -101,9 +100,9 @@ function show (req, res) {
var locals = {
profile: profile,
fields: profile.fields,
-
- title: 'Edit profile'
+ title: 'Edit profile',
+ error: err
}
res.template("profile-edit.ejs", locals)
})
-}
+}
View
4 templates/profile-edit.ejs
@@ -3,6 +3,10 @@
<p><a href=/password>Change your Password</a></p>
+<% if (error) { %>
+ <p class="error"><%- error %></p>
+<% } %>
+
<form method=post action=/profile-edit>
<input type=hidden name=_id value="<%= profile._id %>">
<input type=hidden name=name value="<%= profile.name %>">

0 comments on commit 2dc81ef

Please sign in to comment.