00001 <?php
00009 class Dsao_Model_User_Profile extends Dsao_Model_Abstract
00010 {
00014 protected $_request = null;
00015
00019 protected $_user = null;
00020
00028 protected function _editEmailAddress()
00029 {
00030
00031 if (!$this->_request || !$this->_user)
00032 {
00033 return false;
00034 }
00035
00036
00037 $emailAddress = strtolower(trim
00038 ($this->_request->getPost('emailAddress')));
00039 $emailAddressVerification = strtolower(trim($this->_request->getPost
00040 ('emailAddressVerification')));
00041 $password = $this->_request->getPost('password');
00042
00043
00044 $validator = new Zend_Validate_EmailAddress();
00045
00046
00047
00048 if (!$emailAddress || $emailAddress == $this->_user->emailAddress)
00049 {
00050 $this->getLog()->err(null, __METHOD__);
00051 }
00052
00053
00054 else if ($emailAddress != $emailAddressVerification)
00055 {
00056 $this->getLog()->err('user_register_email_error_nonconform', __METHOD__);
00057 }
00058
00059
00060 else if (!$password)
00061 {
00062 $this->getLog()->err
00063 ('user_profile_edit_error_password_missing', __METHOD__);
00064 }
00065
00066
00067 else if (md5($password) != $this->_user->password)
00068 {
00069 $this->getLog()->err('user_profile_edit_error_password_wrong', __METHOD__);
00070 }
00071
00072
00073 else if (!$validator->isValid($emailAddress))
00074 {
00075 $this->getLog()->err('user_register_email_error_invalid', __METHOD__);
00076 }
00077
00078
00079 else if (Dsao_Registry::getModel('User_Register')->isUniqueEmailAddress($emailAddress))
00080 {
00081 $this->getLog()->err('user_register_email_error_not_unique', __METHOD__);
00082 }
00083
00084
00085 if ($this->getLog()->hasError(__METHOD__))
00086 {
00087 return false;
00088 }
00089
00090
00091 $this->_user->emailAddress = $emailAddress;
00092
00093 return true;
00094 }
00095
00104 protected function _editPassword()
00105 {
00106
00107 if (!$this->_request || !$this->_user)
00108 {
00109 return false;
00110 }
00111
00112
00113 $password = $this->_request->getPost('password');
00114 $passwordNew = $this->_request->getPost('passwordNew');
00115 $passwordNewVerification = $this->_request->getPost
00116 ('passwordNewVerification');
00117
00118
00119 $validator = new Dsao_Validate_Password();
00120
00121
00122
00123 if (!$passwordNew || md5($passwordNew) == $this->_user->password)
00124 {
00125 $this->getLog()->err(null, __METHOD__);
00126 }
00127
00128
00129 else if ($passwordNew != $passwordNewVerification)
00130 {
00131 $this->getLog()->err
00132 ('user_register_password_error_nonconform', __METHOD__);
00133 }
00134
00135
00136 else if (!$password)
00137 {
00138 $this->getLog()->err
00139 ('user_profile_edit_error_password_missing', __METHOD__);
00140 }
00141
00142
00143 else if (md5($password) != $this->_user->password)
00144 {
00145 $this->getLog()->err('user_profile_edit_error_password_wrong', __METHOD__);
00146 }
00147
00148
00149 else if (!$validator->isValid($passwordNew))
00150 {
00151 $this->getLog()->err('user_register_password_error_invalid', __METHOD__);
00152 }
00153
00154
00155 if ($this->getLog()->hasError(__METHOD__))
00156 {
00157 return false;
00158 }
00159
00160
00161 $this->_user->password = Dsao_Hash_Password::fromText($passwordNew)
00162 ->getHash();
00163
00164 return true;
00165 }
00166
00179 protected function _editUserData()
00180 {
00181
00182 $changedCols = array();
00183
00184
00185 $invalidCols = array();
00186
00187
00188 $userDataFilters = array();
00189
00190
00191 $userDataFilters['alphanumeric'] = new Dsao_Filter_Input
00192 (
00193 array
00194 (
00195 '*' => 'StringTrim',
00196 ),
00197 null,
00198 array
00199 (
00200 'contactAim' => $this->_request->getPost('contactAim'),
00201 'contactSkype' => $this->_request->getPost('contactSkype'),
00202 'layout' => $this->_request->getPost('layout'),
00203 'personalBirthday' => $this->_request->getPost('personalBirthday'),
00204 'personalCity' => $this->_request->getPost('personalCity'),
00205 'personalCountry' => $this->_request->getPost('personalCountry'),
00206 'personalForename' => $this->_request->getPost('personalForename'),
00207 'personalStreet' => $this->_request->getPost('personalStreet'),
00208 'personalSurname' => $this->_request->getPost('personalSurname'),
00209 )
00210 );
00211
00212
00213
00214 $userDataFilters['emailAddresses'] = new Dsao_Filter_Input
00215 (
00216 array
00217 (
00218 '*' => 'StringTrim',
00219 ),
00220 array
00221 (
00222 '*' => array
00223 (
00224 'EmailAddress',
00225 'allowEmpty' => true,
00226 ),
00227 ),
00228 array
00229 (
00230 'contactJabber' => $this->_request->getPost('contactJabber'),
00231 'contactMsn' => $this->_request->getPost('contactMsn'),
00232 )
00233 );
00234
00235
00236
00237 $userDataFilters['flags'] = new Dsao_Filter_Input
00238 (
00239 array
00240 (
00241 '*' => 'Int',
00242 ),
00243 null,
00244 array
00245 (
00246 'javascriptLoadFiles' => $this->_request->getPost
00247 ('javascriptLoadFiles'),
00248 'profileShowContactData' => $this->_request->getPost
00249 ('showContactData'),
00250 'profileShowEmailAddress' => $this->_request->getPost
00251 ('showEmailAddress'),
00252 'profileShowPersonalData' => $this->_request->getPost
00253 ('showPersonalData'),
00254 'scrollMailNotification' => $this->_request->getPost
00255 ('scrollMailNotification'),
00256 )
00257 );
00258
00259
00260 $userDataFilters['numeric'] = new Dsao_Filter_Input
00261 (
00262 array
00263 (
00264 '*' => 'StringTrim',
00265 ),
00266 array
00267 (
00268 '*' => array
00269 (
00270 'Digits',
00271 'allowEmpty' => true,
00272 ),
00273 ),
00274 array
00275 (
00276 'contactIcq' => $this->_request->getPost('contactIcq'),
00277 'personalPostcode' => $this->_request->getPost('personalPostcode'),
00278 )
00279 );
00280
00281
00282 foreach ($userDataFilters as $userDataFilter)
00283 {
00284
00285 if ($userDataFilter->hasInvalid())
00286 {
00287
00288 foreach ($userDataFilter->getUnknown() as $col => $formValue)
00289 {
00290 $invalidCols[] = self::underscore($col);
00291 }
00292 }
00293
00294
00295 foreach ($userDataFilter->getEscaped() as $col => $formValue)
00296 {
00297
00298 if ($formValue == $this->_user->$col)
00299 {
00300 continue;
00301 }
00302
00303
00304 $this->_user->$col = $formValue;
00305
00306
00307 $changedCols[] = $col;
00308 }
00309 }
00310
00311 return array(
00312 'changedCols' => $changedCols,
00313 'invalidCols' => $invalidCols);
00314 }
00315
00327 public function editProfile(Zend_Controller_Request_Http $request, Dsao_User $user)
00328 {
00329
00330 $this->_request = $request;
00331 $this->_user = $user->setReadOnly(false);
00332
00333
00334 $cols = $this->_editUserData();
00335
00336
00337 if ($this->_editEmailAddress())
00338 {
00339 $cols['changedCols'][] = 'emailAddress';
00340 }
00341
00342
00343 if ($this->_editPassword())
00344 {
00345 $cols['changedCols'][] = 'password';
00346 }
00347
00348
00349 if ($cols['changedCols'])
00350 {
00351
00352 $this->_user->update($cols['changedCols'])->setReserialize(true);
00353 }
00354
00355
00356 $this->_user->setValid()->setReadOnly();
00357
00358
00359 $this->_request = null;
00360 $this->_user = null;
00361
00362 return $cols;
00363 }
00364 }