|
From: <al...@us...> - 2008-09-29 16:53:32
|
Revision: 709
http://sciret.svn.sourceforge.net/sciret/?rev=709&view=rev
Author: alpeb
Date: 2008-09-29 16:53:06 +0000 (Mon, 29 Sep 2008)
Log Message:
-----------
added ability to let anonymous users open an account. Disabled by default
Modified Paths:
--------------
trunk/actions/SavePreferences.php
trunk/flowMap.php
trunk/forms/RequestCategoryForm.php
trunk/models/Configuration.php
trunk/models/User.php
trunk/models/Users.php
trunk/templates/EditPreferences.tpl
trunk/templates/Login.tpl
trunk/templates/header.tpl
trunk/views/EditPreferences.php
trunk/views/Login.php
trunk/views/View.php
Added Paths:
-----------
trunk/actions/SaveRegistration.php
trunk/forms/RegistrationForm.php
trunk/templates/Register.tpl
trunk/views/Register.php
Modified: trunk/actions/SavePreferences.php
===================================================================
--- trunk/actions/SavePreferences.php 2008-09-29 15:56:51 UTC (rev 708)
+++ trunk/actions/SavePreferences.php 2008-09-29 16:53:06 UTC (rev 709)
@@ -36,6 +36,7 @@
$clamavError = '';
if (($this->user->role & User::ROLE_ADMIN) == User::ROLE_ADMIN) {
$this->configuration->setConfigValue('publishKB', $_POST['publishKB'] == '1'? '1' : '0');
+ $this->configuration->setConfigValue('anonymousRegistration', $_POST['anonymousRegistration'] == '1'? '1' : '0');
$this->configuration->setConfigValue('publishArticlesAuto', $_POST['publishArticlesAuto'] == '1'? '1' : '0');
$this->configuration->setConfigValue('publishBookmarksAuto', $_POST['publishBookmarksAuto'] == '1'? '1' : '0');
$this->configuration->setConfigValue('publishCommentsAuto', $_POST['publishCommentsAuto'] == '1'? '1' : '0');
Added: trunk/actions/SaveRegistration.php
===================================================================
--- trunk/actions/SaveRegistration.php (rev 0)
+++ trunk/actions/SaveRegistration.php 2008-09-29 16:53:06 UTC (rev 709)
@@ -0,0 +1,106 @@
+<?php
+
+/*
+* @copyright Copyright (C) 2005-2008 Keyboard Monkeys Ltd. http://www.kb-m.com
+* @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License
+* @author Alejandro Pedraza
+* @since Sciret 1.2
+* @package Sciret
+* @packager Keyboard Monkeys
+*/
+
+require 'actions/Action.php';
+
+class SaveRegistration extends Action
+{
+ private $_users;
+
+ public function dispatch()
+ {
+ if (!$this->configuration->getConfigValue('anonymousRegistration')) {
+ $_SESSION['message'] = $this->user->lang('Anonymous registration is disabled');
+ Library::redirect(Library::getLink(array('view' => 'MainView')));
+ }
+
+ $this->_users = new Users();
+
+ $form = new RegistrationForm(null, $this->user);
+ $formData = array(
+ 'firstName' => $_POST['firstName'],
+ 'lastName' => $_POST['lastName'],
+ 'userName' => $_POST['userName'],
+ 'email' => $_POST['email'],
+ );
+ $form->populate($formData);
+ if (!$form->isValid($formData)) {
+ $this->_redirectInvalidForm($form);
+ }
+
+ if ($this->_userNameExists($form->getValue('userName'))) {
+ $form->userName->addError($this->user->lang('This User Name is already used by someone else'));
+ $this->_redirectInvalidForm($form);
+ }
+
+ if ($this->_emailExists($form->getValue('email'))) {
+ $form->email->addError($this->user->lang('This E-mail is already used by someone else'));
+ $this->_redirectInvalidForm($form);
+ }
+
+ $user = $this->_users->createRow();
+ $user->firstname = $form->getValue('firstName');
+ $user->lastname = $form->getValue('lastName');
+ $user->username = $form->getValue('userName');
+ $user->email = $form->getValue('email');
+ $user->setAdmin(false);
+
+ // have the password expire now, so after the user logs in
+ // he's asked to change it
+ $password = $user->generateRandomPassword();
+ $user->setPassword($password);
+ $user->password_changed = '1900-01-01';
+
+ $mail = new EmailGateway($this->configuration);
+
+ $mail->AddAddress($user->email);
+ $mail->Subject = $this->user->lang('Welcome to the Knowledge Base');
+ $mail->Body = $this->user->lang("Thank you for opening an account in the Knowledge Base.\r\n\r\nYour UserName is: %s\r\nYour Password is: %s\r\n\r\nYou will be prompted to change the password when you log in.\r\n\r\nThank you.",
+ $user->username,
+ $password);
+
+ if (!$mail->Send()) {
+ $_SESSION['message'] = $this->user->lang('Sorry, there was a problem sending the confirmation E-mail, please try again later');
+ Library::redirect(Library::getLink(array('view' => 'MainView')));
+ }
+
+ $user->save();
+
+ $_SESSION['message'] = $this->user->lang('Thank you for registering. You will receive an E-mail with your account details.');
+ Library::redirect(Library::getLink(array('view' => 'MainView')));
+ }
+
+ /**
+ * @return bool
+ */
+ private function _userNameExists($userName)
+ {
+ return $this->_users->getUserGivenUsername($userName);
+ }
+
+ /**
+ * @return bool
+ */
+ private function _emailExists($email)
+ {
+ return $this->_users->getUserGivenEmail($email);
+ }
+
+ /**
+ * @return void
+ */
+ private function _redirectInvalidForm($form)
+ {
+ $appSession = Zend_Registry::get('appSession');
+ $appSession->registrationForm = $form;
+ Library::redirect(Library::getLink(array('view' => 'Register')));
+ }
+}
Modified: trunk/flowMap.php
===================================================================
--- trunk/flowMap.php 2008-09-29 15:56:51 UTC (rev 708)
+++ trunk/flowMap.php 2008-09-29 16:53:06 UTC (rev 709)
@@ -17,6 +17,7 @@
'InstallEnterCredentials' => array(User::ROLE_ANONYMOUS, false, true, false, false),
'InstallOk' => array(User::ROLE_ANONYMOUS, true, true, false, false),
'Login' => array(User::ROLE_ANONYMOUS, true, true, true, false),
+ 'Register' => array(User::ROLE_ANONYMOUS, true, true, true, false),
'MainView' => array(User::ROLE_ANONYMOUS, true, true, true, true),
'Rss' => array(User::ROLE_ANONYMOUS, true, false, false, true),
'EditArticle' => array(User::ROLE_REGISTERED, true, true, true),
@@ -50,6 +51,7 @@
$actions = array(
'Install' => array(User::ROLE_ANONYMOUS, false, false),
'Login' => array(User::ROLE_ANONYMOUS, true, false),
+ 'SaveRegistration' => array(User::ROLE_ANONYMOUS, true, false),
'Logout' => array(User::ROLE_REGISTERED, true),
'SaveArticle' => array(User::ROLE_REGISTERED, true),
'SaveBookmark' => array(User::ROLE_REGISTERED, true),
Added: trunk/forms/RegistrationForm.php
===================================================================
--- trunk/forms/RegistrationForm.php (rev 0)
+++ trunk/forms/RegistrationForm.php 2008-09-29 16:53:06 UTC (rev 709)
@@ -0,0 +1,49 @@
+<?php
+
+class RegistrationForm extends Zend_Form
+{
+ private $_user;
+
+ public function __construct($options = null, $user)
+ {
+ $this->_user = $user;
+
+ parent::__construct($options);
+ }
+
+ public function init()
+ {
+ $firstName = new Zend_Form_Element_Text('firstName');
+ $firstName->setLabel($this->_user->lang('First Name'))
+ ->setRequired(true);
+
+ $lastName = new Zend_Form_Element_Text('lastName');
+ $lastName->setLabel($this->_user->lang('Last Name'))
+ ->setRequired(true);
+
+ $userName = new Zend_Form_Element_Text('userName');
+ $userName->setLabel($this->_user->lang('User Name'))
+ ->setRequired(true);
+
+ $email = new Zend_Form_Element_Text('email');
+ $email->setLabel($this->_user->lang('E-mail'))
+ ->addFilter('StringToLower')
+ ->setRequired(true)
+ ->addValidator('EmailAddress');
+
+ $this->addElements(array($firstName, $lastName, $userName, $email));
+ }
+
+ /**
+ * Overrides Zend_Form method to fix issue
+ * @see http://www.nabble.com/Zend_Form-without-MVC-problem-td17375245.html
+ */
+ public function setView(Zend_View_Interface $view)
+ {
+ parent::setView($view);
+ foreach ($this as $item) {
+ $item->setView($view);
+ }
+ return $this;
+ }
+}
Modified: trunk/forms/RequestCategoryForm.php
===================================================================
--- trunk/forms/RequestCategoryForm.php 2008-09-29 15:56:51 UTC (rev 708)
+++ trunk/forms/RequestCategoryForm.php 2008-09-29 16:53:06 UTC (rev 709)
@@ -55,7 +55,6 @@
$this->AddElements(array($name, $email, $this->_parentCategory, $newCategoryName, $comments));
}
-
/**
* Overrides Zend_Form method to fix issue
* @see http://www.nabble.com/Zend_Form-without-MVC-problem-td17375245.html
Modified: trunk/models/Configuration.php
===================================================================
--- trunk/models/Configuration.php 2008-09-29 15:56:51 UTC (rev 708)
+++ trunk/models/Configuration.php 2008-09-29 16:53:06 UTC (rev 709)
@@ -14,6 +14,7 @@
var $configurationArray = array(
// var name => array(defaultValue, isHidden)
'publishKB' => 1,
+ 'anonymousRegistration' => 0,
'publishArticlesAuto' => 1,
'publishBookmarksAuto' => 1,
'publishCommentsAuto' => 1,
Modified: trunk/models/User.php
===================================================================
--- trunk/models/User.php 2008-09-29 15:56:51 UTC (rev 708)
+++ trunk/models/User.php 2008-09-29 16:53:06 UTC (rev 709)
@@ -289,6 +289,11 @@
return vsprintf($phrase, $args);
}
+ public function generateRandomPassword()
+ {
+ return substr(md5($this->getFullName() . time()), 0, 6);
+ }
+
function isPasswordExpired($expirationDays)
{
// there are 86400 seconds in one day
Modified: trunk/models/Users.php
===================================================================
--- trunk/models/Users.php 2008-09-29 15:56:51 UTC (rev 708)
+++ trunk/models/Users.php 2008-09-29 16:53:06 UTC (rev 709)
@@ -33,6 +33,14 @@
return $this->fetchRow($select);
}
+ public function getUserGivenEmail($email)
+ {
+ $select = $this->select()
+ ->where('email=?', $email);
+
+ return $this->fetchRow($select);
+ }
+
function getUsersList()
{
$select = $this->select();
Modified: trunk/templates/EditPreferences.tpl
===================================================================
--- trunk/templates/EditPreferences.tpl 2008-09-29 15:56:51 UTC (rev 708)
+++ trunk/templates/EditPreferences.tpl 2008-09-29 16:53:06 UTC (rev 709)
@@ -75,6 +75,15 @@
</td>
</tr>
<tr class="row_on">
+ <td style="text-align:right; font-weight:bold">[l]Let users open an account[/l]:</td>
+ <td>
+ <select name="anonymousRegistration">
+ <option value="1" {anonymousRegistration_yes_selected}>[l]Yes[/l]</option>
+ <option value="0" {anonymousRegistration_no_selected}>[l]No[/l]</option>
+ </select>
+ </td>
+ </tr>
+ <tr class="row_off">
<td style="text-align:right; font-weight:bold">[l]Publish articles automatically[/l]:</td>
<td>
<select name="publishArticlesAuto">
@@ -83,7 +92,7 @@
</select>
</td>
</tr>
- <tr class="row_off">
+ <tr class="row_on">
<td style="text-align:right; font-weight:bold">[l]Publish bookmarks automatically[/l]:</td>
<td>
<select name="publishBookmarksAuto">
@@ -92,7 +101,7 @@
</select>
</td>
</tr>
- <tr class="row_on">
+ <tr class="row_off">
<td style="text-align:right; font-weight:bold">[l]Publish comments automatically[/l]:</td>
<td>
<select name="publishCommentsAuto">
@@ -101,7 +110,7 @@
</select>
</td>
</tr>
- <tr class="row_off">
+ <tr class="row_on">
<td style="text-align:right; font-weight:bold">[l]Publish questions automatically[/l]:</td>
<td>
<select name="publishQuestionsAuto">
@@ -110,7 +119,7 @@
</select>
</td>
</tr>
- <tr class="row_on">
+ <tr class="row_off">
<td style="text-align:right; font-weight:bold">[l]Internal article by default[/l]:</td>
<td>
<select name="internalByDefault">
@@ -119,7 +128,7 @@
</select>
</td>
</tr>
- <tr class="row_off">
+ <tr class="row_on">
<td style="text-align:right; font-weight:bold">[l]Allow comments and ratings[/l]:</td>
<td>
<select name="allowCommentsRatings">
@@ -128,7 +137,7 @@
</select>
</td>
</tr>
- <tr class="row_on">
+ <tr class="row_off">
<td style="text-align:right; font-weight:bold">[l]Only admin and author can modify an article[/l]:</td>
<td>
<select name="restrictEditDelete">
@@ -137,31 +146,31 @@
</select>
</td>
</tr>
- <tr class="row_off">
+ <tr class="row_on">
<td style="text-align:right; font-weight:bold">[l]Days before password expires[/l]:</td>
<td>
<input type="text" name="passwordExpirationDays" value="{passwordExpirationDays}" size="2" />
</td>
</tr>
- <tr class="row_on">
+ <tr class="row_off">
<td style="text-align:right; font-weight:bold">[l]Send mail from (name)[/l]:</td>
<td>
<input type="text" name="mailFromName" value="{mailFromName}"/>
</td>
</tr>
- <tr class="row_off">
+ <tr class="row_on">
<td style="text-align:right; font-weight:bold">[l]Send mail from (email)[/l]:</td>
<td>
<input type="text" name="mailFromMail" value="{mailFromMail}"/>
</td>
</tr>
- <tr class="row_on">
+ <tr class="row_off">
<td style="text-align:right; font-weight:bold">[l]Send category creation request to (email)[/l]:</td>
<td>
<input type="text" name="mailCategoryRequest" value="{mailCategoryRequest}"/>
</td>
</tr>
- <tr class="row_off">
+ <tr class="row_on">
<td style="text-align:right; font-weight:bold">[l]Send mail using[/l]:</td>
<td>
<select name="mailTransport" onchange="javascript:toggleSMTPSettings(value);">
@@ -170,7 +179,7 @@
</select>
</td>
</tr>
- <tr class="row_on" id="smtp_options" {showSMTPOptions}>
+ <tr class="row_off" id="smtp_options" {showSMTPOptions}>
<td colspan="2">
<p style="text-align:center; font-weight:bold">[l]SMTP settings[/l]:</p>
<ul>
@@ -181,7 +190,7 @@
</ul>
</td>
</tr>
- <tr class="row_off">
+ <tr class="row_on">
<td style="text-align:right; font-weight:bold">
[l]Check uploaded files for viruses[/l]:<br />
[l](You need to have <a href="http://www.clamav.net">ClamAV</a> in your system)[/l]
Modified: trunk/templates/Login.tpl
===================================================================
--- trunk/templates/Login.tpl 2008-09-29 15:56:51 UTC (rev 708)
+++ trunk/templates/Login.tpl 2008-09-29 16:53:06 UTC (rev 709)
@@ -23,4 +23,10 @@
<td colspan="2" style="text-align:right"><input type="submit" value="[l]Login[/l]" /></td>
</tr>
</table>
+ <!-- BEGIN register_block -->
+ <div>
+ You don't have an account?
+ <a href="{registerLink}">[l]Register now[/l]</a>
+ </div>
+ <!-- END register_block -->
</form>
Added: trunk/templates/Register.tpl
===================================================================
--- trunk/templates/Register.tpl (rev 0)
+++ trunk/templates/Register.tpl 2008-09-29 16:53:06 UTC (rev 709)
@@ -0,0 +1,21 @@
+<!--
+/*
+* @copyright Copyright (C) 2005-2008 Keyboard Monkeys Ltd. http://www.kb-m.com
+* @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License
+* @author Alejandro Pedraza
+* @since Sciret 1.2
+* @package Sciret
+* @packager Keyboard Monkeys
+*/
+-->
+
+<form method="post" action="{formAction}">
+ {formFirstName}
+ {formLastName}
+ {formUserName}
+ {formEmail}
+ <input type="submit" id="submitForm" value="[l]Save[/l]" />
+ <script>
+ new YAHOO.widget.Button("submitForm");
+ </script>
+</form>
Modified: trunk/templates/header.tpl
===================================================================
--- trunk/templates/header.tpl 2008-09-29 15:56:51 UTC (rev 708)
+++ trunk/templates/header.tpl 2008-09-29 16:53:06 UTC (rev 709)
@@ -23,6 +23,9 @@
<!-- BEGIN loginLink_block -->
<span class="button_green"><a href="index.php?view=Login">[l]Login[/l]</a></span>
<!-- END loginLink_block -->
+ <!-- BEGIN registerLink_block -->
+ <span class="button_green"><a href="index.php?view=Register">[l]Register[/l]</a></span>
+ <!-- END registerLink_block -->
<!-- BEGIN logoutLink_block -->
<span class="button_green"><a href="index.php?action=Logout">[l]Logout[/l]</a></span>
<!-- END logoutLink_block -->
Modified: trunk/views/EditPreferences.php
===================================================================
--- trunk/views/EditPreferences.php 2008-09-29 15:56:51 UTC (rev 708)
+++ trunk/views/EditPreferences.php 2008-09-29 16:53:06 UTC (rev 709)
@@ -38,6 +38,8 @@
'catAndSubCats_selected' => $this->user->getPreference('navigationType') == 'catAndSubCats'? 'selected="true" ' : '',
'publishKB_yes_selected' => $this->configuration->getConfigValue('publishKB') == '1'? 'selected="true"' : '',
'publishKB_no_selected' => $this->configuration->getConfigValue('publishKB') == '0'? 'selected="true"' : '',
+ 'anonymousRegistration_yes_selected' => $this->configuration->getConfigValue('anonymousRegistration') == '1'? 'selected="true"' : '',
+ 'anonymousRegistration_no_selected' => $this->configuration->getConfigValue('anonymousRegistration') == '0'? 'selected="true"' : '',
'publishArticlesAuto_yes_selected' => $this->configuration->getConfigValue('publishArticlesAuto') == '1'? 'selected="true" ': '',
'publishArticlesAuto_no_selected' => $this->configuration->getConfigValue('publishArticlesAuto') == '0'? 'selected="true" ': '',
'publishBookmarksAuto_yes_selected' => $this->configuration->getConfigValue('publishBookmarksAuto') == '1'? 'selected="true" ': '',
Modified: trunk/views/Login.php
===================================================================
--- trunk/views/Login.php 2008-09-29 15:56:51 UTC (rev 708)
+++ trunk/views/Login.php 2008-09-29 16:53:06 UTC (rev 709)
@@ -15,6 +15,14 @@
function dispatch() {
$this->tpl->set_file('login', 'Login.tpl');
+ $this->tpl->set_block('login', 'register_block', 'register');
+ if ($this->configuration->getConfigValue('anonymousRegistration')) {
+ $this->tpl->set_var('registerLink', Library::getLink(array('view' => 'Register')));
+ $this->tpl->parse('register', 'register_block');
+ } else {
+ $this->tpl->set_var('register', '');
+ }
+
$this->tpl->pparse('out', 'login');
}
}
Added: trunk/views/Register.php
===================================================================
--- trunk/views/Register.php (rev 0)
+++ trunk/views/Register.php 2008-09-29 16:53:06 UTC (rev 709)
@@ -0,0 +1,52 @@
+<?php
+
+/*
+* @copyright Copyright (C) 2005-2008 Keyboard Monkeys Ltd http://www.kb-m.com
+* @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License
+* @author Alejandro Pedraza
+* @since Sciret 1.0
+* @package Sciret
+* @packager Keyboard Monkeys
+*/
+
+require 'views/View.php';
+
+class Register extends View
+{
+ function preDispatch()
+ {
+ if (!$this->configuration->getConfigValue('anonymousRegistration')) {
+ $_SESSION['message'] = $this->user->lang('Anonymous registration is disabled');
+ Library::redirect(Library::getLink(array('view' => 'MainView')));
+ }
+ }
+
+ public function dispatch()
+ {
+ $this->tpl->set_file('register', 'Register.tpl');
+
+ $appSession = Zend_Registry::get('appSession');
+ if (isset($appSession->registrationForm)) {
+ $form = $appSession->registrationForm;
+ unset($appSession->registrationForm);
+ } else {
+ $form = new RegistrationForm(null, $this->user);
+ }
+
+ $view = new Zend_View();
+ $form->setView($view);
+
+ $this->tpl->set_var(array(
+ 'formAction' => Library::getLink(array('action' => 'SaveRegistration')),
+ 'formFirstName' => $form->firstName->render(),
+ 'formLastName' => $form->lastName->render(),
+ 'formUserName' => $form->userName->render(),
+ 'formEmail' => $form->email->render(),
+ ));
+
+
+
+
+ $this->tpl->pparse('out', 'register');
+ }
+}
Modified: trunk/views/View.php
===================================================================
--- trunk/views/View.php 2008-09-29 15:56:51 UTC (rev 708)
+++ trunk/views/View.php 2008-09-29 16:53:06 UTC (rev 709)
@@ -71,6 +71,7 @@
$this->tpl->set_file('header', 'header.tpl');
$this->tpl->set_block('header', 'loginLink_block', 'loginLink');
+ $this->tpl->set_block('header', 'registerLink_block', 'registerLink');
$this->tpl->set_block('header', 'welcome_block', 'welcome');
$this->tpl->set_block('header', 'manageQuestionsLink_block', 'manageQuestionsLink');
@@ -88,6 +89,14 @@
$this->tpl->parse('manageQuestionsLink', 'manageQuestionsLink_block');
}
+ if ($this->user->isAnonymous()
+ && $this->configuration->getConfigValue('anonymousRegistration'))
+ {
+ $this->tpl->parse('registerLink', 'registerLink_block');
+ } else {
+ $this->tpl->set_var('registerLink', '');
+ }
+
$this->tpl->set_block('header', 'logoutLink_block', 'logoutLink');
if ($this->user->isAnonymous()) {
$this->tpl->set_var('logoutLink', '');
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|