changed login to ajax added error message for incorret login, closes #36

v1.18.x
Baris Soner Usakli 12 years ago
parent 8e10ce1924
commit 9b43f80ff8

@ -11,4 +11,31 @@
document.location.href = target.getAttribute('data-url');
}
});
$('#login').on('click', function() {
var loginData = {
'username': $('#username').val(),
'password': $('#password').val(),
'_csrf': $('#csrf-token').val()
};
$.ajax({
type: "POST",
url: '/login',
data: loginData,
success: function(data, textStatus, jqXHR) {
$('#login-error-notify').hide();
window.location.replace("/");
},
error : function(data, textStatus, jqXHR) {
$('#login-error-notify').show().delay(1000).fadeOut(250);
},
dataType: 'json'
});
return false;
});
}());

@ -6,13 +6,17 @@
<button type="button" class="close" data-dismiss="alert">&times;</button>
<strong>Failed Login Attempt</strong> <p></p>
</div>
<form method="post" action="/login">
<form>
<label>Username</label><input type="text" placeholder="Enter Username" name="username" id="username" /><br />
<label>Password</label><input type="password" placeholder="Enter Password" name="password" id="password" /><br />
<input type="hidden" name="_csrf" value="{token}" />
<input type="hidden" name="_csrf" value="{token}" id="csrf-token" />
<button class="btn btn-primary" id="login" type="submit">Login</button> &nbsp; <a href="/reset">Forgot Password?</a>
</form>
<span id="login-error-notify" class="label label-important hide">Invalid username/password</span><br/>
</div>
<div class="well span6 {alternate_logins:display}">
<h4>Alternative Logins</h4>
<ul class="alt-logins">

@ -129,10 +129,9 @@
});
app.post('/login', passport.authenticate('local', {
successRedirect: '/',
failureRedirect: '/login'
}));
app.post('/login', passport.authenticate('local'), function(req, res) {
res.json({success:1});
});
app.post('/register', function(req, res) {
user_module.create(req.body.username, req.body.password, req.body.email, function(err, uid) {

@ -91,7 +91,10 @@ var express = require('express'),
app.get('/' + route, function(req, res) {
if ((route === 'login' || route ==='register') && (req.user && req.user.uid > 0)) {
res.redirect('/account');
user.getUserField(req.user.uid, 'userslug', function(userslug) {
res.redirect('/users/'+userslug);
});
return;
}

Loading…
Cancel
Save