public function listAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         try {
             if (empty($data["admin_id"])) {
                 throw new Exception($this->_("The admin_id parameter is required"));
             }
             $admin = new Admin_Model_Admin();
             $admin->find($data["admin_id"]);
             if (!$admin->getId()) {
                 throw new Exception($this->_("This admin does not exist"));
             }
             $applications = array();
             foreach ($admin->getApplications() as $application) {
                 if (!$application->isActive()) {
                     continue;
                 }
                 $icon = null;
                 if ($application->getIcon()) {
                     $icon = $this->getRequest()->getBaseUrl() . $application->getIcon();
                 }
                 $application->addData(array("url" => $application->getUrl(), "icon" => $icon, 'startup_image_url' => str_replace("//", "/", $this->getRequest()->getBaseUrl() . $application->getStartupImageUrl()), 'retina_startup_image_url' => str_replace("//", "/", $this->getRequest()->getBaseUrl() . $application->getStartupImageUrl("retina"))));
                 $applications[] = $application->getData();
             }
             $data = array("success" => 1, "applications" => $applications);
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
Esempio n. 2
0
 public function createAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         try {
             if (isset($data["id"])) {
                 unset($data["id"]);
             }
             if (isset($data["app_id"])) {
                 unset($data["app_id"]);
             }
             if (empty($data["name"])) {
                 throw new Exception($this->_("The name is required"));
             }
             if (empty($data["user_id"])) {
                 throw new Exception($this->_("This admin does not exist"));
             }
             $admin = new Admin_Model_Admin();
             $admin->find($data["user_id"]);
             if (!$admin->getId()) {
                 throw new Exception($this->_("This admin does not exist"));
             }
             $application = new Application_Model_Application();
             $this->__checkKeyAndDomain($data, $application);
             $application->addData($data)->addAdmin($admin)->save();
             $data = array("success" => 1, "app_id" => $application->getId(), "app_url" => $application->getUrl());
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
Esempio n. 3
0
 public function saveAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $message = '';
             // Récupère le commerçe en cours
             $admin = $this->getSession()->getAdmin();
             if (empty($datas['url_key'])) {
                 throw new Exception($this->_('Please enter a subdomain.'));
             }
             if (preg_match("#[^a-z0-9]#", $datas['url_key'])) {
                 throw new Exception($this->_('Your mobile address should not contain special characters'));
             }
             $dummy = new Admin_Model_Admin();
             if ($dummy->find($datas['url_key'], 'url_key')->getId()) {
                 throw new Exception($this->_('We are sorry but this address is already used.'));
             }
             $admin->setUrlKey($datas['url_key'])->save();
             $html = array('success' => '1', 'success_message' => $message, 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage());
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
Esempio n. 4
0
 public function canPublishThemself()
 {
     $publication_type = System_Model_Config::getValueFor("system_publication_access_type");
     $admin = new Admin_Model_Admin();
     $admin->find($this->getApplication()->getAdminId());
     $publish_rights = $admin->getPublicationAccessType() ? $admin->getPublicationAccessType() : $publication_type;
     return $publish_rights == 'sources';
 }
Esempio n. 5
0
 public function loginasAction()
 {
     if ($admin_id = $this->getRequest()->getParam("admin_id")) {
         $admin = new Admin_Model_Admin();
         $admin->find($admin_id);
         if ($admin->getId()) {
             $key = sha1($admin->getFirstname() . $admin->getId());
             if ($key == $this->getRequest()->getParam('key', 'aa')) {
                 $front_session = $this->getSession('front');
                 $front_session->resetInstance()->setAdmin($admin);
                 $this->_redirect('');
                 return $this;
             }
         }
     }
 }
 public function deleteAction()
 {
     if ($admin_id = $this->getRequest()->getParam('admin_id')) {
         try {
             $admin = new Admin_Model_Admin();
             $admin->find($admin_id);
             if (!$admin->getId()) {
                 throw new Exception($this->_("This administrator does not exist"));
             }
             $admin->delete();
             $html = array('success' => 1, 'admin_id' => $admin_id);
         } catch (Exception $e) {
             $html = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->_sendHtml($html);
     }
 }
Esempio n. 7
0
 public function saveAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             if (!Zend_Validate::is($data["email"], "emailAddress")) {
                 throw new Exception($this->_("Please, enter a correct email address."));
             }
             $admin = new Admin_Model_Admin();
             $dummy = new Admin_Model_Admin();
             $dummy->find($data["email"], "email");
             $isNew = true;
             $data["confirm_password"] = !empty($data["confirm_password"]) ? $data["confirm_password"] : "";
             if (!empty($data["id"])) {
                 $admin->find($data["id"]);
                 $isNew = !$admin->getId();
             }
             if ($isNew and empty($data["password"])) {
                 throw new Exception($this->_("Please, enter a password."));
             }
             if (empty($data["password"]) and empty($data["confirm_password"])) {
                 unset($data["password"]);
                 unset($data["confirm_password"]);
             }
             if (!empty($data["password"]) and $data["password"] != $data["confirm_password"]) {
                 throw new Exception($this->_("Passwords don't match"));
             }
             $admin->addData($data);
             if ($dummy->getEmail() == $admin->getEmail() and $dummy->getId() != $admin->getId()) {
                 throw new Exception($this->_("We are sorry but this email address already exists."));
             }
             if (!empty($data["password"])) {
                 $admin->setPassword($data["password"]);
             }
             if (!empty($data["publication_access_type"])) {
                 $admin->setPublicationAccessType($data["publication_access_type"]);
             }
             $admin->save();
             $data = array("success" => 1, "message" => $this->_("User successfully saved"));
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
Esempio n. 8
0
 public function setaddpageAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             if (empty($data["admin_id"]) or empty($data["app_id"])) {
                 throw new Exception($this->_("An error occurred while saving. Please try again later."));
             }
             $admin = new Admin_Model_Admin();
             $admin->find($data["admin_id"]);
             $application = new Application_Model_Application();
             $application->find($data["app_id"]);
             if (!$admin->getId() or !$application->getId()) {
                 throw new Exception($this->_("An error occurred while saving. Please try again later."));
             }
             $admin->setIsAllowedToAddPages(!empty($data["can_add_page"]))->save();
             $data = array("success" => 1, "message" => $this->_("Data saved successfully."));
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
 public function autologinAction()
 {
     if ($email = $this->getRequest()->getParam("email") and $token = $this->getRequest()->getParam("token")) {
         try {
             $admin = new Admin_Model_Admin();
             $admin->find($email, "email");
             if (!$admin->getId()) {
                 throw new Exception($this->_("The user doesn't exist."));
             }
             if ($admin->getLoginToken() != $token) {
                 throw new Exception($this->_("Authentication failed"));
             }
             $this->getSession()->setAdmin($admin);
             $this->_redirect("admin/application/list");
         } catch (Exception $e) {
         }
     }
 }
Esempio n. 10
0
 public function __construct($params)
 {
     $admin = new Admin_Model_Admin();
     $admin->find($params['id']);
     $this->setObject($admin);
 }
Esempio n. 11
0
 public function getOwner()
 {
     $admin = new Admin_Model_Admin();
     $admin->find($this->getAdminId());
     return $admin;
 }