handle form_submit_element key in login info (#9477)

handle form_submit_elt key in login info (#9477)
This commit is contained in:
Josue Kouka 2016-01-04 12:17:38 +01:00
parent c18739db66
commit 8cef28bcb3
9 changed files with 118 additions and 10 deletions

7
README
View File

@ -47,7 +47,6 @@ Example of local_settings.py
SITE_DOMAIN = 'example.com'
SITE_LOGIN_PATH = '/'
SITE_HOME_PATH = '/profile' # Not required
SITE_CA_URL = 'https://myidp/account/' # Citizen account
SITE_LOCATORS = [
@ -94,13 +93,17 @@ Example of local_settings.py
# // your code
# }
#
SITE_AUTH_CHECKER = 'js/vincennes_auth_checker.js'
SITE_AUTH_CHECKER = 'js/example.auth.checker.js'
# JS/CSS for the association page (/_mandaye/associate)
SITE_ASSOCIATE_STATIC = {
'css': 'css/example_associate.css',
'js': 'js/example_associate.js',
}
# DOM Element used to validate the logon form
# If not provided, default is 'input[type=submit], button'
SITE_FORM_SUBMIT_ELEMENT = 'button[type=submit]'
# Mellon Settings
MELLON_IDENTITY_PROVIDERS = [

View File

@ -22,6 +22,11 @@ var input = JSON.parse(system.stdin.read(2000)); // no .readAll()...
headers_list = []
page.viewportSize = {
width : 1200,
height : 800
}
page.onResourceReceived = function(response){
for (var i=0; i < response.headers.length; i++){
var c_header = response.headers[i];
@ -47,6 +52,7 @@ page.open(input.address, function() {
console.log(JSON.stringify({'result': 'ok', 'cookies': page.cookies, 'headers': headers_list, 'url': page.frameUrl}));
phantom.exit();
}
page.render('home.png');
page.evaluate(function(input) {
var locators = input.locators;
for ( var i=0; i < locators.length; i++ ) {
@ -57,6 +63,6 @@ page.open(input.address, function() {
}
}
}
$(key).parents('form').find('input[type=submit]').click();
$(key).parents('form').find(input.form_submit_element).click();
}, input);
});

View File

@ -82,11 +82,11 @@ panel = Panel.as_view()
def post_login(request, *args, **kwargs):
try:
user = get_user_model().objects.get(username=request.user.username)
logger.debug(user)
logger.info(user)
credentials = UserCredentials.objects.get(
user=user,
linked=True)
logger.debug(credentials)
logger.info(credentials)
except (UserCredentials.DoesNotExist,):
return HttpResponseRedirect(resolve_url('associate'))
@ -135,24 +135,25 @@ def post_login_do(request, *args, **kwargs):
credentials = get_object_or_404(UserCredentials, user=request.user)
site_static_root = os.path.join(getattr(settings, 'STATIC_ROOT'), getattr(settings, 'SITE_STATIC_ROOT_PATH', ''))
site_auth_checker = getattr(settings, 'SITE_AUTH_CHECKER', '')
site_form_submit_element = getattr(settings, 'SITE_FORM_SUBMIT_ELEMENT', 'input[type=submit], button')
login_info = {
'address': request.build_absolute_uri(settings.SITE_LOGIN_PATH),
'cookies': [],
'locators': [ credentials.to_login_info() ],
'homepath': getattr(settings, 'SITE_HOME_PATH', '/'),
'form_submit_element': site_form_submit_element,
'auth_checker': os.path.join(site_static_root, site_auth_checker)
}
logger.debug(login_info)
logger.info(login_info)
result = exec_phantom(login_info)
logger.debug(result)
logger.info(result)
if result.get('result') != 'ok':
logger.debug('authentication failed')
logger.info('authentication failed')
User = get_user_model()
user = User.objects.get(username=request.user.username)
c_user = user.usercredentials_set.get()
c_user.linked = False
c_user.save()
logger.debug("redirecting to {}".format(resolve_url('associate')))
logger.info("redirecting to {}".format(resolve_url('associate')))
messages.error(request, _('wrong user credentials'))
url = resolve_url('associate')
else:

View File

@ -56,6 +56,7 @@ INSTALLED_APPS = (
'django.contrib.staticfiles',
'mandayejs.mandaye',
'mandayejs.sites.vincennes',
'mandayejs.sites.montpellier3m',
'gadjo',
'mellon'
)

View File

@ -0,0 +1,83 @@
body {
width: 900px;
max-width: 100%;
margin: 0 auto;
position: relative;
}
h1 {
font-size: larger;
}
.helptext {
font-size: x-small;
}
.messages {
font-size: small;
text-align: left;
postion: relative;
margin-left: 90px;
color: red;
}
.messages li { list-style-type: none }
.errorlist {
font-size: small;
text-align: left;
position: relative;
left: 90px;
color: red;
margin: 0;
}
.errorlist li { list-style-type: none }
#main-div {
width: 400px;
max-width: 100%;
margin-left: auto;
margin-right: auto;
position: relative;
background: #008592;
color: white;
border: 1px solid #f0f0fb;
border-radius: 5px;
text-align: center;
}
#submit {
text-transform: uppercase;
font-weight: bold;
background-color: #000;
border-color: #000;
color: #fff;
}
p {
text-align: left;
width: 90%;
max-width: 15em;;
margin: 1ex auto;
}
label {
display: block;
margin-left: auto;
margin-right: auto;
vertical-align: top;
text-align: left;
font-size: 14px;
font-weight: normal;
line-height: 20px;
}
input {
width: 100%;
display: block;
margin-left: auto;
margin-right: auto;
padding: 4px;
vertical-align: top;
}

View File

@ -0,0 +1,3 @@
$(function(){
console.log('lol');
});

View File

@ -0,0 +1,8 @@
$(function(){
window.auth_success = function(){
var found = $("body").text().indexOf('Le mot de passe saisi est incorrect, vérifiez la syntaxe et réessayez.');
if (found == -1)
return true;
return false;
}
});

View File

@ -0,0 +1,3 @@
$(function(){
console.log('lol');
});