Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 4325bb2

Browse files
author
Charles Marion
committed
ENH: added settings page
1 parent 02a3649 commit 4325bb2

File tree

22 files changed

+478
-144
lines changed

22 files changed

+478
-144
lines changed

core/AppController.php

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,41 @@ public function preDispatch()
2323
// Set the version
2424
$this->view->version='3.0 beta';
2525
//Init Session
26-
$user=new Zend_Session_Namespace('Auth_User');
27-
if (!isset($user->initialized))
26+
if($fc->getRequest()->getActionName()!='login'||$fc->getRequest()->getControllerName()!='user')
2827
{
29-
Zend_Session::regenerateId();
30-
$user->initialized=true;
31-
}
32-
$user->setExpirationSeconds(60*Zend_Registry::get('configGlobal')->session->lifetime);
33-
$this->userSession=$user;
34-
$this->view->recentItems=array();
35-
if ($user->Dao!=null)
36-
{
37-
$this->logged=true;
38-
$this->view->logged=true;
39-
$this->view->userDao=$user->Dao;
40-
$cookieData = $this->getRequest()->getCookie('recentItems'.$this->userSession->Dao->getKey());
28+
Zend_Loader::loadClass( "UserDao", BASE_PATH . '/core/models/dao');
29+
Zend_Loader::loadClass( "ItemDao", BASE_PATH . '/core/models/dao');
30+
31+
if (isset($_POST['sid']))
32+
{
33+
Zend_Session::setId($_POST['sid']);
34+
}
35+
Zend_Session::start();
36+
$user=new Zend_Session_Namespace('Auth_User');
37+
$user->setExpirationSeconds(60*Zend_Registry::get('configGlobal')->session->lifetime);
38+
$this->userSession=$user;
4139
$this->view->recentItems=array();
42-
if(isset($cookieData))
40+
if ($user->Dao!=null)
41+
{
42+
$this->logged=true;
43+
$this->view->logged=true;
44+
$this->view->userDao=$user->Dao;
45+
$cookieData = $this->getRequest()->getCookie('recentItems'.$this->userSession->Dao->getKey());
46+
$this->view->recentItems=array();
47+
if(isset($cookieData))
48+
{
49+
$this->view->recentItems= unserialize($cookieData);
50+
}
51+
}
52+
else
4353
{
44-
$this->view->recentItems= unserialize($cookieData);
45-
}
54+
$this->view->logged=false;
55+
$this->logged=false;
56+
}
4657
}
4758
else
4859
{
60+
$this->userSession=null;
4961
$this->view->logged=false;
5062
$this->logged=false;
5163
}

core/Bootstrap.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ protected function _initDoctype()
2323
*/
2424
protected function _initConfig()
2525
{
26-
Zend_Loader::loadClass( "UserDao", BASE_PATH . '/core/models/dao');
27-
Zend_Loader::loadClass( "ItemDao", BASE_PATH . '/core/models/dao');
28-
if (isset($_POST['sid']))
29-
{
30-
Zend_Session::setId($_POST['sid']);
31-
}
32-
Zend_Session::start();
26+
3327
$configGlobal = new Zend_Config_Ini(APPLICATION_CONFIG,'global',true);
3428
if(isset($_COOKIE['lang']))
3529
{

core/controllers/UserController.php

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class UserController extends AppController
88
public $_daos=array(
99
'User','Folder','Folderpolicygroup','Folderpolicyuser','Group'
1010
);
11-
public $_components=array('Date');
11+
public $_components=array('Date','Filter');
1212
public $_forms=array(
1313
'User'
1414
);
@@ -45,7 +45,7 @@ function registerAction()
4545
throw new Zend_Exception("User already exists.");
4646
}
4747

48-
$this->userSession->Dao=$this->User->createUser($form->getValue('email'),$form->getValue('password1'),$form->getValue('firstname'),$form->getValue('lastname'));
48+
$this->userSession->Dao=$this->User->createUser(trim($form->getValue('email')),$form->getValue('password1'),trim($form->getValue('firstname')),trim($form->getValue('lastname')));
4949

5050
$this->_redirect("/");
5151
}
@@ -74,7 +74,6 @@ function loginAction()
7474
$passwordPrefix=Zend_Registry::get('configGlobal')->password->prefix;
7575
if($userDao != false && md5($passwordPrefix.$form->getValue('password')) == $userDao->getPassword())
7676
{
77-
$this->userSession->Dao=$userDao;
7877
$remember=$form->getValue('remerberMe');
7978

8079
if(isset($remember) && $remember == 1)
@@ -86,8 +85,12 @@ function loginAction()
8685
{
8786
Zend_Session::ForgetMe();
8887
}
88+
Zend_Session::start();
89+
$user=new Zend_Session_Namespace('Auth_User');
90+
$user->setExpirationSeconds(60*Zend_Registry::get('configGlobal')->session->lifetime);
91+
$user->Dao=$userDao;
8992
$url=$form->getValue('url');
90-
$this->userSession->lock();
93+
$user->lock();
9194
$this->getLogger()->info(__METHOD__ . " Log in : " . $userDao->getFullName());
9295
}
9396
}
@@ -174,8 +177,106 @@ public function settingsAction()
174177
}
175178
$this->_helper->layout->disableLayout();
176179

