Skip to content

Commit

Permalink
Merge branch 'master' into 2.5
Browse files Browse the repository at this point in the history
# Conflicts:
#	application/controllers/admin/tokens.php
#	application/core/plugins/AuthLDAP/AuthLDAP.php
#	application/models/Survey.php
#	application/views/admin/token/invite.php
#	application/views/admin/token/remind.php
#	docs/release_notes.txt
#	locale/_template/limesurvey.pot
#	locale/ca/ca.mo
#	locale/es/es.mo
#	locale/fr/fr.mo
#	locale/it-informal/it-informal.mo
#	locale/it/it.mo
#	locale/ja/ja.mo
#	locale/ko/ko.mo
#	locale/nb/nb.mo
#	locale/nl-informal/nl-informal.mo
#	locale/nl/nl.mo
#	locale/nn/nn.mo
#	locale/pl/pl.mo
#	locale/ru/ru.mo
#	locale/th/th.mo
#	locale/zh-Hant-TW/zh-Hant-TW.mo
  • Loading branch information
c-schmitz committed Oct 2, 2015
2 parents fc95bde + 5323d02 commit 0907cc4
Show file tree
Hide file tree
Showing 21 changed files with 236 additions and 91 deletions.
5 changes: 5 additions & 0 deletions application/config/config-defaults.php
Expand Up @@ -146,6 +146,11 @@
$config['display_user_password_in_email'] = true;


// If no auth plugin is set as default, LS shows this auth method in login form
// Authdb is not set as default from Authdb plugin.
// If value of this variable is not a active plugin, 'Authdb' is used
$config['default_displayed_auth_method']= 'Authdb';

// auth_webserver
// Enable delegation of authentication to the webserver.
// If you set this parameter to true and set your webserver to authenticate
Expand Down
8 changes: 8 additions & 0 deletions application/controllers/admin/authentication.php
Expand Up @@ -70,6 +70,14 @@ public function index()
if (!is_null($beforeLogin->get('default'))) {
$aData['defaultAuth'] = $beforeLogin->get('default');
}
else {
if (App()->getPluginManager()->isPluginActive(Yii::app()->getConfig('default_displayed_auth_method'))) {
$aData['defaultAuth'] = Yii::app()->getConfig('default_displayed_auth_method');
}
else {
$aData['defaultAuth'] = 'Authdb';
}
}
$newLoginForm = new PluginEvent('newLoginForm');
App()->getPluginManager()->dispatchEvent($newLoginForm);
$aData['summary'] = $this->_getSummary('logout');
Expand Down
28 changes: 17 additions & 11 deletions application/controllers/admin/tokens.php
Expand Up @@ -1218,6 +1218,7 @@ function updatetokenattributedescriptions($iSurveyId)

// find out the existing token attribute fieldnames
$tokenattributefieldnames = getAttributeFieldNames($iSurveyId);

$languages = array_merge((array) Survey::model()->findByPk($iSurveyId)->language, Survey::model()->findByPk($iSurveyId)->additionalLanguages);
$fieldcontents = array();
$captions = array();
Expand All @@ -1230,9 +1231,8 @@ function updatetokenattributedescriptions($iSurveyId)
'cpdbmap' => Yii::app()->request->getPost('cpdbmap_' . $fieldname)
);
foreach ($languages as $language)
$captions[$language][$fieldname] = $_POST["caption_{$fieldname}_$language"];
$captions[$language][$fieldname] = Yii::app()->request->getPost("caption_{$fieldname}_$language");
}

Survey::model()->updateByPk($iSurveyId, array('attributedescriptions' => json_encode($fieldcontents)));
foreach ($languages as $language)
{
Expand Down Expand Up @@ -1451,13 +1451,16 @@ function email($iSurveyId, $tokenids = null)
}
$modsubject = Replacefields($sSubject[$emrow['language']], $fieldsarray);
$modmessage = Replacefields($sMessage[$emrow['language']], $fieldsarray);
if (trim($emrow['validfrom']) != '' && convertDateTimeFormat($emrow['validfrom'], 'Y-m-d H:i:s', 'U') * 1 > date('U') * 1)

if (!App()->request->getPost('bypassdatecontrol') && trim($emrow['validfrom']) != '' && convertDateTimeFormat($emrow['validfrom'], 'Y-m-d H:i:s', 'U') * 1 > date('U') * 1)
{
$tokenoutput .= $emrow['tid'] . " " . ReplaceFields(gT("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) delayed: Token is not yet valid.") . "<br />", $fieldsarray);
$tokenoutput .= $emrow['tid'] . " " . htmlspecialchars(ReplaceFields(gT("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) delayed: Token is not yet valid.",'unescaped'), $fieldsarray)). "<br />";
$bInvalidDate=true;
}
elseif (trim($emrow['validuntil']) != '' && convertDateTimeFormat($emrow['validuntil'], 'Y-m-d H:i:s', 'U') * 1 < date('U') * 1)
elseif (!App()->request->getPost('bypassdatecontrol') && trim($emrow['validuntil']) != '' && convertDateTimeFormat($emrow['validuntil'], 'Y-m-d H:i:s', 'U') * 1 < date('U') * 1)
{
$tokenoutput .= $emrow['tid'] . " " . ReplaceFields(gT("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) skipped: Token is not valid anymore.") . "<br />", $fieldsarray);
$tokenoutput .= $emrow['tid'] . " " . htmlspecialchars(ReplaceFields(gT("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) skipped: Token is not valid anymore.",'unescaped'), $fieldsarray)). "<br />";
$bInvalidDate=true;
}
else
{
Expand Down Expand Up @@ -1531,7 +1534,7 @@ function email($iSurveyId, $tokenids = null)
if ($success)
{
// Put date into sent
$token = Token::model($iSurveyId)->findByPk($emrow['tid']);
$token = Token::model($iSurveyId)->findByPk($emrow['tid']);
if ($bEmail)
{
$tokenoutput .= gT("Invitation sent to:");
Expand All @@ -1546,7 +1549,7 @@ function email($iSurveyId, $tokenids = null)
$token->save();

//Update central participant survey_links
if(!empty($emrow['participant_id']))
if(!empty($emrow['participant_id']))
{
$slquery = SurveyLink::model()->find('participant_id = :pid AND survey_id = :sid AND token_id = :tid',array(':pid'=>$emrow['participant_id'],':sid'=>$iSurveyId,':tid'=>$emrow['tid']));
if (!is_null($slquery))
Expand Down Expand Up @@ -1588,7 +1591,10 @@ function email($iSurveyId, $tokenids = null)
}
else
{
$aData['tokenoutput'].="<strong class='result success text-success'>".gT("All emails were sent.")."<strong>";
if(isset($bInvalidDate))
$aData['tokenoutput'].="<strong class='result success text-success'>".gT("Except those with invalid date, all emails were sent.")."<strong>";
else
$aData['tokenoutput'].="<strong class='result success text-success'>".gT("All emails were sent.")."<strong>";
}

$this->_renderWrappedTemplate('token', $aViewUrls, $aData);
Expand Down Expand Up @@ -2165,7 +2171,7 @@ function import($iSurveyId)
if (isset($aWriteArray[$field]))
{
$oCriteria->addCondition("{$field} = :{$field}");
$aParams[":{$field}"]=$writearray[$field];
$aParams[":{$field}"]=$aWriteArray[$field];
}
}
if(!empty($aParams))
Expand All @@ -2174,7 +2180,7 @@ function import($iSurveyId)
if ($dupresult > 0)
{
$bDuplicateFound = true;
$aDuplicateList[] = sprintf(gt("Line %s : %s %s (%s)"),$recordcount,$writearray['firstname'],$writearray['lastname'],$writearray['email']);
$aDuplicateList[] = sprintf(gt("Line %s : %s %s (%s)"),$iRecordCount,$aWriteArray['firstname'],$aWriteArray['lastname'],$aWriteArray['email']);
}
}

Expand Down
72 changes: 58 additions & 14 deletions application/core/plugins/AuthLDAP/AuthLDAP.php
Expand Up @@ -91,6 +91,14 @@ class AuthLDAP extends ls\pluginmanager\AuthPluginBase
'is_default' => array(
'type' => 'checkbox',
'label' => 'Check to make default authentication method'
),
'autocreate' => array(
'type' => 'checkbox',
'label' => 'Automatically create user if it exists in LDAP server'
),
'automaticsurveycreation' => array(
'type' => 'checkbox',
'label' => 'Grant survey creation permission to automatically created users'
)
);

Expand Down Expand Up @@ -119,8 +127,17 @@ public function createNewUser()
return;
}

$this->_createNewUser(flattenText(Yii::app()->request->getPost('new_user'), false, true));
}

/**
* Create a LDAP user
*
* @return int New user ID
*/
private function _createNewUser($new_user)
{
$oEvent = $this->getEvent();
$new_user = flattenText(Yii::app()->request->getPost('new_user'), false, true);

// Get configuration settings:
$ldapserver = $this->get('server');
Expand All @@ -141,15 +158,15 @@ public function createNewUser()
$oEvent->set('errorCode',self::ERROR_LDAP_CONNECTION);
$oEvent->set('errorMessageTitle','');
$oEvent->set('errorMessageBody',$ldapconn['errorMessage']);
return;
return null;
}

if (empty($ldapmode) || $ldapmode=='simplebind')
{
$oEvent->set('errorCode',self::ERROR_LDAP_MODE);
$oEvent->set('errorMessageTitle',gT("Failed to add user"));
$oEvent->set('errorMessageBody',gT("Simple bind LDAP configuration doesn't allow LDAP user creation"));
return;
return null;
}

// Search email address and full name
Expand All @@ -169,7 +186,7 @@ public function createNewUser()
$oEvent->set('errorMessageTitle',gT('Could not connect to LDAP server.'));
$oEvent->set('errorMessageBody',gT(ldap_error($ldapconn)));
ldap_close($ldapconn); // all done? close connection
return;
return null;
}
// Now prepare the search fitler
if ( $extrauserfilter != "")
Expand All @@ -195,15 +212,15 @@ public function createNewUser()
$oEvent->set('errorMessageTitle',gT('Username not found in LDAP server'));
$oEvent->set('errorMessageBody',gT('Verify username and try again'));
ldap_close($ldapconn); // all done? close connection
return;
return null;
}

if (!validateEmailAddress($new_email))
{
$oEvent->set('errorCode',self::ERROR_INVALID_EMAIL);
$oEvent->set('errorMessageTitle',gT("Failed to add user"));
$oEvent->set('errorMessageBody',gT("The email address is not valid."));
return;
return null;
}
$new_pass = createPassword();
$iNewUID = User::model()->insertUser($new_user, $new_pass, $new_full_name, Yii::app()->session['loginID'], $new_email);
Expand All @@ -212,16 +229,17 @@ public function createNewUser()
$oEvent->set('errorCode',self::ERROR_ALREADY_EXISTING_USER);
$oEvent->set('errorMessageTitle','');
$oEvent->set('errorMessageBody',gT("Failed to add user"));
return;
return null;
}

$this->setAuthPermission($iNewUID,'auth_ldap');
Permission::model()->setGlobalPermission($iNewUID,'auth_ldap');

$oEvent->set('newUserID',$iNewUID);
$oEvent->set('newPassword',$new_pass);
$oEvent->set('newEmail',$new_email);
$oEvent->set('newFullName',$new_full_name);
$oEvent->set('errorCode',self::ERROR_NONE);
return $iNewUID;
}


Expand Down Expand Up @@ -329,6 +347,8 @@ public function getPluginSettings($getValues = true)
unset($aPluginSettings['ldapoptreferrals']);
unset($aPluginSettings['mailattribute']);
unset($aPluginSettings['fullnameattribute']);
unset($aPluginSettings['autocreate']);
unset($aPluginSettings['automaticsurveycreation']);
}
}

Expand All @@ -348,15 +368,25 @@ public function newUserSession()
$username = $this->getUsername();
$password = $this->getPassword();

$ldapmode = $this->get('ldapmode');
$autoCreateFlag = false;
$user = $this->api->getUserByName($username);

// No user found!
if ($user === null)
{
// If the user doesnt exist in the LS database, he can not login
$this->setAuthFailure(self::ERROR_USERNAME_INVALID);
return;
// If ldap mode is searchandbind and autocreation is enabled we can continue
if ($ldapmode=='searchandbind' && $this->get('autocreate', null, null, false) == true)
{
$autoCreateFlag = true;
}
else
{
// If the user doesnt exist in the LS database, he can not login
$this->setAuthFailure(self::ERROR_USERNAME_INVALID);
return;
}
}
if ($user->uid == 1 || !Permission::model()->hasGlobalPermission('auth_ldap','read',$user->uid))
if ($user !== null && ($user->uid == 1 || !Permission::model()->hasGlobalPermission('auth_ldap','read',$user->uid)))
{
$this->setAuthFailure(self::ERROR_AUTH_METHOD_INVALID, gT('LDAP authentication method is not allowed for this user'));
return;
Expand All @@ -373,7 +403,6 @@ public function newUserSession()
// Get configuration settings:
$ldapserver = $this->get('server');
$ldapport = $this->get('ldapport');
$ldapmode = $this->get('ldapmode');
$suffix = $this->get('domainsuffix');
$prefix = $this->get('userprefix');
$searchuserattribute = $this->get('searchuserattribute');
Expand Down Expand Up @@ -475,6 +504,21 @@ public function newUserSession()

ldap_close($ldapconn); // all done? close connection

// Finally, if user didn't exist and auto creation is enabled, we create it
if ($autoCreateFlag)
{
if (($iNewUID = $this->_createNewUser($username)) && $this->get('automaticsurveycreation', null, null, false))
{
Permission::model()->setGlobalPermission($iNewUID, 'surveys', array('create_p'));
}
}
$user = $this->api->getUserByName($username);
if ($user === null)
{
$this->setAuthFailure(self::ERROR_USERNAME_INVALID, gT('Credentials are valid but we failed to create a user'));
return;
}

// If we made it here, authentication was a success and we do have a valid user
$this->setAuthSuccess($user);
}
Expand Down
4 changes: 1 addition & 3 deletions application/core/plugins/Authdb/Authdb.php
Expand Up @@ -58,7 +58,7 @@ public function createNewUser()
return;
}

$this->setAuthPermission($iNewUID,'auth_db');
Permission::model()->setGlobalPermission($iNewUID,'auth_db');

$oEvent->set('newUserID',$iNewUID);
$oEvent->set('newPassword',$new_pass);
Expand All @@ -77,8 +77,6 @@ public function beforeDeactivate()

public function beforeLogin()
{
$this->getEvent()->set('default', get_class($this)); // This is the default login method, should be configurable from plugin settings

// We can skip the login form here and set username/password etc.
$request = $this->api->getRequest();
if (!is_null($request->getParam('onepass'))) {
Expand Down
2 changes: 1 addition & 1 deletion application/core/plugins/Authwebserver/Authwebserver.php
Expand Up @@ -121,7 +121,7 @@ public function newUserSession()
{
$permission=new Permission;
$permission->setPermissions($oUser->uid, 0, 'global', $this->api->getConfigKey('auth_webserver_autocreate_permissions'), true);
$this->setAuthPermission($oUser->uid,'auth_webserver');
Permission::model()->setGlobalPermission($oUser->uid,'auth_webserver');

// read again user from newly created entry
$this->setAuthSuccess($oUser);
Expand Down
16 changes: 12 additions & 4 deletions application/core/plugins/ExportSTATAxml/ExportSTATAxml.php
Expand Up @@ -34,10 +34,18 @@ public function listExportOptions()
switch ($type) {
case 'stataxml':
$event->set('label', gT("STATA (.xml)"));
$event->set('onclick', 'document.getElementById("ansabbrev").checked=true;
document.getElementById("ansfull").disabled=true;document.getElementById("convertyto1").checked=true;document.getElementById("convertnto2").checked=true;
document.getElementById("convertnto").value=0;document.getElementById("convertyto").value=1;
document.getElementById("headcodes").disabled=true;document.getElementById("headabbreviated").disabled=true;document.getElementById("headfull").checked=true;');
$event->set('onclick', '
document.getElementById("answers-short").checked=true;
document.getElementById("answers-long").disabled=true;
document.getElementById("converty").checked=true;
document.getElementById("convertn").checked=true;
document.getElementById("convertnto").value=0;
document.getElementById("convertyto").value=1;
document.getElementById("headstyle-code").disabled=true;
document.getElementById("headstyle-abbreviated").disabled=true;
document.getElementById("headstyle-full").checked=true;
document.getElementById("headstyle-codetext").disabled=true;
');
break;

default:
Expand Down
4 changes: 3 additions & 1 deletion application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -360,6 +360,8 @@ function run($surveyid,$args) {
{
// may be submitting from the navigation bar, in which case need to process all intervening questions
// in order to update equations and ensure there are no intervening relevant mandatory or relevant invalid questions
if($thissurvey['questionindex']==2) // Must : save actual page , review whole before set finished to true (see #09906), index==1 seems to don't need it : (don't force move)
LimeExpressionManager::StartSurvey($surveyid, $surveyMode, $surveyOptions);
$moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['totalsteps'] + 1, false);
}
}
Expand Down Expand Up @@ -391,7 +393,7 @@ function run($surveyid,$args) {
if (isset($moveResult) && isset($moveResult['seq']) )// Reload at first page (welcome after click previous fill an empty $moveResult array
{
// With complete index, we need to revalidate whole group bug #08806. It's actually the only mode where we JumpTo with force
if($moveResult['finished'] == true && $thissurvey['questionindex']==2)// $thissurvey['questionindex']>=2
if($moveResult['finished'] == true && $move != 'movesubmit' && $thissurvey['questionindex']==2)// we already done if move == 'movesubmit', don't do it again
{
//LimeExpressionManager::JumpTo(-1, false, false, true);
LimeExpressionManager::StartSurvey($surveyid, $surveyMode, $surveyOptions);
Expand Down
9 changes: 1 addition & 8 deletions application/helpers/admin/htmleditor_helper.php
Expand Up @@ -148,14 +148,7 @@ function getEditor($fieldtype,$fieldname,$fieldtext, $surveyID=null,$gID=null,$q
{
$htmleditormode = $session['htmleditormode'];
}

if ( ($fieldtype == 'email-inv' ||
$fieldtype == 'email-reg' ||
$fieldtype == 'email-admin-notification' ||
$fieldtype == 'email-admin-resp' ||
$fieldtype == 'email-conf' ||
$fieldtype == 'email-rem' ) &&
getEmailFormat($surveyID) != 'html')
if ( $surveyID && getEmailFormat($surveyID) != 'html' && substr($fieldtype,0,6)==="email-" )// email but survey as text email
{
return '';
}
Expand Down

0 comments on commit 0907cc4

Please sign in to comment.