@@ -8,7 +8,7 @@ class UserController extends AppController
8
8
public $ _daos =array (
9
9
'User ' ,'Folder ' ,'Folderpolicygroup ' ,'Folderpolicyuser ' ,'Group '
10
10
);
11
- public $ _components =array ('Date ' );
11
+ public $ _components =array ('Date ' , ' Filter ' );
12
12
public $ _forms =array (
13
13
'User '
14
14
);
@@ -45,7 +45,7 @@ function registerAction()
45
45
throw new Zend_Exception ("User already exists. " );
46
46
}
47
47
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 ' ) ));
49
49
50
50
$ this ->_redirect ("/ " );
51
51
}
@@ -74,7 +74,6 @@ function loginAction()
74
74
$ passwordPrefix =Zend_Registry::get ('configGlobal ' )->password ->prefix ;
75
75
if ($ userDao != false && md5 ($ passwordPrefix .$ form ->getValue ('password ' )) == $ userDao ->getPassword ())
76
76
{
77
- $ this ->userSession ->Dao =$ userDao ;
78
77
$ remember =$ form ->getValue ('remerberMe ' );
79
78
80
79
if (isset ($ remember ) && $ remember == 1 )
@@ -86,8 +85,12 @@ function loginAction()
86
85
{
87
86
Zend_Session::ForgetMe ();
88
87
}
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 ;
89
92
$ url =$ form ->getValue ('url ' );
90
- $ this -> userSession ->lock ();
93
+ $ user ->lock ();
91
94
$ this ->getLogger ()->info (__METHOD__ . " Log in : " . $ userDao ->getFullName ());
92
95
}
93
96
}
@@ -174,8 +177,106 @@ public function settingsAction()
174
177
}
175
178
$ this ->_helper ->layout ->disableLayout ();
176
179
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 );
177
278
}
178
-
279
+
179
280
/** user page action*/
180
281
public function userpageAction ()
181
282
{
0 commit comments