180+
$accountForm=$this->Form->User->createAccountForm($this->userSession->Dao->getFirstname(),$this->userSession->Dao->getLastname(),
181+
$this->userSession->Dao->getCompany(),$this->userSession->Dao->getPrivacy());
182+
$this->view->accountForm=$this->getFormAsArray($accountForm);
183+
184+
if($this->_request->isPost())
185+
{
186+
$this->_helper->viewRenderer->setNoRender();
187+
$submitPassword=$this->_getParam('modifyPassword');
188+
$modifyAccount=$this->_getParam('modifyAccount');
189+
$modifyPicture=$this->_getParam('modifyPicture');
190+
if(isset($submitPassword)&&$this->logged)
191+
{
192+
$oldPass=$this->_getParam('oldPassword');
193+
$newPass=$this->_getParam('newPassword');
194+
$passwordPrefix=Zend_Registry::get('configGlobal')->password->prefix;
195+
$userDao=$this->User->load($this->userSession->Dao->getKey());
196+
if($userDao != false && md5($passwordPrefix.$oldPass) == $userDao->getPassword())
197+
{
198+
$userDao->setPassword(md5($passwordPrefix.$newPass));
199+
$this->User->save($userDao);
200+
$this->userSession->Dao=$userDao;
201+
echo JsonComponent::encode(array(true,$this->t('Changes saved')));
202+
}
203+
else
204+
{
205+
echo JsonComponent::encode(array(false,$this->t('The old password is incorrect')));
206+
}
207+
}
208+
209+
if(isset($modifyAccount)&&$this->logged)
210+
{
211+
$firtname=trim($this->_getParam('firstname'));
212+
$lastname=trim($this->_getParam('lastname'));
213+
$company=trim($this->_getParam('company'));
214+
$privacy=$this->_getParam('privacy');
215+
216+
$userDao=$this->User->load($this->userSession->Dao->getKey());
217+
218+
if(!isset($privacy)||($privacy!=MIDAS_USER_PRIVATE&&$privacy!=MIDAS_USER_PUBLIC))
219+
{
220+
echo JsonComponent::encode(array(false,'Error'));
221+
}
222+
if(!isset($lastname)||!isset($firtname)||empty($lastname)||empty($firtname))
223+
{
224+
echo JsonComponent::encode(array(false,'Error'));
225+
}
226+
$userDao->setFirstname($firtname);
227+
$userDao->setLastname($lastname);
228+
if(isset($company))
229+
{
230+
$userDao->setCompany($company);
231+
}
232+
$userDao->setPrivacy($privacy);
233+
$this->User->save($userDao);
234+
$this->userSession->Dao=$userDao;
235+
echo JsonComponent::encode(array(true,$this->t('Changes saved')));
236+
}
237+
if(isset($modifyPicture)&&$this->logged)
238+
{
239+
$upload = new Zend_File_Transfer();
240+
$upload->receive();
241+
$path=$upload->getFileName();
242+
if (!empty($path)&& file_exists($path) && $upload->getFileSize() > 0)
243+
{
244+
//create thumbnail
245+
$thumbnailCreator=$this->Component->Filter->getFilter('ThumbnailCreator');
246+
$thumbnailCreator->inputFile = $path;
247+
$thumbnailCreator->inputName = basename($path);
248+
$hasThumbnail = $thumbnailCreator->process();
249+
$thumbnail_output_file = $thumbnailCreator->outputFile;
250+
if($hasThumbnail&& file_exists($thumbnail_output_file))
251+
{
252+
$userDao=$this->User->load($this->userSession->Dao->getKey());
253+
$oldThumbnail=$userDao->getThumbnail();
254+
if(!empty($oldThumbnail))
255+
{
256+
unlink(BASE_PATH.'/'.$oldThumbnail);
257+
}
258+
$userDao->setThumbnail(substr($thumbnail_output_file, strlen(BASE_PATH)+1));
259+
$this->User->save($userDao);
260+
$this->userSession->Dao=$userDao;
261+
echo JsonComponent::encode(array(true,$this->t('Changes saved'),$userDao->getThumbnail()));
262+
}
263+
else
264+
{
265+
echo JsonComponent::encode(array(false,'Error'));
266+
}
267+
}
268+
}
269+
}
270+
271+
$this->view->thumbnail=$this->userSession->Dao->getThumbnail();
272+
$this->view->jsonSettings=array();
273+
$this->view->jsonSettings['accountErrorFirstname']=$this->t('Please set your firstname');
274+
$this->view->jsonSettings['accountErrorLastname']=$this->t('Please set your lastname');
275+
$this->view->jsonSettings['passwordErrorShort']=$this->t('Password too short');
276+
$this->view->jsonSettings['passwordErrorMatch']=$this->t('The passwords are not the same');
277+
$this->view->jsonSettings=JsonComponent::encode($this->view->jsonSettings);
177278
}
178-
279+
179280
/** user page action*/
180281
public function userpageAction()
181282
{

core/controllers/forms/UserForm.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ public function createRegisterForm()
8383

8484
return $form;
8585
}
86-
86+
8787

8888
/** acount form */
89-
public function createAccountForm()
89+
public function createAccountForm($firstname_value=null,$lastname_value=null,$company_value=null,$policy_value=null)
9090
{
9191
$form = new Zend_Form;
9292
$form->setAction($this->webroot.'/user/settings')
@@ -104,14 +104,39 @@ public function createAccountForm()
104104
->addValidator('NotEmpty', true)
105105
->addValidator(new Zend_Validate_Alnum());
106106

107-
$compagny = new Zend_Form_Element_Text('lastname');
108-
$compagny
107+
$company = new Zend_Form_Element_Text('company');
108+
$company
109109
->addValidator(new Zend_Validate_Alnum());
110110

111-
$submit = new Zend_Form_Element_Submit('submit');
112-
$submit ->setLabel($this->t("Save"));
111+
$submit = new Zend_Form_Element_Submit('modifyAccount');
112+
$submit ->setLabel($this->t("Modify"));
113+
114+
$privacy = new Zend_Form_Element_Radio('privacy');
115+
$privacy->addMultiOptions( array(
116+
MIDAS_USER_PUBLIC => $this->t("Public"),
117+
MIDAS_USER_PRIVATE => $this->t("Private"),
118+
))
119+
->setRequired(true)
120+
->setValue(MIDAS_COMMUNITY_PUBLIC);
121+
122+
if($firstname_value!=null)
123+
{
124+
$firstname->setValue($firstname_value);
125+
}
126+
if($lastname_value!=null)
127+
{
128+
$lastname->setValue($lastname_value);
129+
}
130+
if($company_value!=null)
131+
{
132+
$company->setValue($company_value);
133+
}
134+
if($policy_value!=null)
135+
{
136+
$privacy->setValue($policy_value);
137+
}
113138

114-
$form->addElements(array($firstname,$lastname,$compagny,$submit));
139+
$form->addElements(array($firstname,$lastname,$company,$privacy,$submit));
115140

116141
return $form;
117142
}

