Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.64 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Application\Controllers;
  4.  
  5. /**
  6.  * Flex Web PHP Development Framework V1
  7.  * @author: matix
  8.  * @version: 1
  9.  */
  10.  
  11. use Application\Plugins\UserManagement\Application\Controllers;
  12.  
  13. final class Users extends Controllers\Users
  14. {
  15.  
  16.   public function __construct()
  17.   {
  18.     parent::__construct();
  19.    
  20.     $this->getUser()->geti18n()->setSource('user');
  21.   }
  22.  
  23.   public function executeIndex()
  24.   {
  25.     $this->users = \User::doSelectLikeUsername($this->getResponse()->getParameter('start'));
  26.   }
  27.  
  28.   public function executeShow()
  29.   {
  30.     $this->throw404Unless($this->user = \Doctrine_Core::getTable('User')->findOneBySlug($this->getResponse()->getParameter('slug')));
  31.   }
  32.  
  33.   public function executeLocale()
  34.   {
  35.     if (in_array($this->getResponse()->getParameter('locale'), \Flex\Config\Yml::getAttribute('settings#locales')))
  36.     {
  37.       $locale = $this->getResponse()->getParameter('locale') . '_' . strtoupper($this->getResponse()->getParameter('locale'));
  38.      
  39.       $this->getUser()->setLocale($locale);
  40.       $this->getUser()->setFlash('notice', $this->getUser()->geti18n()->changed_locale);
  41.     }
  42.    
  43.     return $this->getResponse()->setLocation($this->getUrl()->getReferer());
  44.   }
  45.  
  46.   public function executeSettings()
  47.   {
  48.     $this->redirectUnlessLogged();
  49.     // ...
  50.   }
  51.  
  52.   public function executeEdit()
  53.   {
  54.     $this->redirectUnlessLogged();
  55.    
  56.     $this->user = $user = $this->getUser()->getUserInfo();
  57.     $this->form = $form = new \Application\Forms\Profile\User;
  58.     $this->interests = $interests = \Flex\Config\Php::getAttribute('user_interests');
  59.    
  60.     $form->bind($form->convertToFormData($user->toArray()));
  61.    
  62.     if($form->postAndValid())
  63.     {
  64.       if($this->getResponse()->getParameter('t') == 5)
  65.       {
  66.         $c = new \Experience;
  67.         $c->fromArray($form->asArray());
  68.        
  69.         $user->Experience->add($c);
  70.       }else{
  71.         $user->fromArray($form->asArray());
  72.       }
  73.      
  74.       $user->save();
  75.      
  76.       $this->getUser()->setFlash('notice', __('successfully_updated_data'));
  77.       $this->getResponse()->setLocation($this->getUrl()->getReferer());
  78.     }
  79.   }
  80.  
  81.   public function executeDestroy()
  82.   {
  83.     $this->redirectUnlessLogged();
  84.     $user_data = $this->getUser()->getUserInfo();
  85.    
  86.     if($this->getResponse()->isPost())
  87.     {
  88.       if(sha1($this->getResponse()->getPost('password')) == $user_data->password)
  89.       {
  90.         $user_data->delete();
  91.         $this->getUser()->destroy();
  92.        
  93.         $this->getUser()->setFlash('notice', __('successfully_deleted_account'));
  94.         return $this->getResponse()->setLocation($this->getUrl()->generateUrl('root'));
  95.       }else{
  96.         $this->getUser()->setFlash('error', __('invalid_password'));
  97.         return $this->getResponse()->setLocation($this->getUrl()->getReferer());
  98.       }
  99.     }
  100.   }
  101.  
  102.   public function executePassword()
  103.   {
  104.     $this->redirectUnlessLogged();
  105.     $user = $this->getUser()->getUserInfo();
  106.     $form = $this->form = new \Application\Forms\Profile\Password;
  107.    
  108.     if($form->postAndValid())
  109.     {
  110.       $user->password = sha1($form->new_password);
  111.       $user->save();
  112.      
  113.       $this->getUser()->destroy();
  114.       $this->getUser()->setFlash('notice', __('successfully_updated_data'));
  115.       return $this->getResponse()->setLocation($this->getUrl()->getReferer());
  116.     }
  117.   }
  118.  
  119.   public function executeMail()
  120.   {
  121.     $this->redirectUnlessLogged();
  122.     $user = $this->getUser()->getUserInfo();
  123.     $form = $this->form = new \Application\Forms\Profile\Email;
  124.    
  125.     if($form->postAndValid())
  126.     {
  127.       $user->mail = $form->new_mail;
  128.       $user->save();
  129.      
  130.       $this->getUser()->setFlash('notice', __('successfully_updated_data'));
  131.       return $this->getResponse()->setLocation($this->getUrl()->getReferer());
  132.     }
  133.   }
  134.  
  135.   public function executePrivacy()
  136.   {
  137.     $this->redirectUnlessLogged();
  138.     $user = $this->getUser()->getUserInfo();
  139.     $form = $this->form = new \Application\Forms\Profile\Email;
  140.    
  141.     if($form->postAndValid())
  142.     {
  143.       $user->mail = $form->new_mail;
  144.       $user->save();
  145.      
  146.       $this->getUser()->setFlash('notice', __('successfully_updated_data'));
  147.       return $this->getResponse()->setLocation($this->getUrl()->getReferer());
  148.     }
  149.   }
  150.  
  151.   public function executeDeletePhoto()
  152.   {
  153.     $this->redirectUnlessLogged();
  154.     $userData = $this->getUser()->getUserInfo();
  155.     $userData->photo = NULL;
  156.     $userData->save();
  157.    
  158.     $this->getUser()->setFlash('notice', __('successfully_updated_data'));
  159.     return $this->getResponse()->setLocation($this->getUrl()->getReferer());
  160.   }
  161.  
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement