Skip to content

Commit bd21280

Browse files
committed
added auth error messages
1 parent 5fb621a commit bd21280

File tree

2 files changed

+50
-23
lines changed

2 files changed

+50
-23
lines changed

coder-base/apps/auth/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,10 @@ exports.api_login_handler = function( req, res ) {
509509
return;
510510
}
511511
}
512-
res.json( { status: 'error' } );
512+
res.json( {
513+
status: 'error',
514+
error: 'invalid password'
515+
} );
513516
};
514517
exports.api_logout_handler = function( req, res ) {
515518
req.session.authenticated = false;

coder-base/static/apps/auth/js/index.js

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ var setupLoginFields = function() {
118118
$('#login_form .formfield.textinput input').focus( hideTextLabel );
119119
$('#login_form .formfield.textinput input').blur( onBlurTextInput );
120120
$('#login_form .formfield.textinput input').change( testLoginSubmitEnable );
121-
$('#login_form .formfield.textinput input').keydown( function() {
122-
setTimeout( testLoginSubmitEnable, 0 );
121+
$('#login_form .formfield.textinput input').keydown( function(e) {
122+
if (e.which != 13) {
123+
setTimeout( testLoginSubmitEnable, 0 );
124+
}
123125
});
124126

125127
//submit on enter or button click
@@ -139,9 +141,11 @@ var setupLogoutFields = function() {
139141
$('#logout_form .formfield.textinput input').focus( hideTextLabel );
140142
$('#logout_form .formfield.textinput input').blur( onBlurTextInput );
141143
$('#logout_form .formfield.textinput input').change( testLoginSubmitEnable );
142-
$('#logout_form .formfield.textinput input').keydown( function() {
143-
setTimeout( testLoginSubmitEnable, 0 );
144-
});
144+
$('#logout_form .formfield.textinput input').keydown( function(e) {
145+
if (e.which != 13) {
146+
setTimeout( testLoginSubmitEnable, 0 );
147+
}
148+
});
145149

146150
//submit on enter or button click
147151
$('#logout_form .formfield.textinput .pass').keypress(function (e) {
@@ -160,9 +164,11 @@ var setupConfigureFields = function() {
160164
$('#configure_form .formfield.textinput input').focus( hideTextLabel );
161165
$('#configure_form .formfield.textinput input').blur( onBlurTextInput );
162166
$('#configure_form .formfield.textinput input').change( testConfigureSubmitEnable );
163-
$('#configure_form .formfield.textinput input').keydown( function() {
164-
setTimeout( testConfigureSubmitEnable, 0 );
165-
});
167+
$('#configure_form .formfield.textinput input').keydown( function(e) {
168+
if (e.which != 13) {
169+
setTimeout( testConfigureSubmitEnable, 0 );
170+
}
171+
});
166172

167173
$('#configure_form .submit').click( configureClick );
168174
};
@@ -172,9 +178,18 @@ var setupAddPasswordFields = function() {
172178
$('#addpassword_form .formfield.textinput input').focus( hideTextLabel );
173179
$('#addpassword_form .formfield.textinput input').blur( onBlurTextInput );
174180
$('#addpassword_form .formfield.textinput input').change( testAddPasswordSubmitEnable );
175-
$('#addpassword_form .formfield.textinput input').keydown( function() {
176-
setTimeout( testAddPasswordSubmitEnable, 0 );
177-
});
181+
$('#addpassword_form .formfield.textinput input').keydown( function(e) {
182+
if (e.which != 13) {
183+
setTimeout( testAddPasswordSubmitEnable, 0 );
184+
}
185+
});
186+
187+
$('#addpassword_form .formfield.textinput .pass_repeat').keypress(function (e) {
188+
if (e.which == 13) {
189+
e.preventDefault();
190+
addPasswordClick();
191+
}
192+
});
178193

179194
$('#addpassword_form .submit').click( addPasswordClick );
180195
};
@@ -185,10 +200,19 @@ var setupChangePasswordFields = function() {
185200
$('#changepassword_form .formfield.textinput input').focus( hideTextLabel );
186201
$('#changepassword_form .formfield.textinput input').blur( onBlurTextInput );
187202
$('#changepassword_form .formfield.textinput input').change( testChangePasswordSubmitEnable );
188-
$('#changepassword_form .formfield.textinput input').keydown( function() {
189-
setTimeout( testChangePasswordSubmitEnable, 0 );
203+
$('#changepassword_form .formfield.textinput input').keydown( function(e) {
204+
if (e.which != 13) {
205+
setTimeout( testChangePasswordSubmitEnable, 0 );
206+
}
190207
});
191208

209+
$('#changepassword_form .formfield.textinput .pass_repeat').keypress(function (e) {
210+
if (e.which == 13) {
211+
e.preventDefault();
212+
changePasswordClick();
213+
}
214+
});
215+
192216
$('#changepassword_form .submit').click( changePasswordClick );
193217
$('#changepassword_form .cancel').click( function() {
194218
window.location.href="/";
@@ -201,7 +225,8 @@ var loginClick = function( what ) {
201225
if ( pagemode === "logout" ) {
202226
$form = $('#logout_form');
203227
}
204-
228+
229+
$form.find('.errormessage').css('visibility','hidden');
205230
$form.find('.pass').removeClass('error');
206231
$.post(
207232
appurl + '/api/login',
@@ -213,7 +238,7 @@ var loginClick = function( what ) {
213238
if( data.status === "success" ) {
214239
window.location.href="/app/coder";
215240
} else {
216-
241+
$form.find('.errormessage').text( data.error ).css('visibility','visible');
217242
$form.find('.pass').addClass('error');
218243
}
219244
}
@@ -249,13 +274,12 @@ var configureClick = function() {
249274
};
250275

251276
var addPasswordClick = function() {
252-
$this = $(this);
253277
var $form = $('#addpassword_form');
254278

255279
$form.find('.pass, .pass_repeat').removeClass('error');
256280
$form.find('.errormessage').css('visibility','hidden');
257-
var pass = $this.parent().find('.pass').val();
258-
var pass_repeat = $this.parent().find('.pass_repeat').val();
281+
var pass = $form.find('.pass').val();
282+
var pass_repeat = $form.find('.pass_repeat').val();
259283

260284
if ( !isValidPassword(pass) ) {
261285
$form.find('.pass').addClass('error');
@@ -287,14 +311,14 @@ var addPasswordClick = function() {
287311

288312

289313
var changePasswordClick = function() {
290-
$this = $(this);
314+
291315
var $form = $('#changepassword_form');
292316

293317
$form.find('.oldpass, .pass, .pass_repeat').removeClass('error');
294318
$form.find('.errormessage').css('visibility','hidden');
295-
var oldpass = $this.parent().find('.oldpass').val();
296-
var pass = $this.parent().find('.pass').val();
297-
var pass_repeat = $this.parent().find('.pass_repeat').val();
319+
var oldpass = $form.find('.oldpass').val();
320+
var pass = $form.find('.pass').val();
321+
var pass_repeat = $form.find('.pass_repeat').val();
298322

299323
if ( oldpass === "" ) {
300324
$form.find('.oldpass').addClass('error');

0 commit comments

Comments
 (0)