Commit 8a5331aa authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan
Browse files

Merge branch 'ajaxlogin'

parents 684ca884 e7f28a3d
......@@ -25,6 +25,7 @@
*/
define('INTERNAL', 1);
define('IFRAME', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
// Upload a temporary file to attach to a blog post.
......@@ -39,7 +40,6 @@ $createid = param_variable('createid');
// Ignore possible file name clashes; they should be dealt with in the
// javascript on the edit blog post page.
safe_require('artefact', 'blog');
$attach = ArtefactTypeBlogPost::save_attachment_temporary('userfile', session_id() . $createid,
$result->uploadnumber);
......
// file.js
function ajaxlogin_iframe(form, crap) {
save_orig_data = false;
sendjsonrequest(
config.wwwroot + 'minilogin.php',
{'login_username': form.elements['login_username'].value, 'login_password': form.elements['login_password'].value, 'pieform_login': ''},
'POST',
function(data) {
removeElement('ajax-login-form');
removeElement('overlay');
config.sesskey = data.message;
uploader.getresult({"uploadnumber":$('uploadnumber').value,"message": get_string('timeouterror'),"problem": true});
},
function() {},
true
);
save_orig_data = true;
}
// The file browser part needs to be kept relatively separated from
// the file uploader because they are used slightly differently in the
// my files screen and the edit blog post screen
......@@ -608,7 +626,7 @@ function FileUploader(element, uploadscript, statevars, foldername, folderid, up
appendChildNodes(self.form,
INPUT({'type':'hidden', 'name':'parentfoldername', 'value':self.foldername}),
INPUT({'type':'hidden', 'name':'collideaction', 'value':collideaction}),
INPUT({'type':'hidden', 'name':'uploadnumber', 'value':self.nextupload}));
INPUT({'type':'hidden', 'id' : 'uploadnumber', 'name':'uploadnumber', 'value':self.nextupload}));
appendChildNodes(self.form,
INPUT({'type':'hidden', 'name':'parentfolder', 'value':self.folderid}));
......@@ -630,7 +648,10 @@ function FileUploader(element, uploadscript, statevars, foldername, folderid, up
}
this.getresult = function(data) {
if (!data.error) {
if (data.problem) {
var image = 'images/icon_problem.gif';
}
else if (!data.error) {
var image = 'images/success.gif';
}
else {
......
......@@ -83,6 +83,7 @@ $string['parentfolder'] = 'Parent folder';
$string['Preview'] = 'Preview';
$string['savechanges'] = 'Save changes';
$string['Size'] = 'Size';
$string['timeouterror'] = 'File upload failed: try uploading the file again';
$string['title'] = 'Name';
$string['titlefieldisrequired'] = 'The name field is required';
$string['Type'] = 'Type';
......
......@@ -126,6 +126,7 @@ class PluginArtefactFile extends PluginArtefact {
'nofilesfound',
'overwrite',
'savechanges',
'timeouterror',
'title',
'titlefieldisrequired',
'unlinkthisfilefromblogposts?',
......
......@@ -25,6 +25,7 @@
*/
define('INTERNAL', 1);
define('IFRAME', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'file');
global $USER;
......@@ -94,7 +95,7 @@ $result->quota = $USER->get('quota');
$result->quotaused = $USER->get('quotaused');
$r = json_encode($result);
log_debug($r);
$frame = <<< EOF
<html><head><script>
<!--
......
......@@ -378,10 +378,15 @@ function auth_setup () {
else if ($sessionlogouttime > 0) {
// The session timed out
$USER->logout();
if (defined('JSON')) {
json_reply('global', get_string('sessiontimedoutreload'), 1);
}
if (defined('IFRAME')) {
$frame = '<html><head></head><body onload="parent.show_login_form(\'ajaxlogin_iframe\')"></body></html>';
header('Content-type: text/html');
echo $frame;
exit;
}
// If the page the user is viewing is public, inform them that they can
// log in again
......
......@@ -204,7 +204,7 @@ if (!get_config('installed')
redirect('/admin/');
}
if (defined('JSON')) {
if (defined('JSON') && !defined('NOSESSKEY')) {
$sesskey = param_variable('sesskey', null);
global $USER;
if ($sesskey === null || $USER->get('sesskey') != $sesskey) {
......
......@@ -25,17 +25,53 @@ function get_themeurl(s) {
return config.theme[s];
}
var save_orig_data = true;
var orig_caller;
var orig_arguments;
var real_sesskey = '';
function globalErrorHandler(data) {
if (data.returnCode == 1) {
// Logged out!
// Later - ajaxlogin
displayMessage(data.message, 'error');
show_login_form('ajaxlogin');
}
else {
displayMessage(data.message, 'error');
}
}
function show_login_form(submit) {
if($('ajax-login-form') == null) {
var loginForm = DIV({id: 'ajax-login-form'});
loginForm.innerHTML = '<h2>' + get_string('login') + '</h2><a href="/">&laquo; ' + get_string('home') + '<\/a><div id="loginmessage">' + get_string('sessiontimedout') + '</div><form class="pieform" name="login" method="post" action="" id="login" onsubmit="' + submit + '(this, 42); return false;"><table cellspacing="0" border="0" class="maharatable"><tbody><tr id="login_login_username_header" class="required text"><th><label for="login_login_username">' + get_string('username') + ':<\/label><\/th><\/tr><tr id="login_login_username_container"><td><input type="text" class="required text autofocus" id="login_login_username" name="login_username" tabindex="2" value=""><\/td><\/tr><tr><td class="description"> <\/td><\/tr><tr id="login_login_password_header" class="required password"><th><label for="login_login_password">' + get_string('password') + ':<\/label><\/th><\/tr><tr id="login_login_password_container"><td><input type="password" class="required password" id="login_login_password" name="login_password" tabindex="2" value=""><\/td><\/tr><tr><td class="description"> <\/td><\/tr><tr id="login_submit_container"><td><input type="submit" class="submit" id="login_submit" name="submit" tabindex="2" value="' + get_string('login') + '"><\/td><\/tr><\/tbody><\/table><div id="homepage"><\/div><input type="hidden" name="sesskey" value=""><input type="hidden" name="pieform_login" value=""><\/form><script type="text\/javascript">var login_btn = null;addLoadEvent(function() { connect($(\'login_submit\'), \'onclick\', function() { login_btn = \'login_submit\'; });});connect(\'login\', \'onsubmit\', function() { formStartProcessing(\'login\', login_btn); });<\/script>';
appendChildNodes(document.body, DIV({id: 'overlay'}));
appendChildNodes(document.body, loginForm);
$('login_login_username').focus();
}
else {
$('loginmessage').innerHTML = get_string('loginfailed');
$('login_login_username').focus();
}
}
function ajaxlogin(form, crap) {
save_orig_data = false;
sendjsonrequest(
config.wwwroot + 'minilogin.php',
{'login_username': form.elements['login_username'].value, 'login_password': form.elements['login_password'].value, 'pieform_login': ''},
'POST',
function(data) {
removeElement('ajax-login-form');
removeElement('overlay');
config.sesskey = data.message;
sendjsonrequest.apply(orig_caller, orig_arguments);
},
function() {},
true
);
save_orig_data = true;
}
// Form related functions
var oldValue = null;
function formStartProcessing(form, btn) {
......@@ -149,6 +185,11 @@ function sendjsonrequest(script, data, rtype, successcallback, errorcallback, qu
break;
}
if (save_orig_data) {
orig_caller = this;
orig_arguments = arguments;
}
var d = doXHR(script, xhrOptions);
d.addCallbacks(function (result) {
......@@ -161,7 +202,9 @@ function sendjsonrequest(script, data, rtype, successcallback, errorcallback, qu
errtype = 'error';
}
else {
logWarning('invoking globalErrorHandler(', data, ')');
logWarning('invoking globalErrorHandler(', data, this, arguments, ')');
// Trying something ninja. The call failed, but in the event that the global error
// handler can recover, maybe it can be called
globalErrorHandler(data);
}
if (errtype) {
......
......@@ -453,6 +453,12 @@ function jsstrings() {
'pendingfriend',
'pendingfriends',
'couldnotgethelp',
'password',
'username',
'login',
'sessiontimedout',
'loginfailed',
'home',
),
),
'tablerenderer' => array(
......@@ -516,6 +522,7 @@ function themepaths() {
'images/failure.gif',
'images/loading.gif',
'images/success.gif',
'images/icon_problem.gif',
'images/icon_help.gif',
),
);
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2007 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Clare Lenihan <clare@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('JSON', 1);
define('NOSESSKEY', 1);
require('init.php');
json_reply(false, $USER->get('sesskey'));
?>
......@@ -639,6 +639,26 @@ div.sidebar p {
float: left;
}
/* AJAX LOGIN */
#ajax-login-form {
border: 5px solid green;
background-color: #fff;
position: fixed;
top: 150px;
left: 20%;
width: 250px;
z-index: 1000;
text-align: left;
}
#overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url(../images/overlay.png) repeat;
}
/* system messages between nav and main content */
#messages {
......
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