Example #1
0
 public function login($userId = null)
 {
     if (!$userId) {
         $userId = $this->getRequest()->request->get('user', '');
     }
     $user = new User($userId);
     $code = $this->ion_auth->getManagerCode();
     if ($code && ($manager = $this->ion_auth->codeManagerExist($code))) {
         if (!$manager->isManager($userId)->exists()) {
             $error[] = 'You are not a manager of this user';
         }
         if ($this->get('core.status.system')->isPaymentEnabled() && !$user->hasActiveSubscription()) {
             $error[] = 'Selected customer do not have an active subscription';
         }
         if ($this->ion_auth->is_admin($userId) || $this->ion_auth->is_manager($userId)) {
             $error[] = 'User is not a simple member';
         }
         if (empty($error)) {
             $manager->manager_code = $this->ion_auth->createManagerCode();
             $manager->manager_login_as = $userId;
             if ($manager->save()) {
                 $ionAuth = new Ion_auth_model();
                 $ionAuth->loginForce($user->email);
                 $this->addFlash('You are succesfully login as another user', 'success');
             }
         } else {
             foreach ($error as $e) {
                 $this->addFlash($e);
             }
             //$this->template->set('email', $manager->manager_user->get()->email);
             $this->template->render('manager');
             return;
         }
     }
     redirect();
 }
Example #2
0
 /**
  * Check if user has an active payment
  *
  * @param int $userId   
  */
 protected function checkActiveSubscription($userId)
 {
     $user = new User($userId);
     if (!$user->hasActiveSubscription() && $this->router->fetch_class() != 'payment' && $this->router->fetch_class() != 'subscript') {
         if ($this->ion_auth->is_collaborator()) {
             $this->addFlash('Your major user don`t have active subscription');
             redirect('auth/login');
         } else {
             $this->template->set('no_subscription', true);
             $this->template->set('last_plan_id', $this->c_user->getLastSubscription()->plan_id);
         }
     }
 }