import v1.0.0-RC4 | 2009-05-20

This commit is contained in:
2019-07-17 22:08:50 +02:00
commit b484e522e8
2459 changed files with 1038434 additions and 0 deletions

View File

@ -0,0 +1,89 @@
<?php
/*
* @copyright Copyright (C) 2005-2009 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_LoginController extends Monkeys_Controller_Action
{
public function indexAction()
{
$settings = new Settings();
$this->view->maintenanceEnabled = $settings->isMaintenanceMode();
$appSession = Zend_Registry::get('appSession');
if (isset($appSession->loginForm)) {
$this->view->loginForm = $appSession->loginForm;
unset($appSession->loginForm);
} else {
$this->view->loginForm = new LoginForm();
}
if ($this->_config->SSL->enable_mixed_mode) {
$this->view->loginTargetBase = 'https://' . $_SERVER['HTTP_HOST'] . $this->view->base;
} else {
$this->view->loginTargetBase = $this->view->base;
}
$this->_helper->viewRenderer->setResponseSegment('sidebar');
}
public function authenticateAction()
{
$auth = Zend_Auth::getInstance();
$form = new LoginForm();
$formData = $this->_request->getPost();
$form->populate($formData);
$appSession = Zend_Registry::get('appSession');
if (!$form->isValid($formData)) {
$appSession->loginForm = $form;
$this->_redirectToNormalConnection('');
}
$db = Zend_Db::factory($this->_config->database);
$authAdapter = new Zend_Auth_Adapter_DbTable($db, 'users', 'username', 'password', 'MD5(CONCAT(openid, ?))');
$authAdapter->setIdentity($this->_request->getPost('username'));
$authAdapter->setCredential($this->_request->getPost('password'));
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
$users = new Users();
$user = $users->getUser($result->getIdentity());
// $user might not exist when the openid validation passed, but there's no
// user in the system with that openid identity
if (!$user) {
Zend_Auth::getInstance()->clearIdentity();
$this->_helper->FlashMessenger->addMessage('Invalid credentials');
} else {
$auth->getStorage()->write($user);
if ($user->role != User::ROLE_ADMIN && $this->underMaintenance) {
Zend_Auth::getInstance()->clearIdentity();
return $this->_redirectForMaintenance(true);
}
}
} else {
$this->_helper->FlashMessenger->addMessage('Invalid credentials');
$appSession->loginForm = $form;
}
$this->_redirectToNormalConnection('');
}
public function logoutAction()
{
Zend_Auth::getInstance()->clearIdentity();
$this->_redirect('');
}
}

View File

@ -0,0 +1,33 @@
<?php
/*
* @copyright Copyright (C) 2005-2009 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_ManageusersController extends Monkeys_Controller_Action
{
public function indexAction()
{
$this->_helper->actionStack('index', 'login', 'users');
}
public function deleteAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNeverRender(true);
$this->targetUser->delete();
echo $this->view->translate('User has been deleted successfully');
}
public function deleteunconfirmedAction()
{
$users = new Users();
$users->deleteUnconfirmed();
}
}

View File

@ -0,0 +1,72 @@
<?php
/*
* @copyright Copyright (C) 2005-2009 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_PersonalinfoController extends Monkeys_Controller_Action
{
public function indexAction()
{
$this->_helper->actionStack('index', 'login', 'users');
}
public function showAction()
{
$fields = new Fields();
$this->view->fields = $fields->getValues($this->user);
}
public function editAction()
{
$appSession = Zend_Registry::get('appSession');
if (isset($appSession->personalInfoForm)) {
$this->view->fields = $appSession->personalInfoForm->getElements();
unset($appSession->personalInfoForm);
} else {
$personalInfoForm = new PersonalInfoForm(null, $this->user);
$this->view->fields = $personalInfoForm->getElements();
}
}
public function saveAction()
{
$form = new PersonalInfoForm(null, $this->user);
$formData = $this->_request->getPost();
$form->populate($formData);
if (!$form->isValid($formData)) {
$appSession = Zend_Registry::get('appSession');
$appSession->personalInfoForm = $form;
$this->_forward('edit');
return;
}
$fieldsValues = new FieldsValues();
$fieldsValues->deleteForUser($this->user);
foreach ($form->getValues() as $fieldName => $fieldValue) {
if (!$fieldValue) {
continue;
}
$fieldsValue = $fieldsValues->createRow();
$fieldsValue->user_id = $this->user->id;
list(, $fieldId) = explode('_', $fieldName);
$fieldsValue->field_id = $fieldId;
$fieldsValue->value = $fieldValue;
$fieldsValue->save();
}
$this->_forward('show');
}
}

View File

@ -0,0 +1,22 @@
<?php
/*
* @copyright Copyright (C) 2005-2009 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_ProfileController extends Monkeys_Controller_Action
{
public function indexAction()
{
if (!$this->targetUser->id && $this->user->role != User::ROLE_ADMIN) {
throw new Monkeys_AccessDeniedException();
}
$this->_helper->actionStack('index', 'login', 'users');
}
}

View File

@ -0,0 +1,307 @@
<?php
/*
* @copyright Copyright (C) 2005-2009 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_ProfilegeneralController extends Monkeys_Controller_Action
{
private $_users;
public function preDispatch()
{
if ($this->user->role != User::ROLE_ADMIN
&& $this->targetUser->id != $this->user->id)
{
throw new Monkeys_AccessDeniedException();
}
}
public function accountinfoAction()
{
}
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 != User::ROLE_ADMIN))
{
throw new Monkeys_AccessDeniedException();
}
$appSession = Zend_Registry::get('appSession');
if (isset($appSession->accountInfoForm)) {
$this->view->accountInfoForm = $appSession->accountInfoForm;
unset($appSession->accountInfoForm);
} else {
$this->view->accountInfoForm = new AccountInfoForm(null, $this->targetUser);
$this->view->accountInfoForm->populate(array(
'username' => $this->targetUser->username,
'firstname' => $this->targetUser->firstname,
'lastname' => $this->targetUser->lastname,
'email' => $this->targetUser->email,
));
}
}
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
throw new Monkeys_AccessDeniedException();
}
$form = new AccountInfoForm(null, $this->targetUser);
$formData = $this->_request->getPost();
$form->populate($formData);
if (!$form->isValid($formData)) {
return $this->_redirectInvalidForm($form);
}
$existingUsernameOrEmail = false;
$newUsername = $form->getValue('username');
if (($isNewUser && $this->_usernameAlreadyExists($newUsername))
|| (!$isNewUser && ($this->targetUser->username != $newUsername)
&& $this->_usernameAlreadyExists($newUsername)))
{
$form->username->addError($this->view->translate('This username is already in use'));
$existingUsernameOrEmail = true;
}
$newEmail = $form->getValue('email');
if (($isNewUser && $this->_emailAlreadyExists($newEmail))
|| (!$isNewUser && ($this->targetUser->email != $newEmail)
&& $this->_emailAlreadyExists($newEmail)))
{
$form->email->addError($this->view->translate('This E-mail is already in use'));
$existingUsernameOrEmail = true;
}
if ($existingUsernameOrEmail) {
return $this->_redirectInvalidForm($form);
}
$this->targetUser->username = $newUsername;
$this->targetUser->firstname = $form->getValue('firstname');
$this->targetUser->lastname = $form->getValue('lastname');
$this->targetUser->email = $newEmail;
if ($isNewUser) {
$this->targetUser->accepted_eula = 1;
$this->targetUser->registration_date = date('Y-m-d');
$this->targetUser->openid = $this->_generateOpenId($this->targetUser->username);
$this->targetUser->role = User::ROLE_REGISTERED;
$this->targetUser->setClearPassword($form->getValue('password1'));
}
$this->targetUser->save();
/**
* When the form is submitted through a YUI request using a file, an iframe is used,
* so the framework doesn't detected it as ajax, so we have to manually ensure the
* layout is not shown.
*/
$this->_helper->layout->disableLayout();
$this->_forward('accountinfo', null , null, array('userid' => $this->targetUser->id));
}
private function _usernameAlreadyExists($username)
{
$users = $this->_getUsers();
return $users->getUser($username);
}
private function _emailAlreadyExists($email)
{
$users = $this->_getUsers();
return $users->getUserWithEmail($email);
}
private function _redirectInvalidForm(Zend_Form $form)
{
$appSession = Zend_Registry::get('appSession');
$appSession->accountInfoForm = $form;
/**
* When the form is submitted through a YUI request using a file, an iframe is used,
* so the framework doesn't detected it as ajax, so we have to manually ensure the
* layout is not shown.
*/
$this->_helper->layout->disableLayout();
$this->_forward('editaccountinfo', null , null, array('userid' => $this->targetUser->id));
return;
}
/**
* Only the users themselves can change their passwords
*/
public function changepasswordAction()
{
if ($this->targetUser->id != $this->user->id)
{
throw new Monkeys_AccessDeniedException();
}
$appSession = Zend_Registry::get('appSession');
if (isset($appSession->changePasswordForm)) {
$this->view->changePasswordForm = $appSession->changePasswordForm;
unset($appSession->changePasswordForm);
} else {
$this->view->changePasswordForm = new ChangePasswordForm();
}
}
public function savepasswordAction()
{
if ($this->targetUser->id != $this->user->id)
{
throw new Monkeys_AccessDeniedException();
}
$form = new ChangePasswordForm();
$formData = $this->_request->getPost();
$form->populate($formData);
if (!$form->isValid($formData)) {
$appSession = Zend_Registry::get('appSession');
$appSession->changePasswordForm = $form;
return $this->_forward('changepassword', null , null, array('userid' => $this->targetUser->id));
}
$this->targetUser->setClearPassword($form->getValue('password1'));
$this->targetUser->save();
return $this->_forward('accountinfo', null , null, array('userid' => $this->targetUser->id));
}
public function confirmdeleteAction()
{
$this->_helper->actionStack('index', 'login', 'users');
}
public function deleteAction()
{
$mail = self::getMail();
$mail->setFrom('support@community-id.org');
$mail->addTo($this->_config->email->supportemail);
$mail->setSubject('Community-ID user deletion');
$userFullname = $this->user->getFullName();
$reasonsChecked = array();
if ($this->_getParam('reason_test')) {
$reasonsChecked[] = 'This was just a test account';
}
if ($this->_getParam('reason_foundbetter')) {
$reasonsChecked[] = 'I found a better service';
}
if ($this->_getParam('reason_lackedfeatures')) {
$reasonsChecked[] = 'Service lacked some key features I needed';
}
if ($this->_getParam('reason_none')) {
$reasonsChecked[] = 'No particular reason';
}
if ($reasonsChecked) {
$reasonsChecked = implode("\r\n", $reasonsChecked);
} else {
$reasonsChecked = 'None (no checkbox was ticked).';
}
$comment = $this->_getParam('reason_comments');
$body = <<<EOT
Dear Admin:
The user $userFullname has deleted his account, giving the following feedback:
Reasons checked:
$reasonsChecked
Comment:
$comment
EOT;
$mail->setBodyText($body);
try {
$mail->send();
} catch (Zend_Mail_Protocol_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');
}
}
$users = $this->_getUsers();
$users->deleteUser($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
*/
public static function getMail()
{
// can't use $this->_config 'cause it's a static function
$configEmail = Zend_Registry::get('config')->email;
switch (strtolower($configEmail->transport)) {
case 'smtp':
Zend_Mail::setDefaultTransport(
new Zend_Mail_Transport_Smtp(
$configEmail->host,
$configEmail->toArray()
)
);
break;
case 'mock':
Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Mock());
break;
default:
Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Sendmail());
}
$mail = new Zend_Mail();
return $mail;
}
private function _getUsers()
{
if (!isset($this->_users)) {
$this->_users = new Users();
}
return $this->_users;
}
}

View File

@ -0,0 +1,141 @@
<?php
/*
* @copyright Copyright (C) 2005-2009 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_RecoverpasswordController extends Monkeys_Controller_Action
{
public function init()
{
parent::init();
if ($this->user->role != User::ROLE_ADMIN && $this->underMaintenance) {
return $this->_redirectForMaintenance();
}
}
public function indexAction()
{
$appSession = Zend_Registry::get('appSession');
if (isset($appSession->recoverPasswordForm)) {
$this->view->form = $appSession->recoverPasswordForm;
unset($appSession->recoverPasswordForm);
} else {
$this->view->form = new RecoverPasswordForm();
}
$this->_helper->actionStack('index', 'login', 'users');
}
public function sendAction()
{
$form = new RecoverPasswordForm();
$formData = $this->_request->getPost();
$form->populate($formData);
if (!$form->isValid($formData)) {
$appSession = Zend_Registry::get('appSession');
$appSession->recoverPasswordForm = $form;
return $this->_forward('index');
}
$users = new Users();
$user = $users->getUserWithEmail($form->getValue('email'));
if (!$user) {
$form->email->addError($this->view->translate('This E-mail is not registered in the system'));
$appSession = Zend_Registry::get('appSession');
$appSession->recoverPasswordForm = $form;
return $this->_forward('index');
}
$user->token = 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";
}
$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'];
preg_match('#(.*)/users/recoverpassword#', $URI, $matches);
$emailTemplate = str_replace('{passwordResetURL}',
$matches[1] . '/users/recoverpassword/reset?token=' . $user->token,
$emailTemplate);
$this->_sendMail($user->email, $this->view->translate('Community-ID password reset'), $emailTemplate);
$this->_helper->FlashMessenger->addMessage($this->view->translate('Password reset E-mail has been sent'));
$this->_redirect('');
}
public function resetAction()
{
$users = new Users();
$user = $users->getUserWithToken($this->_getParam('token'));
if (!$user) {
$this->_helper->FlashMessenger->addMessage('Wrong Token');
$this->_redirect('');
return;
}
$newPassword = $user->generateRandomPassword();
$user->setClearPassword($newPassword);
// reset token
$user->token = User::generateToken();
$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";
}
$emailTemplate = file_get_contents($file);
$emailTemplate = str_replace('{userName}', $user->getFullName(), $emailTemplate);
$emailTemplate = str_replace('{password}', $newPassword, $emailTemplate);
$this->_sendMail($user->email, $this->view->translate('Community-ID password reset'), $emailTemplate);
$this->_helper->FlashMessenger->addMessage($this->view->translate('You\'ll receive your new password via E-mail'));
$this->_redirect('');
}
private function _sendMail($to, $subject, $body)
{
if (strtolower($this->_config->email->transport) == 'smtp') {
Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Smtp($this->_config->email->host, $this->_config->email->toArray()));
} else {
Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Sendmail());
}
$mail = new Zend_Mail('utf-8');
$mail->setBodyText($body);
$mail->setFrom($this->_config->email->supportemail);
$mail->addTo($to);
$mail->setSubject($subject);
$mail->send();
}
}

View File

@ -0,0 +1,227 @@
<?php
/*
* @copyright Copyright (C) 2005-2009 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_RegisterController extends Monkeys_Controller_Action
{
protected $_numCols = 1;
public function init()
{
parent::init();
if ($this->user->role != User::ROLE_ADMIN && $this->underMaintenance) {
return $this->_redirectForMaintenance();
}
if (!$this->_config->environment->registrations_enabled) {
$this->_helper->FlashMessenger->addMessage($this->view->translate(
'Sorry, registrations are currently disabled'
));
return $this->_redirect('');
}
}
public function indexAction()
{
$appSession = Zend_Registry::get('appSession');
if (isset($appSession->registerForm)) {
$form = $appSession->registerForm;
unset($appSession->registerForm);
} else {
$form = new RegisterForm(null, $this->view->base);
}
$this->view->form = $form;
}
public function saveAction()
{
$form = new RegisterForm(null, $this->view->base);
$formData = $this->_request->getPost();
$form->populate($formData);
if (!$form->isValid($formData)) {
$appSession = Zend_Registry::get('appSession');
$appSession->registerForm = $form;
return $this->_forward('index', null, null);
}
$users = new Users();
if ($users->getUser($form->getValue('username'))) {
$form->username->addError($this->view->translate('This username is already in use'));
$appSession = Zend_Registry::get('appSession');
$appSession->registerForm = $form;
return $this->_forward('index', null, null);
}
if ($users->getUserWithEmail($form->getValue('email'))) {
$form->email->addError($this->view->translate('This E-mail is already in use'));
$appSession = Zend_Registry::get('appSession');
$appSession->registerForm = $form;
return $this->_forward('index', null, null);
}
$user = $users->createRow();
$user->firstname = $form->getValue('firstname');
$user->lastname = $form->getValue('lastname');
$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;
} else {
$openid = $matches[1] . '/identity/' . $user->username;
}
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 = User::ROLE_GUEST;
$registrationToken = User::generateToken();
$user->token = $registrationToken;
$user->accepted_eula = 0;
$user->registration_date = date('Y-m-d');
$user->save();
$mail = $this->getMail($user);
try {
$mail->send();
$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'));
if ($this->_config->logging->level == Zend_Log::DEBUG) {
$this->_helper->FlashMessenger->addMessage($e->getMessage());
}
}
$this->_redirect('');
}
public function eulaAction()
{
$users = new Users();
if ($this->_request->getParam('token') == ''
|| !($user = $users->getUserWithToken($this->_request->getParam('token')))) {
$this->_helper->FlashMessenger->addMessage('Invalid token');
$this->_redirect('');
}
$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";
}
$this->view->eula = file_get_contents($file);
}
public function declineeulaAction()
{
$users = new Users();
if (!($user = $users->getUserWithToken($this->_request->getParam('token'))) || $this->_request->getParam('token') == '') {
Zend_Registry::get('logger')->log('invalid token', Zend_Log::DEBUG);
$this->_helper->FlashMessenger->addMessage('Invalid token');
$this->_redirect('');
}
$user->delete();
$this->_helper->FlashMessenger->addMessage('Your account has been deleted');
$this->_redirect('');
}
public function accepteulaAction()
{
$users = new Users();
if (!($user = $users->getUserWithToken($this->_request->getParam('token'))) || $this->_request->getParam('token') == '') {
$this->_helper->FlashMessenger->addMessage('Invalid token');
$this->_redirect('');
}
$user->role = User::ROLE_REGISTERED;
$user->accepted_eula = 1;
$user->registration_date = date('Y-m-d');
$user->token = '';
$user->save();
$auth = Zend_Auth::getInstance();
$auth->getStorage()->write($user);
$this->_redirect('/users/profile');
}
/**
* @return Zend_Mail
* @throws Zend_Mail_Protocol_Exception
*/
public function getMail(User $user)
{
$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";
}
$emailTemplate = file_get_contents($file);
$emailTemplate = str_replace('{userName}', $user->getFullName(), $emailTemplate);
$currentUrl = Zend_OpenId::selfURL();
preg_match('#(.*)/register/save#', $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
$configEmail = Zend_Registry::get('config')->email;
switch (strtolower($configEmail->transport)) {
case 'smtp':
Zend_Mail::setDefaultTransport(
new Zend_Mail_Transport_Smtp(
$configEmail->host,
$configEmail->toArray()
)
);
break;
case 'mock':
Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Mock());
break;
default:
Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Sendmail());
}
$mail = new Zend_Mail();
$mail->setBodyText($emailTemplate);
$mail->setFrom('support@community-id.org');
$mail->addTo($user->email);
$mail->setSubject($this->view->translate('Community-ID registration confirmation'));
return $mail;
}
}

View File

@ -0,0 +1,67 @@
<?
/*
* @copyright Copyright (C) 2005-2009 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_UserslistController extends Monkeys_Controller_Action
{
public function indexAction()
{
$this->_helper->viewRenderer->setNeverRender(true);
$users = new Users();
switch($this->_getParam('filter')) {
case 'confirmed':
$where = "accepted_eula=1 AND role != '".User::ROLE_ADMIN."'";
break;
case 'unconfirmed':
$where = "accepted_eula=0 AND role != '".User::ROLE_ADMIN."'";
break;
default:
$where = false;
break;
}
$usersRows = $users->getUsers(
$this->_getParam('startIndex'),
$this->_getParam('results'),
$this->_getParam('sort', 'registration'),
$this->_getParam('dir', Users::DIR_DESC),
$where);
$jsonObj = new StdClass();
$jsonObj->recordsReturned = count($usersRows);
$jsonObj->totalRecords = $users->getNumUsers($where);
$jsonObj->totalUnconfirmedUsers = $users->getNumUnconfirmedUsers();
$jsonObj->startIndex = $_GET['startIndex'];
$jsonObj->sort = $this->_getParam('sort');
$jsonObj->dir = $this->_getParam('dir');
$jsonObj->records = array();
foreach ($usersRows as $user) {
if ($user->role == User::ROLE_ADMIN) {
$status = $this->view->translate('admin');
} else if ($user->accepted_eula) {
$status = $this->view->translate('confirmed');
} else {
$status = $this->view->translate('unconfirmed');
}
$jsonObjUser = new StdClass();
$jsonObjUser->id = $user->id;
$jsonObjUser->name = $user->getFullName();
$jsonObjUser->registration = $user->registration_date;
$jsonObjUser->role = $user->role;
$jsonObjUser->status = $status;
$jsonObj->records[] = $jsonObjUser;
}
echo Zend_Json::encode($jsonObj);
}
}