I found an example for this on the internet and followed it.
This is my code in /hooks/header-extras.php :
Code: Select all
<script>
function recaptcha_onSubmit(token) {
//alert('TEST CLICKED');
document.getElementById('login_form').submit();
}
function validate(event) {
event.preventDefault();
grecaptcha.execute();
}
function recaptcha_onload() {
var element = document.getElementById('recaptcha_btn');
element.onclick = validate;
}
</script>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
This is my code in the modified /login.php file (I tried to comment items I added or modified) :
Code: Select all
<?php if(!isset($Translation)) { @header('Location: index.php?signIn=1'); exit; } ?>
<?php include_once("$currDir/header.php"); ?>
<?php if($_GET['loginFailed']) { ?>
<div class="alert alert-danger"><?php echo $Translation['login failed']; ?></div>
<?php } ?>
<div class="row">
<div class="col-sm-6 col-lg-8" id="login_splash">
<!-- customized splash content here -->
</div>
<div class="col-sm-6 col-lg-4">
<div class="panel panel-success">
<div class="panel-heading">
<h1 class="panel-title"><strong><?php echo $Translation['sign in here']; ?></strong></h1>
<?php if(sqlValue("select count(1) from membership_groups where allowSignup=1")) { ?>
<a class="btn btn-success pull-right" href="membership_signup.php"><?php echo $Translation['sign up']; ?></a>
<?php } ?>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<!-- added id to form -->
<form method="post" id="login_form" action="index.php">
<div class="form-group">
<label class="control-label" for="username"><?php echo $Translation['username']; ?></label>
<input class="form-control" name="username" id="username" type="text" placeholder="<?php echo $Translation['username']; ?>" required>
</div>
<div class="form-group">
<label class="control-label" for="password"><?php echo $Translation['password']; ?></label>
<input class="form-control" name="password" id="password" type="password" placeholder="<?php echo $Translation['password']; ?>" required>
<span class="help-block"><?php echo $Translation['forgot password']; ?></span>
</div>
<div class="checkbox">
<label class="control-label" for="rememberMe">
<input type="checkbox" name="rememberMe" id="rememberMe" value="1">
<?php echo $Translation['remember me']; ?>
</label>
</div>
<!-- added div below -->
<div id='recaptcha' class="g-recaptcha"
data-sitekey="**********************************"
data-callback="recaptcha_onSubmit"
data-size="invisible">
</div>
<div class="row">
<div class="col-sm-offset-3 col-sm-6">
<!-- <button name="signIn" type="button" id="submit" value="signIn" class="btn btn-primary btn-lg btn-block"><?php echo $Translation['sign in']; ?></button>
-->
<br>
<!-- I added the button below -->
<button class="btn btn-success btn-lg" id="recaptcha_btn" type="button">TEST</button></div>
</div>
</form>
<!-- added by me -->
<script>recaptcha_onload();</script>
</div>
<?php if(is_array(getTableList()) && count(getTableList())) { /* if anon. users can see any tables ... */ ?>
<div class="panel-footer">
<?php echo $Translation['browse as guest']; ?>
</div>
<?php } ?>
</div>
</div>
</div>
<script>document.getElementById('username').focus();</script>
<?php include_once("$currDir/footer.php"); ?>
I know this is a lot of stuff to review but any help with making this work work be greatly appreciated!
TD