File indexing completed on 2024-12-22 05:33:34
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 **/ 0023 class SettingsController extends Local_Controller_Action_DomainSwitch 0024 { 0025 0026 protected $_auth; 0027 protected $_memberId; 0028 /** @var Zend_Db_Table */ 0029 protected $_memberTable; 0030 /** @var Zend_Db_Table_Row */ 0031 protected $_memberSettings; 0032 0033 protected $_projectTable; 0034 /** @var Zend_Db_Table_Row */ 0035 protected $_mainproject; 0036 0037 private $htmlVerifier = '<meta name="ocs-site-verification" content="?" />'; 0038 0039 public function init() 0040 { 0041 parent::init(); 0042 $this->getResponse()->clearHeaders(array('Expires', 'Pragma', 'Cache-Control'))->setHeader('Pragma', 'no-cache', 0043 true) 0044 ->setHeader('Cache-Control', 'private, no-cache, must-revalidate', true); 0045 0046 $this->_auth = Zend_Auth::getInstance(); 0047 $this->_memberId = $this->_auth->getStorage()->read()->member_id; 0048 $this->_memberTable = new Default_Model_DbTable_Member(); 0049 0050 $showMember = $this->_memberTable->find($this->_memberId)->current(); 0051 $this->view->member = $showMember; 0052 $this->_memberSettings = $showMember; 0053 0054 $this->_projectTable = new Default_Model_DbTable_Project(); 0055 0056 // init default main project 0057 $main_project_id = $showMember->main_project_id; 0058 $mainproject_rowset = $this->_projectTable->find($main_project_id); 0059 $this->_mainproject = $this->view->mainproject = $mainproject_rowset->current(); 0060 0061 0062 $action = $this->getRequest()->getActionName(); 0063 $title = ''; 0064 if ($action == 'index') { 0065 $title = 'settings'; 0066 } else { 0067 $title = $action; 0068 } 0069 $this->view->headTitle($title . ' - ' . $this->getHeadTitle(), 'SET'); 0070 } 0071 0072 public function indexAction() 0073 { 0074 $this->view->member = $this->_memberSettings; 0075 $memberSettings = $this->_memberSettings->toArray(); 0076 0077 $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); 0078 $paypalValidStatus = $paypalValidStatusTable->find($this->_memberSettings->paypal_valid_status)->current(); 0079 $this->view->paypal_valid_status = $paypalValidStatus; 0080 0081 $this->view->profileform = $this->formProfile(); 0082 $this->view->profileform->populate($memberSettings); 0083 $this->view->profileform->aboutme->setValue($this->_mainproject->description); 0084 0085 $this->view->accounts = $this->formConnectedAccounts(); 0086 $this->view->accounts->populate($memberSettings); 0087 0088 $this->view->github = $this->formGithub(); 0089 $this->view->github->populate($memberSettings); 0090 0091 $this->view->pictureform = $this->formProfilePicture(); 0092 $this->view->pictureform->populate($memberSettings); 0093 0094 $this->view->pictureformbg = $this->formProfilePictureBackground(); 0095 $this->view->pictureformbg->populate($memberSettings); 0096 0097 $this->view->passwordform = $this->formPassword(); 0098 0099 $websiteOwner = new Local_Verification_WebsiteOwner(); 0100 $linkWebsite = stripslashes($this->_memberSettings->link_website); 0101 $this->view->homepageform = 0102 $this->formHomepage($linkWebsite, $websiteOwner->generateAuthCode($linkWebsite), 0103 $this->_memberSettings->validated); 0104 0105 $this->view->newsletterform = $this->formNewsletter(stripslashes($this->_memberSettings->newsletter)); 0106 0107 $this->view->paymentform = $this->formPayment(); 0108 $this->view->paymentform->populate($memberSettings); 0109 } 0110 0111 /** 0112 * @return Default_Form_Settings 0113 * @throws Zend_Form_Exception 0114 */ 0115 private function formProfile() 0116 { 0117 $form = new Default_Form_Settings(); 0118 $form->setMethod("POST")->setAttrib("id", "settingsProfileForm")->setAction('/settings/saveprofile'); 0119 0120 $userNameLength = new Zend_Validate_StringLength(array('min' => 4, 'max' => 35)); 0121 $username = 0122 $form->createElement('text', 0123 'username')->setLabel("Username:")->setRequired(false)->setFilters(array('StringTrim')) 0124 ->addValidator($userNameLength)->setAttrib('readonly', 'true')->setDecorators(array( 0125 'ViewHelper', 0126 'Label', 0127 'Errors', 0128 array( 0129 'ViewScript', 0130 array( 0131 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0132 'placement' => false 0133 ) 0134 ) 0135 )); 0136 $form->addElement($username); 0137 0138 $firstname = $form->createElement('text', 0139 'firstname')->setLabel("First Name:")->setRequired(false)->removeDecorator('HtmlTag') 0140 ->setFilters(array('StringTrim'))->setDecorators(array( 0141 'ViewHelper', 0142 'Label', 0143 'Errors', 0144 array( 0145 'ViewScript', 0146 array( 0147 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0148 'placement' => false 0149 ) 0150 ) 0151 )); 0152 $form->addElement($firstname); 0153 0154 $lastname = $form->createElement('text', 0155 'lastname')->setLabel("Last Name:")->setRequired(false)->removeDecorator('HtmlTag') 0156 ->setFilters(array('StringTrim'))->setDecorators(array( 0157 'ViewHelper', 0158 'Label', 0159 'Errors', 0160 array( 0161 'ViewScript', 0162 array( 0163 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0164 'placement' => false 0165 ) 0166 ) 0167 )); 0168 $form->addElement($lastname); 0169 0170 $city = $form->createElement('text', 0171 'city')->setLabel("City:")->setRequired(false)->setFilters(array('StringTrim')) 0172 ->removeDecorator('HtmlTag')->setDecorators(array( 0173 'ViewHelper', 0174 'Label', 0175 'Errors', 0176 array( 0177 'ViewScript', 0178 array( 0179 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0180 'placement' => false 0181 ) 0182 ) 0183 )); 0184 $form->addElement($city); 0185 0186 $country = $form->createElement('text', 0187 'country')->setLabel("Country:")->setRequired(false)->setFilters(array('StringTrim')) 0188 ->removeDecorator('HtmlTag')->setDecorators(array( 0189 'ViewHelper', 0190 'Label', 0191 'Errors', 0192 array( 0193 'ViewScript', 0194 array( 0195 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0196 'placement' => false 0197 ) 0198 ) 0199 )); 0200 $form->addElement($country); 0201 0202 $about = $form->createElement('textarea', 0203 'aboutme')->setLabel('About me:')->setRequired(false)->setAttrib('class', 'about') 0204 ->setDecorators(array( 0205 'ViewHelper', 0206 'Label', 0207 'Errors', 0208 array( 0209 'ViewScript', 0210 array( 0211 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0212 'placement' => false 0213 ) 0214 ) 0215 )); 0216 $form->addElement($about); 0217 0218 return $form; 0219 } 0220 0221 0222 /** 0223 * Forms 0224 */ 0225 0226 /** 0227 * @return Default_Form_Settings 0228 * @throws Zend_Form_Exception 0229 */ 0230 private function formConnectedAccounts() 0231 { 0232 $form = new Default_Form_Settings(); 0233 $form->setMethod("POST")->setAttrib("id", "settingsConnectedAccounts")->setAction('/settings/accounts'); 0234 0235 $facebook = $form->createElement('text', 'link_facebook')->setLabel("Facebook Profile:")->setRequired(false) 0236 ->removeDecorator('HtmlTag')->setDecorators(array( 0237 'ViewHelper', 0238 'Label', 0239 'Errors', 0240 array( 0241 'ViewScript', 0242 array( 0243 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0244 'placement' => false 0245 ) 0246 ) 0247 )); 0248 $facebook->addValidator(new Local_Validate_PartialUrl()); 0249 $form->addElement($facebook); 0250 0251 $twitter = 0252 $form->createElement('text', 0253 'link_twitter')->setLabel("Twitter Profile:")->setRequired(false)->removeDecorator('HtmlTag') 0254 ->setDecorators(array( 0255 'ViewHelper', 0256 'Label', 0257 'Errors', 0258 array( 0259 'ViewScript', 0260 array( 0261 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0262 'placement' => false 0263 ) 0264 ) 0265 )); 0266 $twitter->addValidator(new Local_Validate_PartialUrl); 0267 $form->addElement($twitter); 0268 0269 $github = 0270 $form->createElement('text', 0271 'link_github')->setLabel("GitHub Profile:")->setRequired(false)->removeDecorator('HtmlTag') 0272 ->setDecorators(array( 0273 'ViewHelper', 0274 'Label', 0275 'Errors', 0276 array( 0277 'ViewScript', 0278 array( 0279 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0280 'placement' => false 0281 ) 0282 ) 0283 )); 0284 $github->addValidator(new Local_Validate_PartialUrl); 0285 $form->addElement($github); 0286 0287 return $form; 0288 } 0289 0290 /** 0291 * @return Default_Form_Settings 0292 * @throws Zend_Form_Exception 0293 */ 0294 private function formGithub() 0295 { 0296 $form = new Default_Form_Settings(); 0297 $form->setMethod("POST")->setAttrib("id", "settingsGithub")->setAction('/settings/github'); 0298 0299 $github = new Default_Form_Element_UsernameGithub('link_github'); 0300 $github->setLabel("GitHub Profile:")->setRequired(false)->removeDecorator('HtmlTag')->setDecorators(array( 0301 'ViewHelper', 0302 'Label', 0303 'Errors', 0304 array( 0305 'ViewScript', 0306 array( 0307 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0308 'placement' => false 0309 ) 0310 ) 0311 )); 0312 $form->addElement($github); 0313 0314 $token = new Default_Form_Element_TokenGithub('token_github'); 0315 $token->setLabel("GitHub Access Token:")->setRequired(false)->removeDecorator('HtmlTag')->setDecorators(array( 0316 'ViewHelper', 0317 'Label', 0318 'Errors', 0319 array( 0320 'ViewScript', 0321 array( 0322 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0323 'placement' => false 0324 ) 0325 ) 0326 )); 0327 $form->addElement($token); 0328 0329 return $form; 0330 } 0331 0332 /** 0333 * @return Default_Form_Settings 0334 * @throws Zend_File_Transfer_Exception 0335 * @throws Zend_Form_Exception 0336 */ 0337 private function formProfilePicture() 0338 { 0339 $form = new Default_Form_Settings(); 0340 $form->setMethod("POST")->setAttrib("id", "settingsPictureForm")->setAction('/settings/picture') 0341 ->setAttrib('enctype', 'multipart/form-data'); 0342 0343 $hiddenProfilePicture = $form->createElement('hidden', 'profile_image_url')->setDecorators(array( 0344 'ViewHelper', 0345 array( 0346 'ViewScript', 0347 array( 0348 'viewScript' => 'settings/viewscripts/flatui_hidden_image.phtml', 0349 'placement' => false 0350 ) 0351 ) 0352 ))->setAttrib('data-target', '#profile-picture-preview'); 0353 0354 $form->addElement($hiddenProfilePicture); 0355 0356 $imageTable = new Default_Model_DbTable_Image(); 0357 $productPicture = 0358 $form->createElement('file', 0359 'profile_picture_upload')->setDisableLoadDefaultDecorators(true)->setLabel('Profile Picture') 0360 ->setRequired(false)->setDecorators(array( 0361 'File', 0362 array( 0363 'ViewScript', 0364 array( 0365 'viewScript' => 'settings/viewscripts/flatui_profile_image.phtml', 0366 'placement' => false 0367 ) 0368 ) 0369 0370 ))->setAttrib('class', 'product-picture') 0371 ->setAttrib('onchange', 'ImagePreview.previewImage(this, \'profile-picture-preview\');') 0372 ->setTransferAdapter(new Local_File_Transfer_Adapter_Http())->setMaxFileSize(2097152)->addValidator('Count', 0373 false, 1) 0374 ->addValidator('Size', false, array('min' => '5kB', 'max' => '2MB')) 0375 ->addValidator('Extension', false, $imageTable->getAllowedFileExtension())->addValidator('ImageSize', 0376 false, array( 0377 'minwidth' => 20, 0378 'maxwidth' => 1024, 0379 'minheight' => 20, 0380 'maxheight' => 1024 0381 ))->addValidator('MimeType', false, $imageTable->getAllowedMimeTypes()); 0382 0383 $form->addElement($productPicture); 0384 0385 $facebook_username = $form->createElement('text', 0386 'facebook_username')->setLabel("From Facebook Profile:")->setRequired(false) 0387 ->removeDecorator('HtmlTag') 0388 ->setAttrib('data-href', 'https://graph.facebook.com/{username}/picture?type=large') 0389 ->setAttrib('data-target', '#profile-picture-preview')->setAttrib('data-src', 0390 'facebook') 0391 ->setAttrib('class', 'avatar')->setDecorators(array( 0392 'ViewHelper', 0393 'Label', 0394 'Errors' 0395 )); 0396 $form->addElement($facebook_username); 0397 0398 $twitter_username = $form->createElement('text', 0399 'twitter_username')->setLabel("From Twitter Profile:")->setRequired(false) 0400 ->removeDecorator('HtmlTag') 0401 ->setAttrib('data-href', 'http://twitter.com/api/users/profile_image/{username}') 0402 ->setAttrib('data-target', '#profile-picture-preview')->setAttrib('data-src', 0403 'twitter') 0404 ->setAttrib('class', 'avatar')->setDecorators(array( 0405 'ViewHelper', 0406 'Label', 0407 'Errors' 0408 )); 0409 $form->addElement($twitter_username); 0410 0411 $gravatar_email = $form->createElement('text', 0412 'gravatar_email')->setLabel("From Gravatar Profile:")->setRequired(false) 0413 ->setAttrib('data-href', 'http://www.gravatar.com/avatar/{username}.jpg') 0414 ->setAttrib('data-target', '#profile-picture-preview')->setAttrib('data-func', 'MD5') 0415 ->setAttrib('data-src', 'gravatar')->setAttrib('class', 'avatar')->setDecorators(array( 0416 'ViewHelper', 0417 'Label', 0418 'Errors' 0419 )); 0420 $form->addElement($gravatar_email); 0421 0422 $hiddenProfilePictureSrc = $form->createElement('hidden', 'profile_img_src')->setDecorators(array( 0423 'ViewHelper' 0424 )); 0425 0426 $form->addElement($hiddenProfilePictureSrc); 0427 0428 return $form; 0429 } 0430 0431 /** 0432 * @return Default_Form_Settings 0433 * @throws Zend_File_Transfer_Exception 0434 * @throws Zend_Form_Exception 0435 */ 0436 private function formProfilePictureBackground() 0437 { 0438 $form = new Default_Form_Settings(); 0439 $form->setMethod("POST")->setAttrib("id", 0440 "settingsPictureBackgroundForm")->setAction('/settings/picturebackground') 0441 ->setAttrib('enctype', 'multipart/form-data'); 0442 0443 $hiddenProfilePicture = $form->createElement('hidden', 'profile_image_url_bg')->setDecorators(array( 0444 'ViewHelper', 0445 array( 0446 'ViewScript', 0447 array( 0448 'viewScript' => 'settings/viewscripts/flatui_hidden_image.phtml', 0449 'placement' => false 0450 ) 0451 ) 0452 ))->setAttrib('data-target', '#profile-picture-bg-preview'); 0453 0454 $form->addElement($hiddenProfilePicture); 0455 0456 $imageTable = new Default_Model_DbTable_Image(); 0457 $productPicture = $form->createElement('file', 0458 'profile_picture_background_upload')->setDisableLoadDefaultDecorators(true) 0459 ->setLabel('Background Picture')->setRequired(false)->setDecorators(array( 0460 'File', 0461 array( 0462 'ViewScript', 0463 array( 0464 'viewScript' => 'settings/viewscripts/flatui_profile_image_background.phtml', 0465 'placement' => false 0466 ) 0467 ) 0468 0469 ))->setAttrib('class', 'product-picture')->setAttrib('onchange', 0470 'ImagePreview.previewImageMember(this, \'profile-picture-background-preview\');') 0471 ->setTransferAdapter(new Local_File_Transfer_Adapter_Http())//->setMaxFileSize(2097152) 0472 ->addValidator('Count', false, 0473 1)//->addValidator('Size', false, array('min' => '5kB', 'max' => '2MB')) 0474 ->addValidator('Extension', false, $imageTable->getAllowedFileExtension()) 0475 ->addValidator('MimeType', false, $imageTable->getAllowedMimeTypes()); 0476 0477 $form->addElement($productPicture); 0478 0479 return $form; 0480 } 0481 0482 /** 0483 * @return Default_Form_Settings 0484 * @throws Zend_Form_Exception 0485 */ 0486 private function formPassword() 0487 { 0488 $form = new Default_Form_Settings(); 0489 $form->setMethod("POST")->setAttrib("id", "settingsPasswordForm")->setAction('/settings/password'); 0490 0491 $passOld = $form->createElement('password', 'passwordOld')->setLabel('Enter old Password:')->setRequired(true) 0492 ->removeDecorator('HtmlTag')->addValidator(new Local_Validate_OldPasswordConfirm())->setDecorators(array( 0493 'ViewHelper', 0494 'Label', 0495 'Errors', 0496 array( 0497 'ViewScript', 0498 array( 0499 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0500 'placement' => false 0501 ) 0502 ) 0503 )); 0504 0505 $pass1 = $form->createElement('password', 'password1')->setLabel('Enter new Password:')->setRequired(true) 0506 ->addValidator(new Zend_Validate_NotEmpty(Zend_Validate_NotEmpty::STRING))->removeDecorator('HtmlTag') 0507 ->setDecorators(array( 0508 'ViewHelper', 0509 'Label', 0510 'Errors', 0511 array( 0512 'ViewScript', 0513 array( 0514 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0515 'placement' => false 0516 ) 0517 ) 0518 )); 0519 0520 $pass2 = $form->createElement('password', 'password2')->setLabel('Re-enter new Password:')->setRequired(true) 0521 ->addValidator(new Zend_Validate_NotEmpty(Zend_Validate_NotEmpty::STRING))->removeDecorator('HtmlTag') 0522 ->setDecorators(array( 0523 'ViewHelper', 0524 'Label', 0525 'Errors', 0526 array( 0527 'ViewScript', 0528 array( 0529 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0530 'placement' => false 0531 ) 0532 ) 0533 )); 0534 0535 $passValid = new Local_Validate_PasswordConfirm($pass2->getValue()); 0536 $pass1->addValidator($passValid); 0537 0538 $form->addElement($passOld)->addElement($pass1)->addElement($pass2); 0539 0540 return $form; 0541 } 0542 0543 /** 0544 * @param string $valHomepage 0545 * @param string $valVerifyKey 0546 * @param bool $isVerified 0547 * 0548 * @return Local_Form 0549 * @throws Zend_Form_Exception 0550 */ 0551 private function formHomepage($valHomepage = '', $valVerifyKey = '', $isVerified = false) 0552 { 0553 0554 $form = new Local_Form(); 0555 $form->setMethod("POST")->setAttrib("id", "settingsHomepageForm")->setAction('/settings/homepage') 0556 ->addPrefixPath('Local_Form_Element_', 'Local/Form/Element/', 'element'); 0557 0558 $homepage = $form->createElement('text', 0559 'link_website')->setLabel("Website:")->setRequired(false)->setValue($valHomepage) 0560 ->addValidator(new Local_Validate_PartialUrl)->setDecorators(array( 0561 'ViewHelper', 0562 'Label', 0563 'Errors', 0564 array( 0565 'ViewScript', 0566 array( 0567 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0568 'placement' => false 0569 ) 0570 ) 0571 )); 0572 if ($isVerified) { 0573 $homepage->setDescription('<div class="image checked"></div>'); 0574 } else { 0575 $homepage->setDescription('<div class="image unchecked"></div>'); 0576 } 0577 $homepage->addDecorators(array( 0578 array('Description', array('tag' => '', 'escape' => false)) 0579 )); 0580 0581 $form->addElement($homepage); 0582 0583 $hash = $form->createElement('hash', 'csrf', array('salt' => 'RumbaSpiess')); 0584 $hash->setDecorators(array('ViewHelper', 'Errors')); 0585 $hash->getValidator('Identical')->setMessage('Your session is outdated. Please reload the page an try again.'); 0586 $form->addElement($hash); 0587 0588 if ('' != $valVerifyKey) { 0589 $value = str_replace('?', $valVerifyKey, $this->htmlVerifier); 0590 $verifyCode = 0591 $form->createElement('note', 0592 'html_verifier')->setValue($value)->removeDecorator('HtmlTag')->removeDecorator('Label'); 0593 $form->addElement($verifyCode); 0594 } 0595 0596 return $form; 0597 } 0598 0599 /** 0600 * @param string $valNewsletter 0601 * 0602 * @return Default_Form_Settings 0603 * @throws Zend_Form_Exception 0604 * @throws Zend_Validate_Exception 0605 */ 0606 private function formNewsletter($valNewsletter = '') 0607 { 0608 $form = new Default_Form_Settings(); 0609 $form->setMethod("POST")->setAttrib("id", "settingsNewsletterForm")->setAction('/settings/newsletter'); 0610 0611 $questionValid = new Zend_Validate_InArray(array('1', '0')); 0612 $questionValid->setMessage('Yes is required!'); 0613 0614 $question = $form->createElement('checkbox', 'newsletter')// ->addValidator($questionValid, true) 0615 ->setRequired(true)->removeDecorator('HtmlTag')->removeDecorator('Label'); 0616 0617 $question->setValue($valNewsletter); 0618 $form->addElement($question); 0619 0620 return $form; 0621 } 0622 0623 /** 0624 * @param string $valPaypalEmail 0625 * @param string $valWalletAddress 0626 * @param string $valDwollaId 0627 * 0628 * @return Default_Form_Settings 0629 * @throws Zend_Form_Exception 0630 * @throws Zend_Validate_Exception 0631 */ 0632 private function formPayment($valPaypalEmail = '', $valWalletAddress = '', $valDwollaId = '') 0633 { 0634 $form = new Default_Form_Settings(); 0635 $form->setMethod("POST")->setAttrib("id", "settingsPaymentForm")->setAction('/settings/payment'); 0636 0637 $mailValidCheck = new Zend_Validate_EmailAddress(); 0638 $mailValidCheck->setMessage('RegisterFormEmailErrNotValid', Zend_Validate_EmailAddress::INVALID) 0639 ->setMessage('RegisterFormEmailErrNotValid', Zend_Validate_EmailAddress::INVALID_FORMAT) 0640 ->setMessage('RegisterFormEmailErrNotValid', Zend_Validate_EmailAddress::INVALID_LOCAL_PART) 0641 ->setMessage("RegisterFormEmailErrWrongHost", Zend_Validate_EmailAddress::INVALID_HOSTNAME) 0642 ->setMessage("RegisterFormEmailErrWrongHost2", Zend_Validate_Hostname::INVALID_HOSTNAME) 0643 ->setMessage("RegisterFormEmailErrHostLocal", Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED) 0644 ->setOptions(array('domain' => true)); 0645 0646 $mailEmpty = new Zend_Validate_NotEmpty(); 0647 $mailEmpty->setMessage('RegisterFormEmailErrEmpty', Zend_Validate_NotEmpty::IS_EMPTY); 0648 0649 $mailValidatorChain = new Zend_Validate(); 0650 $mailValidatorChain->addValidator($mailValidCheck, true); 0651 0652 $mail = $form->createElement('text', 'paypal_mail')->setLabel('Paypal: Email Adress')->setRequired(false) 0653 ->addValidator($mailValidCheck, true)->setDecorators(array( 0654 'ViewHelper', 0655 'Label', 0656 'Errors', 0657 array( 0658 'ViewScript', 0659 array( 0660 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0661 'placement' => false 0662 ) 0663 ) 0664 )); 0665 $mail->setValue($valPaypalEmail); 0666 $form->addElement($mail); 0667 0668 $bitcoinAddress = 0669 $form->createElement('text', 0670 'wallet_address')->setLabel('Bitcoin: Your Public Wallet Address')->setRequired(false) 0671 ->setDecorators(array( 0672 'ViewHelper', 0673 'Label', 0674 'Errors', 0675 array( 0676 'ViewScript', 0677 array( 0678 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0679 'placement' => false 0680 ) 0681 ) 0682 ))->addValidators(array( 0683 array( 0684 'regex', 0685 false, 0686 array( 0687 'pattern' => '/^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$/', 0688 'messages' => 'The Bitcoin Address is not valid.' 0689 ) 0690 ) 0691 )); 0692 $bitcoinAddress->setValue($valWalletAddress); 0693 $form->addElement($bitcoinAddress); 0694 0695 $dwolla = $form->createElement('text', 0696 'dwolla_id')->setLabel('Dwolla: User ID (xxx-xxx-xxxx)')->setRequired(false) 0697 ->setDecorators(array( 0698 'ViewHelper', 0699 'Label', 0700 'Errors', 0701 array( 0702 'ViewScript', 0703 array( 0704 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 0705 'placement' => false 0706 ) 0707 ) 0708 )); 0709 $dwolla->setValue($valDwollaId); 0710 $form->addElement($dwolla); 0711 0712 return $form; 0713 } 0714 0715 public function profileAction() 0716 { 0717 $this->view->member = $this->_memberSettings; 0718 $memberSettings = $this->_memberSettings->toArray(); 0719 0720 0721 $this->view->profileform = $this->formProfile(); 0722 $this->view->profileform->populate($memberSettings); 0723 $this->view->profileform->aboutme->setValue($this->_mainproject->description); 0724 0725 $this->view->accounts = $this->formConnectedAccounts(); 0726 $this->view->accounts->populate($memberSettings); 0727 0728 0729 $this->view->pictureform = $this->formProfilePicture(); 0730 $this->view->pictureform->populate($memberSettings); 0731 0732 $this->view->pictureformbg = $this->formProfilePictureBackground(); 0733 $this->view->pictureformbg->populate($memberSettings); 0734 0735 0736 $websiteOwner = new Local_Verification_WebsiteOwner(); 0737 $linkWebsite = stripslashes($this->_memberSettings->link_website); 0738 $this->view->homepageform = 0739 $this->formHomepage($linkWebsite, $websiteOwner->generateAuthCode($linkWebsite), 0740 $this->_memberSettings->validated); 0741 } 0742 0743 public function savetagsAction() 0744 { 0745 $this->_helper->layout->disableLayout(); 0746 $error_text = ''; 0747 0748 $tag_id = null; 0749 if (!empty($_POST['tag_id'])) { 0750 $tag_id = $_POST['tag_id']; 0751 } 0752 $tag_group_id = $_POST['tag_group_id']; 0753 $tag_object_id = $this->_memberId; 0754 $model = new Default_Model_Tags(); 0755 $model->saveOSTagForUser($tag_id, $tag_group_id, $tag_object_id); 0756 $this->_helper->json(array('status' => 'ok')); 0757 } 0758 0759 public function saveprofileAction() 0760 { 0761 $this->_helper->layout->disableLayout(); 0762 $this->_helper->viewRenderer('partials/profile'); 0763 0764 if ($this->_request->isPost()) { 0765 $form = $this->formProfile(); 0766 0767 if ($form->isValid($_POST)) { 0768 $values = $form->getValues(); 0769 0770 //remove email and username 0771 unset($values['username']); 0772 unset($values['mail']); 0773 0774 $values['firstname'] = Default_Model_HtmlPurify::purify($values['firstname']); 0775 $values['lastname'] = Default_Model_HtmlPurify::purify($values['lastname']); 0776 $values['city'] = Default_Model_HtmlPurify::purify($values['city']); 0777 $values['country'] = Default_Model_HtmlPurify::purify($values['country']); 0778 $values['aboutme'] = Default_Model_HtmlPurify::purify($values['aboutme']); 0779 0780 $this->_memberSettings->setFromArray($values); 0781 $this->_memberSettings->save(); 0782 0783 $this->_mainproject->description = $values['aboutme']; 0784 0785 $this->_mainproject->save(); 0786 0787 $this->view->profileform = $form; 0788 $this->view->save = 1; 0789 0790 // ppload 0791 // Update profile information 0792 $this->_updatePploadProfile(); 0793 } else { 0794 $this->view->profileform = $form; 0795 $this->view->error = 1; 0796 } 0797 } else { 0798 $form = $this->formProfile(); 0799 $form->populate($this->_memberSettings->toArray()); 0800 $this->view->profileform = $form; 0801 } 0802 } 0803 0804 /** 0805 * ppload 0806 */ 0807 protected function _updatePploadProfile() 0808 { 0809 $pploadApi = new Ppload_Api(array( 0810 'apiUri' => PPLOAD_API_URI, 0811 'clientId' => PPLOAD_CLIENT_ID, 0812 'secret' => PPLOAD_SECRET 0813 )); 0814 0815 $profileName = ''; 0816 if ($this->_memberSettings->firstname 0817 || $this->_memberSettings->lastname) { 0818 $profileName = trim($this->_memberSettings->firstname . ' ' . $this->_memberSettings->lastname); 0819 } else { 0820 if ($this->_memberSettings->username) { 0821 $profileName = $this->_memberSettings->username; 0822 } 0823 } 0824 0825 $profileRequest = array( 0826 'owner_id' => $this->_memberId, 0827 'name' => $profileName, 0828 'email' => $this->_memberSettings->mail, 0829 'homepage' => $this->_memberSettings->link_website, 0830 'image' => $this->_memberSettings->profile_image_url, 0831 'description' => $this->_mainproject->description 0832 ); 0833 $profileResponse = $pploadApi->postProfile($profileRequest); 0834 } 0835 0836 public function accountsAction() 0837 { 0838 $this->_helper->layout->disableLayout(); 0839 $this->_helper->viewRenderer('partials/accounts'); 0840 0841 if ($this->_request->isPost()) { 0842 $form = $this->formConnectedAccounts(); 0843 0844 if ($form->isValid($_POST)) { 0845 $this->_memberSettings->setFromArray($form->getValues()); 0846 $this->_memberSettings->save(); 0847 0848 $this->view->accounts = $form; 0849 $this->view->save = 1; 0850 } else { 0851 $this->view->accounts = $form; 0852 $this->view->error = 1; 0853 } 0854 } else { 0855 $form = $this->formProfile(); 0856 $form->populate($this->_memberSettings->toArray()); 0857 $this->view->accounts = $form; 0858 } 0859 } 0860 0861 public function githubAction() 0862 { 0863 $this->_helper->layout->disableLayout(); 0864 $this->_helper->viewRenderer('partials/github'); 0865 0866 if ($this->_request->isPost()) { 0867 $form = $this->formGithub(); 0868 0869 if ($form->isValid($_POST)) { 0870 $this->_memberSettings->setFromArray($form->getValues()); 0871 $this->_memberSettings->save(); 0872 0873 $memberToken = new Default_Model_DbTable_MemberToken(); 0874 $memberToken->save(array( 0875 'token_member_id' => $this->_memberId, 0876 'token_provider_name' => 'github_personal', 0877 'token_value' => $form->getValue('token_github'), 0878 'token_provider_username' => $form->getValue('link_github') 0879 )); 0880 0881 $this->view->github = $form; 0882 $this->view->save = 1; 0883 } else { 0884 $this->view->github = $form; 0885 $this->view->error = 1; 0886 } 0887 } else { 0888 $form = $this->formProfile(); 0889 $form->populate($this->_memberSettings->toArray()); 0890 $this->view->github = $form; 0891 } 0892 } 0893 0894 public function pictureAction() 0895 { 0896 ini_set('memory_limit', '128M'); 0897 0898 $this->_helper->layout->disableLayout(); 0899 0900 if ($this->_request->isPost()) { 0901 $form = $this->formProfilePicture(); 0902 0903 $formFilename = $form->getElement('profile_picture_upload')->getFileName(); 0904 Zend_Registry::get('logger')->info(__METHOD__ . ' :: form input:' . print_r($formFilename, true)); 0905 if (is_array($formFilename)) { 0906 $filename = $formFilename['profile_picture_upload']; 0907 } else { 0908 $filename = $formFilename; 0909 } 0910 $profilePictureTitleFilename = pathinfo($filename); 0911 0912 if (!isset($profilePictureTitleFilename)) { 0913 $form->populate($this->_memberSettings->toArray()); 0914 $form->addErrorMessage('Please select a new picture'); 0915 $form->markAsError(); 0916 0917 $this->view->pictureform = $form; 0918 $this->view->error = 1; 0919 $this->renderScript('settings/partials/picture.phtml'); 0920 0921 return; 0922 } 0923 if ($form->isValid($_POST)) { 0924 0925 $tmpProfilePictureTitle = IMAGES_UPLOAD_PATH . 'tmp/' . Local_Tools_UUID::generateUUID() . '_' . $profilePictureTitleFilename['basename']; 0926 $form->getElement('profile_picture_upload') 0927 ->addFilter('Rename', array('target' => $tmpProfilePictureTitle, 'overwrite' => true)); 0928 0929 $values = $form->getValues(); 0930 0931 if (array_key_exists('profile_picture_upload', $values) && $values['profile_picture_upload'] != "") { 0932 $imageService = new Default_Model_DbTable_Image(); 0933 $newImageName = $imageService->saveImageOnMediaServer($tmpProfilePictureTitle); 0934 } 0935 if ($form->getElement('facebook_username')->getValue() !== null) { 0936 $this->_memberSettings->facebook_username = $values['facebook_username']; 0937 } 0938 if ($form->getElement('twitter_username')->getValue() !== null) { 0939 $this->_memberSettings->twitter_username = $values['twitter_username']; 0940 } 0941 if ($form->getElement('gravatar_email')->getValue() !== null) { 0942 $this->_memberSettings->gravatar_email = $values['gravatar_email']; 0943 } 0944 if ($values['profile_img_src'] == 'local' && isset($newImageName)) { 0945 $this->_auth->getIdentity()->avatar = $newImageName; 0946 $this->_auth->getIdentity()->profile_image_url = IMAGES_MEDIA_SERVER . '/cache/200x200-2/img/' . $newImageName; 0947 $this->_memberSettings->avatar = $newImageName; 0948 $this->_memberSettings->profile_image_url = IMAGES_MEDIA_SERVER . '/cache/200x200-2/img/' . $newImageName; 0949 $this->_memberSettings->avatar_type_id = Default_Model_DbTable_Member::MEMBER_AVATAR_TYPE_USERUPDATED; 0950 } 0951 $this->_memberSettings->profile_img_src = $values['profile_img_src']; 0952 0953 $this->_memberSettings->save(); 0954 $this->view->member = $this->_memberSettings; 0955 $form->populate($this->_memberSettings->toArray()); 0956 0957 try { 0958 $id_server = new Default_Model_Ocs_OAuth(); 0959 $id_server->updateAvatarForUser($this->_memberSettings->member_id); 0960 } catch (Exception $e) { 0961 Zend_Registry::get('logger')->err($e->getMessage() . PHP_EOL . $e->getTraceAsString()); 0962 } 0963 try { 0964 $ldap_server = new Default_Model_Ocs_Ldap(); 0965 $ldap_server->updateAvatar($this->_memberSettings->member_id, $this->_memberSettings->profile_image_url); 0966 Zend_Registry::get('logger')->debug(__METHOD__ . ' - ldap : ' . implode(PHP_EOL . " - ", 0967 $ldap_server->getMessages())); 0968 } catch (Exception $e) { 0969 Zend_Registry::get('logger')->err($e->getMessage() . PHP_EOL . $e->getTraceAsString()); 0970 } 0971 // ppload 0972 // Update profile information 0973 $this->_updatePploadProfile(); 0974 0975 0976 $this->view->save = 1; 0977 $this->view->pictureform = $form; 0978 0979 $this->renderScript('settings/partials/picture.phtml'); 0980 } else { 0981 $this->view->pictureform = $form; 0982 $this->view->error = 1; 0983 $this->renderScript('settings/partials/picture.phtml'); 0984 } 0985 } else { 0986 $form = $this->formProfilePicture(); 0987 $form->populate($this->_memberSettings->toArray()); 0988 $this->view->pictureform = $form; 0989 $this->renderScript('settings/partials/picture.phtml'); 0990 } 0991 } 0992 0993 public function deletepicturebackgroundAction() 0994 { 0995 $this->_helper->layout->disableLayout(); 0996 $this->_memberSettings->profile_image_url_bg = null; 0997 $this->_memberSettings->save(); 0998 0999 $this->_helper->json(array( 1000 'status' => 'ok' 1001 )); 1002 } 1003 1004 public function picturebackgroundAction() 1005 { 1006 ini_set('memory_limit', '128M'); 1007 1008 $this->_helper->layout->disableLayout(); 1009 1010 if ($this->_request->isPost()) { 1011 $form = $this->formProfilePictureBackground(); 1012 1013 $profilePictureElement = $form->getElement('profile_picture_background_upload'); 1014 if (!isset($profilePictureElement)) { 1015 $form->populate($this->_memberSettings->toArray()); 1016 $form->addErrorMessage('Please select a new picture'); 1017 $form->markAsError(); 1018 1019 $this->view->pictureformbg = $form; 1020 $this->view->error = 1; 1021 $this->renderScript('settings/partials/picture-bg.phtml'); 1022 1023 return; 1024 } 1025 1026 $profilePictureTitleFilename = pathinfo($form->getElement('profile_picture_background_upload')->getFileName()); 1027 1028 if ($form->isValid($_POST)) { 1029 1030 $tmpProfilePictureTitle = 1031 IMAGES_UPLOAD_PATH . 'tmp/' . Local_Tools_UUID::generateUUID() . '_' . $profilePictureTitleFilename['basename']; 1032 $form->getElement('profile_picture_background_upload') 1033 ->addFilter('Rename', array('target' => $tmpProfilePictureTitle, 'overwrite' => true)); 1034 1035 $values = $form->getValues(); 1036 1037 if (array_key_exists('profile_picture_background_upload', $values) 1038 && $values['profile_picture_background_upload'] != "") { 1039 $imageService = new Default_Model_DbTable_Image(); 1040 $newImageName = $imageService->saveImageOnMediaServer($tmpProfilePictureTitle); 1041 } 1042 1043 if (isset($newImageName)) { 1044 $this->_memberSettings->profile_image_url_bg = IMAGES_MEDIA_SERVER . '/cache/1920x450-2/img/' . $newImageName; 1045 } 1046 1047 $this->_memberSettings->save(); 1048 $this->view->member = $this->_memberSettings; 1049 $form->populate($this->_memberSettings->toArray()); 1050 1051 $this->view->save = 1; 1052 $this->view->pictureformbg = $form; 1053 1054 $this->renderScript('settings/partials/picture-bg.phtml'); 1055 } else { 1056 $this->view->pictureformbg = $form; 1057 $this->view->error = 1; 1058 $this->renderScript('settings/partials/picture-bg.phtml'); 1059 } 1060 } else { 1061 $form = $this->formProfilePictureBackground(); 1062 $form->populate($this->_memberSettings->toArray()); 1063 $this->view->pictureformbg = $form; 1064 $this->renderScript('settings/partials/picture-bg.phtml'); 1065 } 1066 } 1067 1068 public function passwordAction() 1069 { 1070 $this->_helper->layout->disableLayout(); 1071 $this->_helper->viewRenderer('partials/password'); 1072 1073 $form = $this->formPassword(); 1074 1075 if (false === $this->_request->isPost()) { 1076 1077 $this->view->passwordform = $form; 1078 1079 return; 1080 } 1081 1082 if (false === $form->isValid($_POST)) { 1083 $this->view->passwordform = $form; 1084 $this->view->error = 1; 1085 1086 return; 1087 } 1088 1089 $values = $form->getValues(); 1090 1091 if ($this->_memberSettings->password != Local_Auth_Adapter_Ocs::getEncryptedPassword($values['passwordOld'], $this->_memberSettings->password_type)) { 1092 $form->addErrorMessage('Your old Password is wrong!'); 1093 $this->view->passwordform = $form; 1094 $this->view->error = 1; 1095 1096 return; 1097 } 1098 1099 //20180801 ronald: If a Hive User changes his password, we change the password type to our Default 1100 if ($this->_memberSettings->password_type == Default_Model_Member::PASSWORD_TYPE_HIVE) { 1101 //Save old data 1102 $this->_memberSettings->password_old = $this->_memberSettings->password; 1103 $this->_memberSettings->password_type_old = Default_Model_Member::PASSWORD_TYPE_HIVE; 1104 1105 //Change type and password 1106 $this->_memberSettings->password_type = Default_Model_Member::PASSWORD_TYPE_OCS; 1107 } 1108 1109 $this->_memberSettings->password = Local_Auth_Adapter_Ocs::getEncryptedPassword($values['password1'], $this->_memberSettings->password_type); 1110 $this->_memberSettings->save(); 1111 1112 $this->view->passwordform = $form; 1113 $this->view->save = 1; 1114 1115 //Update Auth-Services 1116 try { 1117 $id_server = new Default_Model_Ocs_OAuth(); 1118 $id_server->updatePasswordForUser($this->_memberSettings->member_id); 1119 Zend_Registry::get('logger')->info(__METHOD__ . ' - ldap : ' . implode(PHP_EOL . " - ", $id_server->getMessages())); 1120 } catch (Exception $e) { 1121 Zend_Registry::get('logger')->err($e->getMessage() . PHP_EOL . $e->getTraceAsString()); 1122 } 1123 try { 1124 $ldap_server = new Default_Model_Ocs_Ldap(); 1125 $ldap_server->updatePassword($this->_memberSettings->member_id, $values['password1']); 1126 Zend_Registry::get('logger')->debug(__METHOD__ . ' - ldap : ' . implode(PHP_EOL . " - ", $ldap_server->getMessages())); 1127 } catch (Exception $e) { 1128 Zend_Registry::get('logger')->err($e->getMessage() . PHP_EOL . $e->getTraceAsString()); 1129 } 1130 } 1131 1132 public function homepageAction() 1133 { 1134 $this->_helper->layout->disableLayout(); 1135 $this->_helper->viewRenderer('partials/website'); 1136 1137 if ($this->_request->isGet()) { 1138 $websiteVerifier = new Local_Verification_WebsiteOwner(); 1139 $authCode = $websiteVerifier->generateAuthCode($this->_memberSettings->link_website); 1140 $form = $this->formHomepage($this->_memberSettings->link_website, $authCode, 1141 $this->_memberSettings->validated); 1142 $this->view->homepageform = $form; 1143 1144 return; 1145 } 1146 1147 $form = $this->formHomepage($_POST['link_website']); 1148 if ($form->isNotValid($_POST)) { 1149 $this->view->homepageform = $form; 1150 $this->view->error = 1; 1151 1152 return; 1153 } 1154 1155 $values = $form->getValues(); 1156 1157 if ($this->_memberSettings->link_website == $values['link_website']) { 1158 $websiteVerifier = new Local_Verification_WebsiteOwner(); 1159 $authCode = $websiteVerifier->generateAuthCode($this->_memberSettings->link_website); 1160 $form = $this->formHomepage($this->_memberSettings->link_website, $authCode); 1161 $this->view->homepageform = $form; 1162 $this->view->save = 0; 1163 1164 return; 1165 } 1166 1167 $websiteVerifier = new Local_Verification_WebsiteOwner(); 1168 $authCode = $websiteVerifier->generateAuthCode($values['link_website']); 1169 1170 //$queue = Local_Queue_Factory::getQueue(); 1171 //$command = new Backend_Commands_CheckMemberWebsite($this->_memberId, $values['link_website'], $authCode); 1172 //$queue->send(serialize($command)); 1173 1174 $this->_memberSettings->link_website = $values['link_website']; 1175 $this->_memberSettings->validated = 0; 1176 $this->_memberSettings->save(); 1177 1178 $this->view->save = 1; 1179 $this->view->homepageform = $this->formHomepage($values['link_website'], $authCode); 1180 1181 // ppload 1182 // Update profile information 1183 $this->_updatePploadProfile(); 1184 } 1185 1186 public function newsletterAction() 1187 { 1188 $this->_helper->layout->disableLayout(); 1189 $this->_helper->viewRenderer('partials/newsletter'); 1190 1191 if ($this->_request->isPost()) { 1192 $form = $this->formNewsletter(); 1193 1194 if ($form->isValid($_POST)) { 1195 $values = $form->getValues(); 1196 1197 $this->_memberSettings->newsletter = $values['newsletter']; 1198 1199 $this->_memberSettings->save(); 1200 1201 $this->view->newsletterform = $this->formNewsletter($this->_memberSettings->newsletter); 1202 1203 $this->view->save = 1; 1204 } else { 1205 $this->view->newsletterform = $form; 1206 $this->view->error = 1; 1207 } 1208 } else { 1209 $form = $this->formNewsletter($this->_memberSettings->newsletter); 1210 1211 $this->view->newsletterform = $form; 1212 } 1213 } 1214 1215 public function paymentAction() 1216 { 1217 $this->_helper->layout->disableLayout(); 1218 $this->_helper->viewRenderer('partials/payment'); 1219 1220 if ($this->_request->isPost()) { 1221 $form = $this->formPayment(); 1222 1223 if ($form->isValid($_POST)) { 1224 $values = $form->getValues(); 1225 //If the user changes the paypal address, we set the valid staus back to null 1226 if ($this->_memberSettings->paypal_mail != $values['paypal_mail']) { 1227 //$showMember = $this->_memberTable->find($this->_memberId)->current(); 1228 //$showMember->paypal_valid_status = null; 1229 //$this->_memberTable->save($showMember); 1230 //$this->view->member = $showMember; 1231 $this->_memberTable->update(array('paypal_valid_status' => null), 1232 'member_id = ' . $this->_memberId); 1233 1234 //Log if paypal changes 1235 1236 $desc = 'Paypal-Address changed from '; 1237 if (isset($this->_memberSettings->paypal_mail)) { 1238 $desc .= $this->_memberSettings->paypal_mail; 1239 } 1240 $desc .= ' to ' . $values['paypal_mail']; 1241 Default_Model_ActivityLog::logActivity($this->_memberSettings->member_id, null, $this->_memberId, 1242 Default_Model_ActivityLog::MEMBER_PAYPAL_CHANGED, array('title' => '', 'description' => $desc)); 1243 } 1244 1245 $this->_memberSettings->paypal_mail = $values['paypal_mail']; 1246 $this->_memberSettings->wallet_address = $values['wallet_address']; 1247 $this->_memberSettings->dwolla_id = $values['dwolla_id']; 1248 1249 $this->_memberSettings->save(); 1250 1251 $this->view->paymentform = $this->formPayment(); 1252 $this->view->paymentform->populate($this->_memberSettings->toArray()); 1253 1254 $this->view->save = 1; 1255 } else { 1256 $this->view->paymentform = $form; 1257 $this->view->error = 1; 1258 } 1259 } else { 1260 $form = $this->formPayment(); 1261 $form->populate($this->_memberSettings->toArray()); 1262 1263 $this->view->paymentform = $form; 1264 } 1265 } 1266 1267 public function deleteAction() 1268 { 1269 $this->_memberSettings->is_deleted = 1; 1270 $this->_memberSettings->is_active = 0; 1271 $this->_memberSettings->save(); 1272 1273 $tableProject = new Default_Model_Project(); 1274 $tableProject->setAllProjectsForMemberDeleted($this->_memberId); 1275 1276 $auth = Zend_Auth::getInstance(); 1277 $auth->clearIdentity(); 1278 1279 $session = new Zend_Session_Namespace(); 1280 $session->unsetAll(); 1281 Zend_Session::forgetMe(); 1282 Zend_Session::destroy(); 1283 1284 $config = Zend_Registry::get('config'); 1285 $cookieName = $config->settings->session->remember_me->name; 1286 $cookieData = $this->_request->getCookie($cookieName, null); 1287 if ($cookieData) { 1288 $cookieData = unserialize($cookieData); 1289 $remember_me_seconds = $config->settings->session->remember_me->cookie_lifetime; 1290 $domain = Local_Tools_ParseDomain::get_domain($this->getRequest()->getHttpHost()); 1291 $cookieExpire = time() - $remember_me_seconds; 1292 1293 setcookie($cookieName, null, $cookieExpire, '/', $domain, null, true); 1294 1295 //TODO: Remove Cookie from database 1296 $modelAuthorization = new Default_Model_Authorization(); 1297 $modelAuthorization->removeAllCookieInformation('member_id', $cookieData['mi']); 1298 } 1299 1300 // ppload 1301 // Delete owner and related data 1302 $pploadApi = new Ppload_Api(array( 1303 'apiUri' => PPLOAD_API_URI, 1304 'clientId' => PPLOAD_CLIENT_ID, 1305 'secret' => PPLOAD_SECRET 1306 )); 1307 $ownerResponse = $pploadApi->deleteOwner($this->_memberId); 1308 } 1309 1310 public function githubtokenAction() 1311 { 1312 $this->_helper->layout->disableLayout(); 1313 $this->_helper->viewRenderer('partials/github'); 1314 1315 $modelGithubOauth = new Default_Model_Oauth_Github( 1316 Zend_Registry::get('db'), 1317 'member', 1318 Zend_Registry::get('config')->third_party->github); 1319 $modelGithubOauth->authStart('/settings'); 1320 } 1321 1322 public function addemailAction() 1323 { 1324 $this->_helper->layout->disableLayout(); 1325 $this->_helper->viewRenderer('partials/email'); 1326 1327 $filterInput = $this->createFilter(); 1328 1329 if ($filterInput->hasInvalid()) { 1330 $this->view->messages = $filterInput->getMessages(); 1331 1332 return; 1333 } 1334 1335 $resultSet = $this->saveEmail($filterInput); 1336 1337 $this->sendConfirmationMail($resultSet->toArray()); 1338 1339 $this->view->messages = 1340 array('user_email' => array('success' => 'Your email was saved. Please check your email account for verification email.')); 1341 } 1342 1343 /** 1344 * @return Zend_Filter_Input 1345 * @throws Zend_Validate_Exception 1346 */ 1347 protected function createFilter() 1348 { 1349 $mailValidCheck = new Zend_Validate_EmailAddress(); 1350 $mailValidCheck->setOptions(array('domain' => true)); 1351 1352 $mailExistCheck = new Zend_Validate_Db_NoRecordExists(array( 1353 'table' => 'member_email', 1354 'field' => 'email_address', 1355 'exclude' => array('field' => 'email_deleted', 'value' => 1) 1356 )); 1357 $mailExistCheck->setMessage('RegisterFormEmailErrAlreadyRegistered', 1358 Zend_Validate_Db_NoRecordExists::ERROR_RECORD_FOUND); 1359 1360 // Filter-Parameter 1361 $filterInput = new Zend_Filter_Input(array('*' => 'StringTrim', 'user_email' => 'StripTags'), array( 1362 'user_email' => array( 1363 $mailValidCheck, 1364 $mailExistCheck, 1365 'presence' => 'required' 1366 ) 1367 ), $this->getAllParams()); 1368 1369 return $filterInput; 1370 } 1371 1372 /** 1373 * @param Zend_Filter_Input $filterInput 1374 * 1375 * @return Zend_Db_Table_Row_Abstract 1376 * @throws Exception 1377 */ 1378 protected function saveEmail($filterInput) 1379 { 1380 $data = array(); 1381 $data['email_member_id'] = $this->_authMember->member_id; 1382 $data['email_address'] = $filterInput->getEscaped('user_email'); 1383 $data['email_hash'] = md5($filterInput->getEscaped('user_email')); 1384 $data['email_verification_value'] = 1385 Default_Model_MemberEmail::getVerificationValue($this->_authMember->username, 1386 $filterInput->getEscaped('user_email')); 1387 $modelMemberEmail = new Default_Model_DbTable_MemberEmail(); 1388 1389 return $modelMemberEmail->save($data); 1390 } 1391 1392 /** 1393 * @param array $data 1394 * @throws Zend_Exception 1395 */ 1396 protected function sendConfirmationMail($data) 1397 { 1398 $config = Zend_Registry::get('config'); 1399 $defaultFrom = $config->resources->mail->defaultFrom->email; 1400 1401 $confirmMail = new Default_Plugin_SendMail('tpl_verify_email'); 1402 $confirmMail->setTemplateVar('servername', $this->getServerName()); 1403 $confirmMail->setTemplateVar('username', $this->_authMember->username); 1404 $confirmMail->setTemplateVar('email_address', $data['email_address']); 1405 $confirmMail->setTemplateVar('verificationlinktext', 1406 '<a href="https://' . $this->getServerName() . '/settings/verification/v/' . $data['email_verification_value'] 1407 . '">Click here to verify your email address</a>'); 1408 $confirmMail->setTemplateVar('verificationlink', 1409 '<a href="https://' . $this->getServerName() . '/settings/verification/v/' . $data['email_verification_value'] 1410 . '">https://' . $this->getServerName() . '/settings/verification/v/' . $data['email_verification_value'] . '</a>'); 1411 $confirmMail->setTemplateVar('verificationurl', 1412 'https://' . $this->getServerName() . '/settings/verification/v/' . $data['email_verification_value']); 1413 $confirmMail->setReceiverMail($data['email_address']); 1414 $confirmMail->setFromMail($defaultFrom); 1415 $confirmMail->send(); 1416 } 1417 1418 /** 1419 * @return mixed 1420 */ 1421 protected function getServerName() 1422 { 1423 /** @var Zend_Controller_Request_Http $request */ 1424 $request = $this->getRequest(); 1425 1426 return $request->getHttpHost(); 1427 } 1428 1429 public function removeemailAction() 1430 { 1431 $this->_helper->layout->disableLayout(); 1432 $this->_helper->viewRenderer('partials/email'); 1433 1434 $emailId = (int)$this->getParam('i'); 1435 1436 $modelEmail = new Default_Model_DbTable_MemberEmail(); 1437 1438 $result = $modelEmail->delete($emailId); 1439 1440 $this->view->messages = array('user_email' => array('success' => 'Your email was removed.')); 1441 } 1442 1443 public function setdefaultemailAction() 1444 { 1445 $this->_helper->layout->disableLayout(); 1446 $this->_helper->viewRenderer('partials/email'); 1447 1448 $emailId = (int)$this->getParam('i'); 1449 1450 $modelEmail = new Default_Model_MemberEmail(); 1451 $result = $modelEmail->setDefaultEmail($emailId, $this->_authMember->member_id); 1452 1453 if (true === $result) { 1454 try { 1455 $id_server = new Default_Model_Ocs_OAuth(); 1456 $id_server->updateMailForUser($this->_authMember->member_id); 1457 Zend_Registry::get('logger')->debug(__METHOD__ . ' - oauth : ' . implode(PHP_EOL . " - ", $id_server->getMessages())); 1458 Zend_Registry::get('logger')->debug(__METHOD__ . ' - oauth : ' . print_r($id_server->getMessages(), true)); 1459 } catch (Exception $e) { 1460 Zend_Registry::get('logger')->err($e->getMessage() . PHP_EOL . $e->getTraceAsString()); 1461 } 1462 try { 1463 $ldap_server = new Default_Model_Ocs_Ldap(); 1464 $ldap_server->updateMail($this->_authMember->member_id); 1465 Zend_Registry::get('logger')->debug(__METHOD__ . ' - ldap : ' . implode(PHP_EOL . " - ", $ldap_server->getMessages())); 1466 } catch (Exception $e) { 1467 Zend_Registry::get('logger')->err($e->getMessage() . PHP_EOL . $e->getTraceAsString()); 1468 } 1469 try { 1470 $openCode = new Default_Model_Ocs_Gitlab(); 1471 $openCode->updateMail($this->_authMember->member_id); 1472 Zend_Registry::get('logger')->debug(__METHOD__ . ' - opencode : ' . implode(PHP_EOL . " - ", $openCode->getMessages())); 1473 } catch (Exception $e) { 1474 Zend_Registry::get('logger')->err($e->getMessage() . PHP_EOL . $e->getTraceAsString()); 1475 } 1476 } 1477 } 1478 1479 public function resendverificationAction() 1480 { 1481 $this->_helper->layout->disableLayout(); 1482 $this->_helper->viewRenderer('partials/email'); 1483 1484 $emailId = (int)$this->getParam('i'); 1485 1486 $modelEmail = new Default_Model_DbTable_MemberEmail(); 1487 $data = $modelEmail->find($emailId)->current(); 1488 $data->email_verification_value = md5($data->email_address . $this->_authMember->username . time()); 1489 $data->save(); 1490 $this->sendConfirmationMail($data); 1491 1492 $this->view->messages = 1493 array('user_email' => array('success' => 'New verification mail was send. Please check your email account.')); 1494 } 1495 1496 public function verificationAction() 1497 { 1498 $this->_helper->layout->disableLayout(); 1499 $this->_helper->viewRenderer->setNoRender(true); 1500 1501 // Filter-Parameter 1502 $filterInput = new Zend_Filter_Input(array('*' => 'StringTrim', 'v' => 'StripTags'), array( 1503 'v' => array( 1504 'presence' => 'required' 1505 ) 1506 ), $this->getAllParams()); 1507 1508 if ($filterInput->hasInvalid()) { 1509 $this->_helper->flashMessenger->addMessage('<p class="text-error">There was an error verifying your email. </p>'); 1510 $this->forward('index'); 1511 1512 return; 1513 } 1514 1515 $modelEmail = new Default_Model_MemberEmail(); 1516 $result = $modelEmail->verificationEmail($filterInput->getEscaped('v')); 1517 1518 if ($result == 1) { 1519 $this->_helper->flashMessenger->addMessage('<p class="text-success">Your email was successfully verified. </p>'); 1520 } else { 1521 $this->_helper->flashMessenger->addMessage('<p class="text-danger">There was an error verifying your email.</p>'); 1522 } 1523 $this->forward('index'); 1524 } 1525 1526 }