Advertisement
Guest User

Untitled

a guest
Mar 1st, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.00 KB | None | 0 0
  1. <?php
  2. namespace Vokuro\Controllers;
  3. use Phalcon\Mvc\Controller;
  4. use Vokuro\Models\EmailConfirmations;
  5. use Vokuro\Models\ResetPasswords;
  6. use Vokuro\Models\Users;
  7.  
  8. /**
  9.  * UserControlController
  10.  * Provides help to users to confirm their passwords or reset them
  11.  */
  12. class UserControlController extends ControllerBase
  13. {
  14.  
  15.     public function initialize()
  16.     {
  17.         if ($this->session->has('auth-identity')) {
  18.             $this->view->setTemplateBefore('private');
  19.         }
  20.     }
  21.  
  22.     public function indexAction()
  23.     {
  24.  
  25.     }
  26.  
  27.     /**
  28.      * Confirms an e-mail, if the user must change thier password then changes it
  29.      */
  30.     public function confirmEmailAction()
  31.     {
  32.  
  33.         $userid = $this->dispatcher->getParam('userid');
  34.         $key = $this->dispatcher->getParam('key');
  35.  
  36.         $user = Users::findFirstById($userid);
  37.  
  38.         if(!$userid || !$key )
  39.            die("error");
  40.  
  41.  
  42.         if($user->activated)
  43.             die("Ovaj account je vec aktiviran");
  44.  
  45.  
  46.        
  47.        
  48.         if($user->activationKey == $key){
  49.             $user->active = "Y";
  50.             $user->activated = 1;
  51.             $user->save();
  52.             $this->flash->success('Uspješna aktivacija profila! Ulogirajte se na vaš profil.');
  53.             return $this->dispatcher->forward(array(
  54.             'controller' => 'index',
  55.             'action' => 'index'
  56.         ));
  57.         }
  58.         else{
  59.              $this->flash->error('Aktivacijska sifra nije tocna. Molimo kontaktirajte administratora!');
  60.              return $this->dispatcher->forward(array(
  61.             'controller' => 'index',
  62.             'action' => 'index'
  63.         ));
  64.         }
  65.     }
  66.  
  67.     public function resetPasswordAction()
  68.     {
  69.         $code = $this->dispatcher->getParam('code');
  70.  
  71.         $resetPassword = ResetPasswords::findFirstByCode($code);
  72.  
  73.         if (!$resetPassword) {
  74.             return $this->dispatcher->forward(array(
  75.                 'controller' => 'index',
  76.                 'action' => 'index'
  77.             ));
  78.         }
  79.  
  80.         if ($resetPassword->reset != 'N') {
  81.             return $this->dispatcher->forward(array(
  82.                 'controller' => 'session',
  83.                 'action' => 'login'
  84.             ));
  85.         }
  86.  
  87.         $resetPassword->reset = 'Y';
  88.  
  89.         /**
  90.          * Change the confirmation to 'reset'
  91.          */
  92.         if (!$resetPassword->save()) {
  93.  
  94.             foreach ($resetPassword->getMessages() as $message) {
  95.                 $this->flash->error($message);
  96.             }
  97.  
  98.             return $this->dispatcher->forward(array(
  99.                 'controller' => 'index',
  100.                 'action' => 'index'
  101.             ));
  102.         }
  103.  
  104.         /**
  105.          * Identify the user in the application
  106.          */
  107.         $this->auth->authUserById($resetPassword->usersId);
  108.  
  109.         $this->flash->success('Please reset your password');
  110.  
  111.         return $this->dispatcher->forward(array(
  112.             'controller' => 'users',
  113.             'action' => 'changePassword'
  114.         ));
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement