Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Better messaging around failed logins

  • Loading branch information...
commit 20461674b56b9babb8b66f44183167d7747dc4c6 1 parent 981e9c6
@isaacs isaacs authored
Showing with 11 additions and 5 deletions.
  1. +6 −4 routes/login.js
  2. +5 −1 templates/login.ejs
View
10 routes/login.js
@@ -30,17 +30,19 @@ function login (req, res) {
function handleForm (req, res) {
req.on('form', function (data) {
if (!data.name || !data.password) {
- return res.error(new Error('bad login'), 400)
+ var er = new Error('Name or password not provided')
+ return res.error(er, 400, 'login.ejs')
}
req.couch.login(data, function (er, cr, couchSession) {
- if (er) return res.error(er)
+ if (er) return res.error(er, 'login.ejs')
if (cr.statusCode !== 200) {
// XXX Should just render the login form
// with an error about a bad login or something.
// Something like:
// res.template('login.ejs', {message:'bad login'})
- return res.error(er, cr.statusCode)
+ er = er || new Error('Username and/or password is wrong')
+ return res.error(er, cr.statusCode, 'login.ejs')
}
// look up the profile data. we're gonna need
@@ -48,7 +50,7 @@ function handleForm (req, res) {
var pu = '/_users/org.couchdb.user:' + data.name
req.couch.get(pu, function (er, cr, data) {
if (er || cr.statusCode !== 200) {
- return res.error(er, cr && cr.statusCode)
+ return res.error(er, 401, 'login.ejs')
}
req.session.set("profile", data)
View
6 templates/login.ejs
@@ -1,10 +1,14 @@
<%- include('header.ejs', locals) %>
<h1>Login, please</h1>
-<% if (locals.failed) { %>
+<% if (locals.failed || locals.error ||
+ locals.statusCode && locals.statusCode >= 400) { %>
<p class=error>The information you entered was rejected for reasons.</p>
<p>You may try again, or <a href=/forgot>reset your password</a>
if you have forgotten it.</p>
+ <% if (locals.message) { %>
+ <p>The server said: <code><%= locals.message %></code></p>
+ <% } %>
<% } %>
<form action='' method='post' class=form>
Please sign in to comment.
Something went wrong with that request. Please try again.