public function processLogin()
 {
     require_once dirname(__FILE__) . '../../../../modules/designer/designer.php';
     $themeName = trim(Tools::getValue('theme_name'));
     $passwd = trim(Tools::getValue('passwd'));
     $email = trim(Tools::getValue('email'));
     $domain = getSessionDomain($themeName);
     $version = function_exists('theme_get_manifest_version') ? '&ver=' . theme_get_manifest_version($themeName) : '';
     $desktop = function_exists('getDesktopParams') ? getDesktopParams() : '';
     if (empty($email)) {
         $this->errors[] = Tools::displayError('E-mail is empty');
     } elseif (!Validate::isEmail($email)) {
         $this->errors[] = Tools::displayError('Invalid e-mail address');
     }
     if (empty($passwd)) {
         $this->errors[] = Tools::displayError('Password is blank');
     } elseif (!Validate::isPasswd($passwd)) {
         $this->errors[] = Tools::displayError('Invalid password');
     }
     if (!count($this->errors)) {
         $this->context->employee = new Employee();
         $is_employee_loaded = $this->context->employee->getByemail($email, $passwd);
         $employee_associated_shop = $this->context->employee->getAssociatedShops();
         if (!$is_employee_loaded) {
             $this->errors[] = Tools::displayError('Employee does not exist or password is incorrect.');
             $this->context->employee->logout();
         } elseif (empty($employee_associated_shop) && !$this->context->employee->isSuperAdmin()) {
             $this->errors[] = Tools::displayError('Employee does not manage any shop anymore (shop has been deleted or permissions have been removed).');
             $this->context->employee->logout();
         } else {
             $this->context->employee->remote_addr = ip2long(Tools::getRemoteAddr());
             $cookie = Context::getContext()->cookie;
             $cookie->id_employee = $this->context->employee->id;
             $cookie->email = $this->context->employee->email;
             $cookie->profile = $this->context->employee->id_profile;
             $cookie->passwd = $this->context->employee->passwd;
             $cookie->remote_addr = $this->context->employee->remote_addr;
             $cookie->write();
             if (Tools::getIsset('theme_name')) {
                 $url = $this->context->link->getAdminLink('AdminAjax') . '&ajax=1' . $domain . $version . $desktop;
             } else {
                 $tab = new Tab((int) $this->context->employee->default_tab);
                 $url = $this->context->link->getAdminLink($tab->class_name);
             }
             if (Tools::isSubmit('ajax')) {
                 die(Tools::jsonEncode(array('hasErrors' => false, 'redirect' => $url)));
             } else {
                 $this->redirect_after = $url;
             }
         }
     }
     if (Tools::isSubmit('ajax')) {
         die(Tools::jsonEncode(array('hasErrors' => true, 'errors' => $this->errors)));
     }
 }
 public static function buildThemesData($currentIndex = '', $adminDir = '')
 {
     $token = Designer::getToken();
     $baseUrl = Designer::getBaseUrlWithLastSlash();
     $themesUrl = $baseUrl . 'themes';
     $adminUrl = $baseUrl . $adminDir . '/' . ($currentIndex ? $currentIndex : 'index.php?controller=AdminAjax') . '&token=' . $token;
     $shop = Designer::getShop();
     $themes = array();
     foreach (Theme::getAvailable(false) as $themeName) {
         if (strpos($themeName, _PREVIEW_SUFFIX_) !== FALSE || !file_exists(getProjectPath($themeName))) {
             continue;
         }
         $id = Designer::getThemeId($themeName);
         $themeUrl = $themesUrl . '/' . $themeName;
         $url = $adminUrl . '&theme_name=' . $themeName;
         $themes['themes'][$themeName] = array('themeName' => $themeName, 'thumbnailUrl' => $themeUrl . '/preview.jpg', 'openUrl' => $url . '&ajax=1&ver=' . theme_get_manifest_version($themeName) . getDesktopParams(), 'settingsUrl' => $url . '&edit=1', 'isActive' => $id && $shop->id_theme == $id);
     }
     return $themes;
 }