Commit a3a80010 authored by Christophe Maudoux's avatar Christophe Maudoux 🐛

Append renew captcha button (#2019)

parent 6c890ecf
Pipeline #7154 passed with stage
in 15 minutes and 3 seconds
......@@ -152,6 +152,7 @@ README
scripts/llngDeleteSession
site/coffee/2fregistration.coffee
site/coffee/autoRenew.coffee
site/coffee/captcha.coffee
site/coffee/confirm.coffee
site/coffee/globalLogout.coffee
site/coffee/idpchoice.coffee
......@@ -281,6 +282,9 @@ site/htdocs/static/common/js/2fregistration.min.js.map
site/htdocs/static/common/js/autoRenew.js
site/htdocs/static/common/js/autoRenew.min.js
site/htdocs/static/common/js/autoRenew.min.js.map
site/htdocs/static/common/js/captcha.js
site/htdocs/static/common/js/captcha.min.js
site/htdocs/static/common/js/captcha.min.js.map
site/htdocs/static/common/js/confirm.js
site/htdocs/static/common/js/confirm.min.js
site/htdocs/static/common/js/confirm.min.js.map
......
......@@ -18,6 +18,7 @@
# * DELETE /sessions/my : ask for global logout
#
# - Authentication
# * GET /renewcaptcha : get token and captcha image
# * POST /sessions/<type>/<session-id>?auth : authenticate with a fixed
# sessionId
# * Note that the "getCookie" method (authentification via SOAP) exists for
......@@ -55,7 +56,8 @@ use MIME::Base64;
our $VERSION = '2.0.7';
extends 'Lemonldap::NG::Portal::Main::Plugin';
extends
qw (Lemonldap::NG::Portal::Main::Plugin Lemonldap::NG::Portal::Lib::Captcha);
has configStorage => (
is => 'ro',
......@@ -95,8 +97,8 @@ has exportedAttr => (
}
}
);
has ott => (
has captcha => ( is => 'rw' );
has ott => (
is => 'rw',
lazy => 1,
default => sub {
......@@ -113,6 +115,13 @@ sub init {
my ($self) = @_;
my @parents = ('Lemonldap::NG::Portal::Main::Plugin');
my $add = 0;
if ( $self->conf->{captcha_mail_enabled}
|| $self->conf->{captcha_login_enabled}
|| $self->conf->{captcha_register_enabled} )
{
$self->captcha( $self->p->loadModule('::Lib::Captcha') ) or return 0;
$self->addUnauthRoute( renewcaptcha => 'sendCaptcha', ['GET'] );
}
if ( $self->conf->{restConfigServer} ) {
push @parents, 'Lemonldap::NG::Common::Conf::RESTServer';
$add++;
......@@ -568,4 +577,12 @@ sub removeSessions {
return $self->p->sendJSONresponse( $req, { result => $nbr } );
}
sub sendCaptcha {
my ( $self, $req ) = @_;
my ( $token, $image ) = $self->captcha->getCaptcha($req);
return $self->p->sendJSONresponse( $req,
{ newtoken => $token, newimage => $image } );
}
1;
# Launch renew captcha request
renewCaptcha = () ->
console.log 'Call URL -> ', "#{portal}renewcaptcha"
# Request to get new token and image
$.ajax
type: "GET"
url: "#{portal}renewcaptcha"
dataType: 'json'
error: (j, status, err) ->
console.log 'Error', err
res = JSON.parse j.responseText
if res and res.error
console.log 'Returned error', res
# On success, values are set
success: (data) ->
newtoken = data.newtoken
console.log 'GET new token -> ', newtoken
newimage = data.newimage
console.log 'GET new image -> ', newimage
$('#token').attr 'value', newtoken
$('#captcha').attr 'src', newimage
$(document).ready ->
$('#logout').attr 'href', portal
$('.renewcaptchaclick').on 'click', renewCaptcha
\ No newline at end of file
// Generated by CoffeeScript 1.12.7
(function() {
var renewCaptcha;
renewCaptcha = function() {
console.log('Call URL -> ', portal + "renewcaptcha");
return $.ajax({
type: "GET",
url: portal + "renewcaptcha",
dataType: 'json',
error: function(j, status, err) {
var res;
console.log('Error', err);
res = JSON.parse(j.responseText);
if (res && res.error) {
return console.log('Returned error', res);
}
},
success: function(data) {
var newimage, newtoken;
newtoken = data.newtoken;
console.log('GET new token -> ', newtoken);
newimage = data.newimage;
console.log('GET new image -> ', newimage);
$('#token').attr('value', newtoken);
return $('#captcha').attr('src', newimage);
}
});
};
$(document).ready(function() {
$('#logout').attr('href', portal);
return $('.renewcaptchaclick').on('click', renewCaptcha);
});
}).call(this);
(function(){var e;e=function(){return console.log("Call URL -> ",portal+"renewcaptcha"),$.ajax({type:"GET",url:portal+"renewcaptcha",dataType:"json",error:function(e,r,o){var n;if(console.log("Error",o),(n=JSON.parse(e.responseText))&&n.error)return console.log("Returned error",n)},success:function(e){var r,o;return o=e.newtoken,console.log("GET new token -> ",o),r=e.newimage,console.log("GET new image -> ",r),$("#token").attr("value",o),$("#captcha").attr("src",r)}})},$(document).ready(function(){return $("#logout").attr("href",portal),$(".renewcaptchaclick").on("click",e)})}).call(this);
\ No newline at end of file
{"version":3,"sources":["lemonldap-ng-portal/site/htdocs/static/common/js/captcha.js"],"names":["renewCaptcha","console","log","portal","$","ajax","type","url","dataType","error","j","status","err","res","JSON","parse","responseText","success","data","newimage","newtoken","attr","document","ready","on","call","this"],"mappings":"CACA,WACE,IAAIA,EAEJA,EAAe,WAEb,OADAC,QAAQC,IAAI,eAAgBC,OAAS,gBAC9BC,EAAEC,KAAK,CACZC,KAAM,MACNC,IAAKJ,OAAS,eACdK,SAAU,OACVC,MAAO,SAASC,EAAGC,EAAQC,GACzB,IAAIC,EAGJ,GAFAZ,QAAQC,IAAI,QAASU,IACrBC,EAAMC,KAAKC,MAAML,EAAEM,gBACRH,EAAIJ,MACb,OAAOR,QAAQC,IAAI,iBAAkBW,IAGzCI,QAAS,SAASC,GAChB,IAAIC,EAAUC,EAMd,OALAA,EAAWF,EAAKE,SAChBnB,QAAQC,IAAI,oBAAqBkB,GACjCD,EAAWD,EAAKC,SAChBlB,QAAQC,IAAI,oBAAqBiB,GACjCf,EAAE,UAAUiB,KAAK,QAASD,GACnBhB,EAAE,YAAYiB,KAAK,MAAOF,OAKvCf,EAAEkB,UAAUC,MAAM,WAEhB,OADAnB,EAAE,WAAWiB,KAAK,OAAQlB,QACnBC,EAAE,sBAAsBoB,GAAG,QAASxB,OAG5CyB,KAAKC"}
\ No newline at end of file
<TMPL_IF NAME="TOKEN">
<input type="hidden" name="token" value="<TMPL_VAR NAME="TOKEN">" />
<input id="token" type="hidden" name="token" value="<TMPL_VAR NAME="TOKEN">" />
</TMPL_IF>
<TMPL_IF NAME="WAITING_MESSAGE">
......@@ -24,9 +24,16 @@
</TMPL_IF>
</div>
<!-- //if:jsminified
<script type="text/javascript" src="<TMPL_VAR NAME="STATIC_PREFIX">common/js/captcha.min.js"></script>
//else -->
<script type="text/javascript" src="<TMPL_VAR NAME="STATIC_PREFIX">common/js/captcha.js"></script>
<!-- //endif -->
<TMPL_IF NAME=CAPTCHA_SRC>
<div class="form-group">
<img src="<TMPL_VAR NAME=CAPTCHA_SRC>" class="img-thumbnail" />
<img class="renewcaptchaclick" src="<TMPL_VAR NAME="STATIC_PREFIX">common/icons/arrow_refresh.png" alt="RENEW CAPTCHA" class="img-thumbnail mb-3" />
<img id="captcha" src="<TMPL_VAR NAME=CAPTCHA_SRC>" class="img-thumbnail" />
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
......
......@@ -37,7 +37,7 @@ SKIP: {
$query =~ s/.*\btoken=([^&]+).*/token=$1/;
my $token;
ok( $token = $1, ' Token value is defined' );
ok( $res->[2]->[0] =~ m#<img src="data:image/png;base64#,
ok( $res->[2]->[0] =~ m#<img id="captcha" src="data:image/png;base64#,
' Captcha image inserted' );
my @form = ( $res->[2]->[0] =~ m#<form.*?</form>#sg );
......@@ -72,7 +72,7 @@ SKIP: {
# -------------------
$query =~ s/.*\btoken=([^&]+).*/token=$1/;
ok( $token = $1, ' Token value is defined' );
ok( $res->[2]->[0] =~ m#<img src="data:image/png;base64#,
ok( $res->[2]->[0] =~ m#<img id="captcha" src="data:image/png;base64#,
' Captcha image inserted' );
@form = ( $res->[2]->[0] =~ m#<form.*?</form>#sg );
......
......@@ -41,9 +41,9 @@ m%<input name="password" type="text" class="form-control key" autocomplete="off"
$query =~ s/.*\btoken=([^&]+).*/token=$1/;
my $token;
ok( $token = $1, ' Token value is defined' );
ok( $res->[2]->[0] =~ m#<img src="data:image/png;base64#,
ok( $res->[2]->[0] =~ m#<img id="captcha" src="data:image/png;base64#,
' Captcha image inserted' )
or explain( $res->[2]->[0], '<img src="data:image/png;base64' );
or explain( $res->[2]->[0], '<img id="captcha" src="data:image/png;base64' );
# Try to get captcha value
......@@ -106,7 +106,7 @@ m%<input name="password" type="text" class="form-control key" autocomplete="off"
),
'Verify that there is a new captcha image'
);
ok( $res->[2]->[0] =~ m#<img src="data:image/png;base64#,
ok( $res->[2]->[0] =~ m#<img id="captcha" src="data:image/png;base64#,
' New captcha image inserted' );
}
count($maintests);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment