import v2.0.0.0_RC3 | 2012-07-01

https://github.com/lucanos/CommunityID -> http://www.itadmins.net/archives/357
This commit is contained in:
2019-07-17 22:31:04 +02:00
parent 38c146901c
commit 2f397f01f7
2677 changed files with 296182 additions and 45159 deletions

33
modules/users/controllers/LoginController.php Executable file → Normal file
View File

@ -1,7 +1,7 @@
<?php
/*
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
* @license http://creativecommons.org/licenses/BSD/ BSD License
* @author Keyboard Monkey Ltd
* @since CommunityID 0.9
@ -25,11 +25,28 @@ class Users_LoginController extends CommunityID_Controller_Action
$this->view->loginForm = new Users_Form_Login(null, $this->view->base, $this->view->useCaptcha);
if ($this->_config->SSL->enable_mixed_mode) {
$this->view->loginTargetBase = 'https://' . $_SERVER['HTTP_HOST'] . $this->view->base;
if ($this->_config->subdomain->enabled) {
// in this case $this->view->base contains the full URL, so we just gotta replace the protocol
$this->view->loginTargetBase = 'https' . substr($this->view->base, strpos($this->view->base, '://'));
} else {
$this->view->loginTargetBase = 'https://' . $_SERVER['HTTP_HOST'] . $this->view->base;
}
} else {
$this->view->loginTargetBase = $this->view->base;
}
$this->view->allowRegistrations = $this->_config->environment->registrations_enabled;
if ($this->user->role == Users_Model_User::ROLE_GUEST && @$_COOKIE['image']) {
$images = new Users_Model_SigninImages();
$this->view->image = $images->getByCookie($_COOKIE['image']);
} else {
$this->view->image = false;
}
$this->view->yubikey = $this->_config->yubikey;
$this->_helper->viewRenderer->setResponseSegment('sidebar');
}
@ -48,9 +65,15 @@ class Users_LoginController extends CommunityID_Controller_Action
}
$users = new Users_Model_Users();
$result = $users->authenticate($this->_request->getPost('username'),
$this->_request->getPost('password'));
$result = $users->authenticate(
$this->_request->getPost('username'),
$this->_config->yubikey->enabled && $this->_config->yubikey->force?
$this->_request->getPost('yubikey')
: $this->_request->getPost('password'),
false,
$this->view
);
if ($result) {
$user = $users->getUser();

View File

@ -1,7 +1,7 @@
<?php
/*
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
* @license http://creativecommons.org/licenses/BSD/ BSD License
* @author Keyboard Monkey Ltd
* @since CommunityID 0.9
@ -21,7 +21,13 @@ class Users_ManageusersController extends CommunityID_Controller_Action
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNeverRender(true);
if ($this->_config->ldap->enabled && $this->_config->ldap->keepRecordsSynced) {
$ldap = Monkeys_Ldap::getInstance();
$ldap->delete($this->targetUser);
}
$this->targetUser->delete();
echo $this->view->translate('User has been deleted successfully');
}
@ -42,31 +48,30 @@ class Users_ManageusersController extends CommunityID_Controller_Action
$mail = self::getMail($user, $this->view->translate('Community-ID registration reminder'));
try {
$mail->send();
$user->reminders++;
$user->save();
} catch (Zend_Mail_Protocol_Exception $e) {
$this->_increaseReminderCount($user);
} catch (Zend_Mail_Exception $e) {
Zend_Registry::get('logger')->log($e->getMessage(), Zend_Log::ERR);
if (!$this->_config->environment->production) {
// still increase the reminder counter when testing
$this->_increaseReminderCount($user);
}
}
}
}
private function _increaseReminderCount(Users_Model_User $user)
{
$user->reminders++;
$user->save();
}
/**
* @return Zend_Mail
* @throws Zend_Mail_Protocol_Exception
*/
public static function getMail(Users_Model_User $user, $subject)
{
$locale = Zend_Registry::get('Zend_Locale');
$localeElements = explode('_', $locale);
if (file_exists(APP_DIR . "/resources/$locale/reminder_mail.txt")) {
$file = APP_DIR . "/resources/$locale/reminder_mail.txt";
} else if (count($localeElements == 2)
&& file_exists(APP_DIR . "/resources/".$localeElements[0]."/reminder_mail.txt")) {
$file = APP_DIR . "/resources/".$localeElements[0]."/reminder_mail.txt";
} else {
$file = APP_DIR . "/resources/en/reminder_mail.txt";
}
$file = CommunityID_Resources::getResourcePath('reminder_mail.txt');
$emailTemplate = file_get_contents($file);
$emailTemplate = str_replace('{userName}', $user->getFullName(), $emailTemplate);
@ -74,7 +79,7 @@ class Users_ManageusersController extends CommunityID_Controller_Action
preg_match('#(.*)/manageusers/sendreminder#', $currentUrl, $matches);
$emailTemplate = str_replace('{registrationURL}', $matches[1] . '/register/eula?token=' . $user->token, $emailTemplate);
// can't use $this-_config 'cause it's a static function
// can't use $this->_config 'cause it's a static function
$configEmail = Zend_Registry::get('config')->email;
switch (strtolower($configEmail->transport)) {

View File

@ -1,7 +1,7 @@
<?php
/*
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
* @license http://creativecommons.org/licenses/BSD/ BSD License
* @author Keyboard Monkey Ltd
* @since CommunityID 0.9
@ -20,30 +20,33 @@ class Users_PersonalinfoController extends CommunityID_Controller_Action
public function indexAction()
{
$this->_helper->actionStack('index', 'login', 'users');
}
$profiles = new Users_Model_Profiles();
$this->view->profiles = $profiles->getForUser($this->user);
public function showAction()
{
$fields = new Model_Fields();
$this->view->fields = $fields->getValues($this->user);
$this->_helper->actionStack('index', 'login', 'users');
}
public function editAction()
{
$this->view->profile = $this->_getProfile();
$appSession = Zend_Registry::get('appSession');
if (isset($appSession->personalInfoForm)) {
$this->view->fields = $appSession->personalInfoForm->getElements();
unset($appSession->personalInfoForm);
} else {
$personalInfoForm = new Users_Form_PersonalInfo(null, $this->user);
$personalInfoForm = new Users_Form_PersonalInfo(null, $this->view->profile);
$this->view->fields = $personalInfoForm->getElements();
}
$this->_helper->actionStack('index', 'login', 'users');
}
public function saveAction()
{
$form = new Users_Form_PersonalInfo(null, $this->user);
$profile = $this->_getProfile();
$form = new Users_Form_PersonalInfo(null, $profile);
$formData = $this->_request->getPost();
$form->populate($formData);
@ -55,15 +58,23 @@ class Users_PersonalinfoController extends CommunityID_Controller_Action
}
$fieldsValues = new Model_FieldsValues();
$fieldsValues->deleteForUser($this->user);
if ($this->_getParam('profile')) {
$fieldsValues->deleteForProfile($profile);
} else {
$profile->user_id = $this->user->id;
$profile->name = $form->getValue('profileName');
$profile->save();
}
foreach ($form->getValues() as $fieldName => $fieldValue) {
if (!$fieldValue) {
if ($fieldName == 'profileName' || !$fieldValue) {
continue;
}
$fieldsValue = $fieldsValues->createRow();
$fieldsValue->user_id = $this->user->id;
$fieldsValue->profile_id = $profile->id;
list(, $fieldId) = explode('_', $fieldName);
$fieldsValue->field_id = $fieldId;
@ -73,7 +84,34 @@ class Users_PersonalinfoController extends CommunityID_Controller_Action
$fieldsValue->save();
}
$this->_helper->FlashMessenger->addMessage($this->view->translate('Profile has been saved'));
$this->_redirect('/users/personalinfo');
}
$this->_forward('show');
public function deleteAction()
{
$profile = $this->_getProfile();
if ($profile->id) {
$profile->delete();
}
$this->_helper->FlashMessenger->addMessage($this->view->translate('Profile has been deleted'));
$this->_redirect('/users/personalinfo');
}
private function _getProfile()
{
$profiles = new Users_Model_Profiles();
if (!$this->_getParam('profile')) {
return $profiles->createRow();
}
$profile = $profiles->getRowInstance($this->_getParam('profile'));
if (!$profile || $profile->user_id != $this->user->id) {
throw new Monkeys_AccessDeniedException();
}
return $profile;
}
}

9
modules/users/controllers/ProfileController.php Executable file → Normal file
View File

@ -1,7 +1,7 @@
<?php
/*
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
* @license http://creativecommons.org/licenses/BSD/ BSD License
* @author Keyboard Monkey Ltd
* @since CommunityID 0.9
@ -17,6 +17,13 @@ class Users_ProfileController extends CommunityID_Controller_Action
throw new Monkeys_AccessDeniedException();
}
$this->view->canEditAccountInfo = !$this->_config->ldap->enabled
|| ($this->_config->ldap->enabled && $this->_config->ldap->keepRecordsSynced);
$this->view->canChangePassword = !$this->_config->ldap->enabled
|| ($this->_config->ldap->enabled && $this->_config->ldap->canChangePassword);
$this->view->yubikey = $this->_config->yubikey;
$this->_helper->actionStack('index', 'login', 'users');
}
}

View File

@ -1,7 +1,7 @@
<?php
/*
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
* @license http://creativecommons.org/licenses/BSD/ BSD License
* @author Keyboard Monkey Ltd
* @since CommunityID 0.9
@ -24,13 +24,15 @@ class Users_ProfilegeneralController extends CommunityID_Controller_Action
public function accountinfoAction()
{
$this->view->yubikey = $this->_config->yubikey;
}
public function editaccountinfoAction()
{
if ($this->targetUser->id != $this->user->id
// this condition checks for an non-admin trying to add a new user
&& ($this->targetUser->id != 0 || $this->user->role != Users_Model_User::ROLE_ADMIN))
if (($this->targetUser->id != $this->user->id
// this condition checks for an non-admin trying to add a new user
&& ($this->targetUser->id != 0 || $this->user->role != Users_Model_User::ROLE_ADMIN))
|| ($this->_config->ldap->enabled && !$this->_config->ldap->keepRecordsSynced))
{
throw new Monkeys_AccessDeniedException();
}
@ -46,16 +48,22 @@ class Users_ProfilegeneralController extends CommunityID_Controller_Action
'firstname' => $this->targetUser->firstname,
'lastname' => $this->targetUser->lastname,
'email' => $this->targetUser->email,
'authMethod' => $this->targetUser->auth_type,
'yubikey' => '' // of course empty
));
}
$this->view->yubikey = $this->_config->yubikey;
}
public function saveaccountinfoAction()
{
$isNewUser = is_null($this->targetUser->id)? true : false;
if (!$isNewUser && $this->targetUser->id != $this->user->id) {
// admins can add new users, but not edit existing ones
if (
// admins can add new users, but not edit existing ones
(!$isNewUser && $this->targetUser->id != $this->user->id)
|| ($this->_config->ldap->enabled && !$this->_config->ldap->keepRecordsSynced)) {
throw new Monkeys_AccessDeniedException();
}
@ -68,9 +76,10 @@ class Users_ProfilegeneralController extends CommunityID_Controller_Action
}
$existingUsernameOrEmail = false;
$oldUsername = $this->targetUser->username;
$newUsername = $form->getValue('username');
if (($isNewUser && $this->_usernameAlreadyExists($newUsername))
|| (!$isNewUser && ($this->targetUser->username != $newUsername)
|| (!$isNewUser && ($oldUsername != $newUsername)
&& $this->_usernameAlreadyExists($newUsername)))
{
$form->username->addError($this->view->translate('This username is already in use'));
@ -90,6 +99,21 @@ class Users_ProfilegeneralController extends CommunityID_Controller_Action
return $this->_redirectInvalidForm($form);
}
if ($this->_config->yubikey->enabled) {
$this->targetUser->auth_type = $form->getValue('authMethod');
$yubikey = trim($form->getValue('yubikey'));
if ($form->getValue('authMethod') == Users_Model_User::AUTH_YUBIKEY) {
// only store or update yubikey for new users or existing that filled in something
if ($isNewUser || $yubikey) {
if (!$publicId = $this->_getYubikeyPublicId($yubikey)) {
$form->yubikey->addError($this->view->translate('Could not validate Yubikey'));
return $this->_redirectInvalidForm($form);
}
$this->targetUser->yubikey_publicid = $publicId;
}
}
}
$this->targetUser->username = $newUsername;
$this->targetUser->firstname = $form->getValue('firstname');
$this->targetUser->lastname = $form->getValue('lastname');
@ -97,11 +121,35 @@ class Users_ProfilegeneralController extends CommunityID_Controller_Action
if ($isNewUser) {
$this->targetUser->accepted_eula = 1;
$this->targetUser->registration_date = date('Y-m-d');
$this->targetUser->openid = $this->_generateOpenId($this->targetUser->username);
preg_match('#(.*)/users/profile.*#', Zend_OpenId::selfURL(), $matches);
$this->targetUser->generateOpenId($matches[1]);
$this->targetUser->role = Users_Model_User::ROLE_REGISTERED;
$this->targetUser->setClearPassword($form->getValue('password1'));
}
if ($this->_config->ldap->enabled && $this->_config->ldap->keepRecordsSynced) {
$ldap = Monkeys_Ldap::getInstance();
if ($isNewUser) {
$this->targetUser->setPassword($form->getValue('password1'));
$ldap->add($this->targetUser);
} else {
if ($oldUsername != $newUsername) {
$ldap->modifyUsername($this->targetUser, $oldUsername);
}
$ldap->modify($this->targetUser);
}
// LDAP passwords must not be stored in the DB
$this->targetUser->setPassword('');
}
$this->targetUser->save();
if ($isNewUser) {
$this->targetUser->createDefaultProfile($this->view);
}
/**
* When the form is submitted through a YUI request using a file, an iframe is used,
@ -115,7 +163,7 @@ class Users_ProfilegeneralController extends CommunityID_Controller_Action
private function _usernameAlreadyExists($username)
{
$users = $this->_getUsers();
return $users->getUserWithUsername($username);
return $users->getUserWithUsername($username, false, $this->view);
}
private function _emailAlreadyExists($email)
@ -144,8 +192,9 @@ class Users_ProfilegeneralController extends CommunityID_Controller_Action
*/
public function changepasswordAction()
{
if ($this->targetUser->id != $this->user->id)
{
if (($this->targetUser->id != $this->user->id)
|| ($this->_config->ldap->enabled && !$this->_config->ldap->canChangePassword)
|| ($this->_config->yubikey->enabled && $this->_config->yubikey->force)) {
throw new Monkeys_AccessDeniedException();
}
@ -154,18 +203,19 @@ class Users_ProfilegeneralController extends CommunityID_Controller_Action
$this->view->changePasswordForm = $appSession->changePasswordForm;
unset($appSession->changePasswordForm);
} else {
$this->view->changePasswordForm = new Users_Form_ChangePassword();
$this->view->changePasswordForm = new Users_Form_ChangePassword(null, $this->user->username);
}
}
public function savepasswordAction()
{
if ($this->targetUser->id != $this->user->id)
{
if (($this->targetUser->id != $this->user->id)
|| ($this->_config->ldap->enabled && !$this->_config->ldap->canChangePassword)
|| ($this->_config->yubikey->enabled && $this->_config->yubikey->force)) {
throw new Monkeys_AccessDeniedException();
}
$form = new Users_Form_ChangePassword();
$form = new Users_Form_ChangePassword(null, $this->user->username);
$formData = $this->_request->getPost();
$form->populate($formData);
if (!$form->isValid($formData)) {
@ -175,14 +225,21 @@ class Users_ProfilegeneralController extends CommunityID_Controller_Action
}
$this->targetUser->setClearPassword($form->getValue('password1'));
$this->targetUser->save();
if ($this->_config->ldap->enabled && $this->_config->ldap->canChangePassword) {
$ldap = Monkeys_Ldap::getInstance();
$ldap->modify($this->targetUser, $form->getValue('password1'));
} else {
$this->targetUser->save();
}
return $this->_forward('accountinfo', null , null, array('userid' => $this->targetUser->id));
}
public function confirmdeleteAction()
{
if ($this->user->role == Users_Model_User::ROLE_ADMIN) {
if ($this->user->role == Users_Model_User::ROLE_ADMIN
|| ($this->_config->ldap->enabled && !$this->_config->ldap->keepRecordsSynced)) {
throw new Monkeys_AccessDeniedException();
}
@ -191,6 +248,11 @@ class Users_ProfilegeneralController extends CommunityID_Controller_Action
public function deleteAction()
{
if ($this->user->role == Users_Model_User::ROLE_ADMIN
|| ($this->_config->ldap->enabled && !$this->_config->ldap->keepRecordsSynced)) {
throw new Monkeys_AccessDeniedException();
}
$mail = self::getMail();
$mail->setFrom($this->_config->email->supportemail);
$mail->addTo($this->_config->email->supportemail);
@ -234,42 +296,26 @@ EOT;
$mail->setBodyText($body);
try {
$mail->send();
} catch (Zend_Mail_Protocol_Exception $e) {
} catch (Zend_Mail_Exception $e) {
if ($this->_config->logging->level == Zend_Log::DEBUG) {
$this->_helper->FlashMessenger->addMessage('Account was deleted, but feedback form couldn\'t be sent to admins');
$this->_helper->FlashMessenger->addMessage($this->view->translate('Account was deleted, but feedback form couldn\'t be sent to admins'));
}
}
$users = $this->_getUsers();
$users->deleteUser($this->user);
if ($this->_config->ldap->enabled && $this->_config->ldap->keepRecordsSynced) {
$ldap = Monkeys_Ldap::getInstance();
$ldap->delete($this->user);
}
Zend_Auth::getInstance()->clearIdentity();
$this->_helper->FlashMessenger->addMessage($this->view->translate('Your acccount has been successfully deleted'));
$this->_redirect('');
}
private function _generateOpenId($username)
{
$selfUrl = Zend_OpenId::selfUrl();
if (!preg_match('#(.*)/users/profile.*#', $selfUrl, $matches)) {
throw new Exception('Couldn\'t retrieve current URL');
}
if ($this->_config->subdomain->enabled) {
$openid = $this->getProtocol() . '://' . $username . '.' . $this->_config->subdomain->hostname;
} else {
$openid = $matches[1] . "/identity/$username";
}
if ($this->_config->SSL->enable_mixed_mode) {
$openid = str_replace('http://', 'https://', $openid);
}
Zend_OpenId::normalizeUrl($openid);
return $openid;
}
/**
* @return Zend_Mail
* @throws Zend_Mail_Protocol_Exception
@ -308,4 +354,33 @@ EOT;
return $this->_users;
}
private function _getYubikeyPublicId($yubikey)
{
$authAdapter = new Monkeys_Auth_Adapter_Yubikey(
array(
'api_id' => $this->_config->yubikey->api_id,
'api_key' => $this->_config->yubikey->api_key
),
null,
$yubikey
);
// do not go through Zend_Auth::getInstance() to avoid losing the session if
// the yubikey is invalid
$result = $authAdapter->authenticate($authAdapter);
if ($result->isValid()) {
$parts = Yubico_Auth::parsePasswordOTP($yubikey);
return $parts['prefix'];
}
$logger = Zend_Registry::get('logger');
$logger->log("Invalid authentication: " . implode(' - ', $result->getMessages()), Zend_Log::DEBUG);
$authOptions = $authAdapter->getOptions();
if ($yubi = @$authOptions['yubiClient']) {
$logger->log("Yubi request was: " . $yubi->getlastQuery(), Zend_Log::DEBUG);
}
return false;
}
}

30
modules/users/controllers/RecoverpasswordController.php Executable file → Normal file
View File

@ -1,7 +1,7 @@
<?php
/*
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
* @license http://creativecommons.org/licenses/BSD/ BSD License
* @author Keyboard Monkey Ltd
* @since CommunityID 0.9
@ -57,23 +57,13 @@ class Users_RecoverpasswordController extends CommunityID_Controller_Action
$user->token = Users_Model_User::generateToken();
$user->save();
$locale = Zend_Registry::get('Zend_Locale');
$localeElements = explode('_', $locale);
if (file_exists(APP_DIR . "/resources/$locale/passwordreset_mail.txt")) {
$file = APP_DIR . "/resources/$locale/passwordreset_mail.txt";
} else if (count($localeElements == 2)
&& file_exists(APP_DIR . "/resources/".$localeElements[0]."/passwordreset_mail.txt")) {
$file = APP_DIR . "/resources/".$localeElements[0]."/passwordreset_mail.txt";
} else {
$file = APP_DIR . "/resources/en/passwordreset_mail.txt";
}
$file = CommunityID_Resources::getResourcePath('passwordreset_mail.txt');
$emailTemplate = file_get_contents($file);
$emailTemplate = str_replace('{userName}', $user->getFullName(), $emailTemplate);
$emailTemplate = str_replace('{IP}', $_SERVER['REMOTE_ADDR'], $emailTemplate);
// $_SERVER['SCRIPT_URI'] is not always available
$URI = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$URI = self::getProtocol() . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
preg_match('#(.*)/users/recoverpassword#', $URI, $matches);
$emailTemplate = str_replace('{passwordResetURL}',
$matches[1] . '/users/recoverpassword/reset?token=' . $user->token,
@ -90,7 +80,7 @@ class Users_RecoverpasswordController extends CommunityID_Controller_Action
$users = new Users_Model_Users();
$user = $users->getUserWithToken($this->_getParam('token'));
if (!$user) {
$this->_helper->FlashMessenger->addMessage('Wrong Token');
$this->_helper->FlashMessenger->addMessage($this->view->translate('Wrong Token'));
$this->_redirect('');
return;
}
@ -103,17 +93,7 @@ class Users_RecoverpasswordController extends CommunityID_Controller_Action
$user->save();
$locale = Zend_Registry::get('Zend_Locale');
$localeElements = explode('_', $locale);
if (file_exists(APP_DIR . "/resources/$locale/passwordreset2_mail.txt")) {
$file = APP_DIR . "/resources/$locale/passwordreset2_mail.txt";
} else if (count($localeElements == 2)
&& file_exists(APP_DIR . "/resources/".$localeElements[0]."/passwordreset2_mail.txt")) {
$file = APP_DIR . "/resources/".$localeElements[0]."/passwordreset2_mail.txt";
} else {
$file = APP_DIR . "/resources/en/passwordreset2_mail.txt";
}
$file = CommunityID_Resources::getResourcePath('passwordreset2_mail.txt');
$emailTemplate = file_get_contents($file);
$emailTemplate = str_replace('{userName}', $user->getFullName(), $emailTemplate);
$emailTemplate = str_replace('{password}', $newPassword, $emailTemplate);

74
modules/users/controllers/RegisterController.php Executable file → Normal file
View File

@ -1,7 +1,7 @@
<?php
/*
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
* @license http://creativecommons.org/licenses/BSD/ BSD License
* @author Keyboard Monkey Ltd
* @since CommunityID 0.9
@ -55,7 +55,7 @@ class Users_RegisterController extends CommunityID_Controller_Action
$users = new Users_Model_Users();
if ($users->getUserWithUsername($form->getValue('username'))) {
if ($users->getUserWithUsername($form->getValue('username'), false, $this->view)) {
$form->username->addError($this->view->translate('This username is already in use'));
$appSession = Zend_Registry::get('appSession');
$appSession->registerForm = $form;
@ -76,35 +76,37 @@ class Users_RegisterController extends CommunityID_Controller_Action
$user->email = $form->getValue('email');
$user->username = $form->getValue('username');
$currentUrl = Zend_OpenId::selfURL();
preg_match('#(.*)/users/register/save#', $currentUrl, $matches);
if ($this->_config->subdomain->enabled) {
$openid = $this->getProtocol() . '://' . $user->username . '.' . $this->_config->subdomain->hostname;
preg_match('#(.*)/users/register/save#', Zend_OpenId::selfURL(), $matches);
$user->generateOpenId($matches[1]);
if ($this->_config->ldap->enabled) {
// when using ldap, unconfirmed users' password is saved unhashed temporarily, while he registers,
// and then it's stored in LDAP and cleared from the db
$user->setPassword($form->getValue('password1'));
} else {
$openid = $matches[1] . '/identity/' . $user->username;
$user->setClearPassword($form->getValue('password1'));
}
if ($this->_config->SSL->enable_mixed_mode) {
$openid = str_replace('http://', 'https://', $openid);
}
Zend_OpenId::normalizeUrl($openid);
$user->openid = $openid;
$user->setClearPassword($form->getValue('password1'));
$user->role = Users_Model_User::ROLE_GUEST;
$registrationToken = Users_Model_User::generateToken();
$user->token = $registrationToken;
$user->token = Users_Model_User::generateToken();
$user->accepted_eula = 0;
$user->registration_date = date('Y-m-d');
$user->save();
$mail = self::getMail($user, $this->view->translate('Community-ID registration confirmation'));
try {
$mail->send();
$user->save();
$user->createDefaultProfile($this->view);
$this->_helper->FlashMessenger->addMessage($this->view->translate('Thank you.'));
$this->_helper->FlashMessenger->addMessage($this->view->translate('You will receive an E-mail with instructions to activate the account.'));
} catch (Zend_Mail_Protocol_Exception $e) {
$this->_helper->FlashMessenger->addMessage($this->view->translate('The account was created but the E-mail could not be sent'));
} catch (Zend_Mail_Exception $e) {
if ($this->_config->environment->production) {
$this->_helper->FlashMessenger->addMessage($this->view->translate('The confirmation E-mail could not be sent, so the account creation was cancelled. Please contact support.'));
} else {
$this->_helper->FlashMessenger->addMessage($this->view->translate('The account was created but the E-mail could not be sent'));
// I still wanna create the user when in development mode
$user->save();
}
if ($this->_config->logging->level == Zend_Log::DEBUG) {
$this->_helper->FlashMessenger->addMessage($e->getMessage());
}
@ -125,18 +127,7 @@ class Users_RegisterController extends CommunityID_Controller_Action
$this->view->token = $user->token;
$locale = Zend_Registry::get('Zend_Locale');
$localeElements = explode('_', $locale);
if (file_exists(APP_DIR . "/resources/$locale/eula.txt")) {
$file = APP_DIR . "/resources/$locale/eula.txt";
} else if (count($localeElements == 2)
&& file_exists(APP_DIR . "/resources/".$localeElements[0]."/eula.txt")) {
$file = APP_DIR . "/resources/".$localeElements[0]."/eula.txt";
} else {
$file = APP_DIR . "/resources/en/eula.txt";
}
$file = CommunityID_Resources::getResourcePath('eula.txt');
$this->view->eula = file_get_contents($file);
}
@ -171,6 +162,15 @@ class Users_RegisterController extends CommunityID_Controller_Action
$user->accepted_eula = 1;
$user->registration_date = date('Y-m-d');
$user->token = '';
if ($this->_config->ldap->enabled) {
$ldap = Monkeys_Ldap::getInstance();
$ldap->add($user);
// clear unencrypted password
$user->setPassword('');
}
$user->save();
$auth = Zend_Auth::getInstance();
@ -185,17 +185,7 @@ class Users_RegisterController extends CommunityID_Controller_Action
*/
public static function getMail(Users_Model_User $user, $subject)
{
$locale = Zend_Registry::get('Zend_Locale');
$localeElements = explode('_', $locale);
if (file_exists(APP_DIR . "/resources/$locale/registration_mail.txt")) {
$file = APP_DIR . "/resources/$locale/registration_mail.txt";
} else if (count($localeElements == 2)
&& file_exists(APP_DIR . "/resources/".$localeElements[0]."/registration_mail.txt")) {
$file = APP_DIR . "/resources/".$localeElements[0]."/registration_mail.txt";
} else {
$file = APP_DIR . "/resources/en/registration_mail.txt";
}
$file = CommunityID_Resources::getResourcePath('registration_mail.txt');
$emailTemplate = file_get_contents($file);
$emailTemplate = str_replace('{userName}', $user->getFullName(), $emailTemplate);

View File

@ -0,0 +1,119 @@
<?php
/*
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
* @license http://creativecommons.org/licenses/BSD/ BSD License
* @author Keyboard Monkey Ltd
* @since CommunityID 0.9
* @package CommunityID
* @packager Keyboard Monkeys
*/
class Users_SigninimageController extends CommunityID_Controller_Action
{
public function indexAction()
{
$appSession = Zend_Registry::get('appSession');
if (isset($appSession->signinImageForm)) {
$this->view->signinImageForm = $appSession->signinImageForm;
unset($appSession->signinImageForm);
} else {
$this->view->signinImageForm = new Users_Form_SigninImage();
}
if (@$_COOKIE['image']) {
$this->view->enabled = true;
} else {
$this->view->enabled = false;
}
$this->_helper->actionStack('index', 'login', 'users');
}
public function saveimageAction()
{
$form = new Users_Form_SigninImage();
$formData = $this->_request->getPost();
// the framework doesn't allow doing this cleanly yet
$formData = array_merge($formData, array('image' => $_FILES['image']['name']));
$form->populate($formData);
if (!$form->isValid($formData)) {
$appSession = Zend_Registry::get('appSession');
$appSession->signinImageForm = $form;
$this->_forward('index');
return;
}
$fileInfo = $form->image->getFileInfo();
$images = new Users_Model_SigninImages();
$images->deleteForUser($this->user);
$image = $images->createRow();
$image->user_id = $this->user->id;
$image->image = file_get_contents($fileInfo['image']['tmp_name']);
$image->mime = $fileInfo['image']['type'];
$image->cookie = $images->generateCookieId($this->user);
$image->save();
// delete cookie
setcookie('image', $image->cookie, time() - 3600, '/', $this->_getCookieDomain());
$this->_redirect('/users/signinimage');
}
public function setcookieAction()
{
if ($this->_request->getParam('enable')) {
$images = new Users_Model_SigninImages();
if (!$image = $images->getForUser($this->user)) {
$this->_helper->FlashMessenger->addMessage($this->view->translate('There is no image uploaded'));
$this->_redirect('/users/signinimage');
return;
}
if (!setcookie('image', $image->cookie, time() + 24*60*60*10000, '/', $this->_getCookieDomain())) {
$this->_helper->FlashMessenger->addMessage($this->view->translate('There was a problem setting the cookie'));
$this->_redirect('/users/signinimage');
return;
}
$this->_helper->FlashMessenger->addMessage($this->view->translate('Image has been set successfully on this computer/browser'));
} else {
setcookie('image', $image->cookie, time() - 3600, '/', $this->_getCookieDomain());
$this->_helper->FlashMessenger->addMessage($this->view->translate('Image has been disabled successfully on this computer/browser'));
}
$this->_redirect('/users/signinimage');
}
public function imageAction()
{
$this->_helper->viewRenderer->setNeverRender(true);
$this->_helper->layout->disableLayout();
$images = new Users_Model_SigninImages();
if ($cookie = $this->_request->getParam('id')) {
$image = $images->getByCookie($cookie);
} else if ($this->user->role != Users_Model_User::ROLE_GUEST) {
$image = $images->getForUser($this->user);
} else {
return;
}
$this->_response->setHeader('Content-type', $image->mime);
echo $image->image;
}
private function _getCookieDomain()
{
if ($this->_config->subdomain->enabled) {
$domain = '.' . $this->_config->subdomain->hostname;
} else {
$domain = $_SERVER['HTTP_HOST'];
}
}
}

11
modules/users/controllers/UserslistController.php Executable file → Normal file
View File

@ -1,7 +1,7 @@
<?php
/*
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
* @license http://creativecommons.org/licenses/BSD/ BSD License
* @author Keyboard Monkey Ltd
* @since CommunityID 0.9
@ -29,6 +29,9 @@ class Users_UserslistController extends CommunityID_Controller_Action
break;
}
// This retrieves user data from the users table, even if using LDAP. This means the user's full name
// might be out of sync with what it's in LDAP. No biggie since user's names rarely change ;)
// However do know that a given user name is synced with LDAP every time he logs in.
$usersRows = $users->getUsers(
$this->_getParam('startIndex'),
$this->_getParam('results'),
@ -49,6 +52,10 @@ class Users_UserslistController extends CommunityID_Controller_Action
foreach ($usersRows as $user) {
if ($user->role == Users_Model_User::ROLE_ADMIN) {
if ($this->_config->ldap->enabled && $user->username != $this->_config->ldap->admin) {
// this is the admin created during the installation, that is not used when ldap is enabled
continue;
}
$status = $this->view->translate('admin');
} else if ($user->accepted_eula) {
$status = $this->view->translate('confirmed');
@ -61,7 +68,7 @@ class Users_UserslistController extends CommunityID_Controller_Action
$jsonObjUser->registration = $user->registration_date;
$jsonObjUser->role = $user->role;
$jsonObjUser->status = $status;
$jsonObjUser->reminders = $user->reminders;
$jsonObjUser->reminders = $user->accepted_eula? 0 : $user->reminders;
$jsonObj->records[] = $jsonObjUser;
}