core/layouts/layout.phtml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,10 @@
7070
if($this->logged)
7171
{
7272
echo '
73-
<b><a href="'.$this->webroot.'/user/'.$this->userDao->getUserId().'" >'.$this->userDao->getFullName().' <img class="arrowUser" src="'.$this->webroot.'/public/images/icons/arrow-user.gif" alt ="" /></a> </b>
73+
<b><a id="topUserName" href="'.$this->webroot.'/user/'.$this->userDao->getUserId().'" >'.$this->userDao->getFullName().' <img class="arrowUser" src="'.$this->webroot.'/public/images/icons/arrow-user.gif" alt ="" /> </a> </b>
7474
<ul>
7575
<li onclick="location.replace(\''.$this->webroot.'/user/userpage\');"><a>'.$this->t('My Page').'</a></li>
7676
<li class="myAccountLink"><a>'.$this->t('My Account').'</a></li>
77-
<li class="settingsLink"><a>'.$this->t('Settings').'</a></li>
7877
<li class="modulesLink"><a>'.$this->t('Modules').'</a></li>';
7978
if($this->userDao->isAdmin())
8079
{

core/models/base/UserModelBase.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function __construct()
1717
'creation' => array('type' => MIDAS_DATA),
1818
'folder_id' => array('type' => MIDAS_DATA),
1919
'admin' => array('type' => MIDAS_DATA),
20+
'privacy' => array('type' => MIDAS_DATA),
2021
'publicfolder_id' => array('type' => MIDAS_DATA),
2122
'privatefolder_id' => array('type' => MIDAS_DATA),
2223
'folder' => array('type' => MIDAS_MANY_TO_ONE, 'model' => 'Folder', 'parent_column' => 'folder_id', 'child_column' => 'folder_id'),
@@ -34,11 +35,6 @@ abstract function getByEmail($email);
3435
abstract function getByUser_id($userid);
3536
abstract function getUserCommunities($userDao);
3637

37-
/** don't use save*/
38-
public function save($dao)
39-
{
40-
throw new Zend_Exception("Use createUser method.");
41-
}
4238

4339
/** create user */
4440
public function createUser($email,$password,$firstname,$lastname,$admin=0)

core/translation/fr-main.csv

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Items;Documents
7979
Folder;Repertoire
8080
Folders;Repertoires
8181
User;Utilisateur
82+
user;utilisateur
8283
Users;Utilisateurs
8384
Size;Taille
8485
Modified;Modifi�
@@ -121,5 +122,21 @@ Leave the community;Quitter la communaut
121122
Manage;G�rer
122123
Move/Copy Item.;D�placer/Copier Document.
123124
Copy Item.;Copier Document.
125+
item;document
124126
My Files;Mes Fichiers
125-
Please select a folder.;S�lectionnez un r�pertoire.
127+
Please select a folder.;S�lectionnez un r�pertoire.
128+
community;communaut�
129+
communities;communaut�s
130+
Modify my password; Modifier mon mot de passe
131+
My old password;Mon ancien mot de passe
132+
My new password;Mon nouveau mot de passe
133+
Confirmation;Confirmation
134+
Modify;Modifier
135+
Changes saved; Changements sauv�s
136+
The old password is incorrect;L'ancien mot de passe est incorrecte
137+
The passwords are not the same;Les mot des passes sont diff�rents
138+
Modify my information;Modifier mes informations
139+
Modify my picture;Modifier mon image
140+
Choose a picture;Choisir une image
141+
Modifier Picture;Modifier image
142+
My picture;Mon image

core/views/element/feed.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
$thumbnail=$feed->getUser()->getThumbnail();
3434
if(!empty($thumbnail))
3535
{
36-
echo "<img src='{$view->webroot}data/thumbnail/{$thumbnail}' alt=''/>";
36+
echo "<img class='thumbnailSmall' src='{$view->webroot}/{$thumbnail}' alt=''/>";
3737
}
3838
else
3939
{
40-
echo "<img src='{$view->webroot}/public/images/icons/unknownUser.png' alt=''/>";
40+
echo "<img class='thumbnailSmall' src='{$view->webroot}/public/images/icons/unknownUser.png' alt=''/>";
4141
}
4242
echo "</div>";
4343
echo "<div class='feedInfo'>";

core/views/feed/index.phtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ MIDAS integrates multimedia server technology with Kitware's open-source data an
3737
<h1>Stats</h1>
3838
<?php
3939
echo "<ul>";
40-
echo " <li>{$this->nUsers} user".(($this->nUsers>1)?'s':'')."</li>";
41-
echo " <li>{$this->nCommunities} ".(($this->nCommunities>1)?'communities':'community')."</li>";
42-
echo " <li>{$this->nItems} item".(($this->nItems>1)?'s':'')."</li>";
40+
echo " <li>{$this->nUsers} {$this->t('user')}".(($this->nUsers>1)?'s':'')."</li>";
41+
echo " <li>{$this->nCommunities} ".(($this->nCommunities>1)?"{$this->t('communities')}":"{$this->t('community')}")."</li>";
42+
echo " <li>{$this->nItems} {$this->t('item')}".(($this->nItems>1)?'s':'')."</li>";
4343
echo "</ul>";
4444
?>
4545
</div>

0 commit comments

Comments
 (0)