Permalink
Browse files

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

  • Loading branch information...
1 parent 306e614 commit 632a5981756884c6eb144a638dc188727d13d53a @robertkowalski committed Apr 14, 2013
Showing with 11 additions and 8 deletions.
  1. +7 −8 routes/profile-edit.js
  2. +4 −0 templates/profile-edit.ejs
View
@@ -15,7 +15,7 @@ function profileEdit (req, res) {
case 'HEAD':
case 'GET':
- return show(req, res)
+ return show(null, req, res)
default:
return res.error(405)
@@ -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('name is required', req, res)
}
// 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('Email must be an email address', req, res)
}
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 (err, req, res) {
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)
})
-}
+}
@@ -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 632a598

Please sign in to comment.