Skip to content

Commit

Permalink
Merge pull request emoncms#221 from inverse/tidy-up-fix
Browse files Browse the repository at this point in the history
Tidied up login page
  • Loading branch information
TrystanLea committed Jul 19, 2014
2 parents 6bde9cd + f67351b commit 68fe102
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 101 deletions.
4 changes: 2 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"browser": true,
"esnext": true,
"globals": {
"$": false,
"$": false
},
"globalstrict": true,
"quotmark": "double",
"smarttabs": true,
"trailing": true,
"undef": true,
"unused": true
}
}
219 changes: 120 additions & 99 deletions Modules/user/login_block.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,34 @@

<div style="margin: 0px auto; max-width:392px; padding:10px;">
<div style="max-width:392px; margin-right:20px; padding-top:45px; padding-bottom:15px; color: #888;">
<img style="margin:12px;" src="<?php echo $path; ?>Theme/emoncms_logo.png" width="256" height="46" />
<img style="margin:12px;" src="<?php echo $path; ?>Theme/emoncms_logo.png" alt="Emoncms" width="256" height="46" />
</div>

<div class="login-container">

<div id="login-form" class="well" style="text-align:left">
<p>
<?php echo _('Username:'); ?><br/>
<input type="text" tabindex="1" name="username" style="width:94%"/>
<label><?php echo _('Username:'); ?>
<input type="text" tabindex="1" name="username" />
</label>
</p>

<p class="register-item" style="display:none">
<?php echo _('Email:'); ?>
<input type="text" name="email" style="width:94%" tabindex="2"/>
<label><?php echo _('Email:'); ?>
<input type="text" name="email" style="width:94%" tabindex="2"/>
</label>
</p>

<p>
<?php echo _('Password:'); ?><br/>
<input type="password" tabindex="3" name="password" style="width:94%"/>
<label><?php echo _('Password:'); ?>
<input type="password" tabindex="3" name="password" />
</label>
</p>

<p class="register-item" style="display:none">
<?php echo _('Confirm password:'); ?><br/>
<input type="password" name="confirm-password" style="width:94%" tabindex="4"/>
<label><?php echo _('Confirm password:'); ?>
<input id="confirm-password" type="password" name="confirm-password" tabindex="4"/>
</label>
</p>

<div id="error" class="alert alert-error" style="display:none;"></div>
Expand All @@ -59,16 +63,26 @@
<a id="cancel-link" href="#"><?php echo _('cancel'); ?></a>
</p>

<p><a id="passwordreset-link" href="#" >Forgotten password</a></p>
<p>
<a id="passwordreset-link" href="#">Forgotten password</a>
</p>

<div id="passwordreset-block" style="display:none">
<hr>
<div id="passwordreset-message"></div>

<div id="passwordreset-input">
<p style="color:#888; font-size:12px">Enter account name:</p>
<input id="passwordreset-username" type="text" /><br>
<p style="color:#888; font-size:12px">Enter account email address:</p>
<input id="passwordreset-email" type="text" /><br>
<p>
<label>Enter account name:
<input id="passwordreset-username" type="text" />
</label>
<p>
<p>
<label>Enter account email address:
<input id="passwordreset-email" type="text" />
</label>
</p>
<div id="error-passwordreset" class="alert alert-error" style="display:none;"></div>
<button id="passwordreset-submit" class="btn">Submit</button>
</div>

Expand All @@ -80,112 +94,119 @@

<script>

var path = "<?php echo $path; ?>";
var register_open = false;
var passwordreset = "<?php echo $enable_password_reset; ?>";
/*global user:false */

if (!passwordreset) $("#passwordreset-link").hide();
"use strict";

$("#passwordreset-link").click(function(){
$("#passwordreset-block").show();
$("#passwordreset-input").show();
$("#passwordreset-message").html("");
});
var path = "<?php echo $path; ?>";

$("#passwordreset-submit").click(function(){
var username = $("#passwordreset-username").val();
var email = $("#passwordreset-email").val();

if (email=="" || username=="") {
alert("Please enter username and email address");
} else {
var result = user.passwordreset(username,email);
if (result.success==true) {
$("#passwordreset-message").html("<div class='alert alert-success'>"+result.message+"</div>");
$("#passwordreset-input").hide();
} else {
$("#passwordreset-message").html("<div class='alert alert-error'>"+result.message+"</div>");
}
}
});
$(document).ready(function() {

$("#register-link").click(function(){
$(".login-item").hide();
$(".register-item").show();
$("#error").hide();
register_open = true;
return false;
});
var register_open = false;
var passwordreset = "<?php echo $enable_password_reset; ?>";

$("#cancel-link").click(function(){
$(".login-item").show();
$(".register-item").hide();
$("#error").hide();
register_open = false;
return false;
});
if (!passwordreset) $("#passwordreset-link").hide();

$("#passwordreset-link").click(function(){
$("#passwordreset-block").show();
$("#passwordreset-input").show();
$("#passwordreset-message").html("");
});

$("input").keypress(function(event) {
//login or register when pressing enter
if (event.which == 13) {
event.preventDefault();
if ( register_open ) {
register();
$("#passwordreset-submit").click(function(){
var username = $("#passwordreset-username").val();
var email = $("#passwordreset-email").val();

if (email==="" || username==="") {
$("#error-passwordreset").text("Please enter username and email address").show();
} else {
login();
var result = user.passwordreset(username,email);
if (result.success===true) {
$("#passwordreset-message").html("<div class='alert alert-success'>"+result.message+"</div>");
$("#passwordreset-input").hide();
} else {
$("#passwordreset-message").html("<div class='alert alert-error'>"+result.message+"</div>");
}
}
}
});

function login(){
var username = $("input[name='username']").val();
var password = $("input[name='password']").val();
var rememberme = 0; if ($("#rememberme").is(":checked")) rememberme = 1;

var result = user.login(username,password,rememberme);

if (result.success)
{
window.location.href = path+"user/view";
}
else
{
$("#error").html(result.message).show();
}
}
});

$("#register-link").click(function(){
$(".login-item").hide();
$(".register-item").show();
$("#error").hide();
register_open = true;
return false;
});

$("#cancel-link").click(function(){
$(".login-item").show();
$(".register-item").hide();
$("#error").hide();
register_open = false;
return false;
});

$("input").keypress(function(event) {
//login or register when pressing enter
if (event.which == 13) {
event.preventDefault();
if ( register_open ) {
register();
} else {
login();
}
}
});

function register(){
var username = $("input[name='username']").val();
var password = $("input[name='password']").val();
var confirmpassword = $("input[name='confirm-password']").val();
var email = $("input[name='email']").val();
function login(){
var username = $("input[name='username']").val();
var password = $("input[name='password']").val();
var rememberme = 0; if ($("#rememberme").is(":checked")) rememberme = 1;

if (password != confirmpassword)
{
$("#error").html("Passwords do not match").show();
}
else
{
var result = user.register(username,password,email);
var result = user.login(username,password,rememberme);

if (result.success)
{
var result = user.login(username,password);
if (result.success)
{
window.location.href = path+"user/view";
}
window.location.href = path+"user/view";
}
else
{
$("#error").html(result.message).show();
}
}
}

$("#login").click(login);
$("#register").click(register);
function register(){
var username = $("input[name='username']").val();
var password = $("input[name='password']").val();
var confirmpassword = $("input[name='confirm-password']").val();
var email = $("input[name='email']").val();

if (password != confirmpassword)
{
$("#error").html("Passwords do not match").show();
}
else
{
var result = user.register(username,password,email);

if (result.success)
{
result = user.login(username,password);
if (result.success)
{
window.location.href = path+"user/view";
}
}
else
{
$("#error").html(result.message).show();
}
}
}

$("#login").click(login);
$("#register").click(register);

});
</script>

5 changes: 5 additions & 0 deletions Theme/emon.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ http://openenergymonitor.org
/* Negative indent footer by it's height */
margin: 0 auto -40px;
}

#login-form input[type="text"], #login-form input[type="password"] {
width: 94%;
}

#push, #footer {
height: 30px;
}
Expand Down

0 comments on commit 68fe102

Please sign in to comment.