diff options
| author | 2012-10-25 19:06:32 +0200 | |
|---|---|---|
| committer | 2012-10-25 19:06:32 +0200 | |
| commit | 3ff51a59ba97f3ef1df3c26df16d9a3ab5789843 (patch) | |
| tree | 89de7b553f5b8240ad0d9f766800973f9845a121 /app/controllers | |
| parent | 48a1aa7d52e712d5f64a33a003b31f23a00b99f5 (diff) | |
Ajout fonctionnalité connexion avec Persona (à améliorer sans doute)
Diffstat (limited to 'app/controllers')
| -rwxr-xr-x | app/controllers/configureController.php | 13 | ||||
| -rwxr-xr-x | app/controllers/entryController.php | 7 | ||||
| -rwxr-xr-x | app/controllers/feedController.php | 181 | ||||
| -rwxr-xr-x | app/controllers/indexController.php | 39 |
4 files changed, 160 insertions, 80 deletions
diff --git a/app/controllers/configureController.php b/app/controllers/configureController.php index 849066ad7..68fa0404a 100755 --- a/app/controllers/configureController.php +++ b/app/controllers/configureController.php @@ -1,6 +1,15 @@ <?php class configureController extends ActionController { + public function firstAction () { + if (login_is_conf ($this->view->conf) && !is_logged ()) { + Error::error ( + 403, + array ('error' => array ('Vous n\'avez pas le droit d\'accéder à cette page')) + ); + } + } + public function categorizeAction () { $catDAO = new CategoryDAO (); @@ -69,12 +78,14 @@ class configureController extends ActionController { $display = Request::param ('display_posts', 'no'); $sort = Request::param ('sort_order', 'low_to_high'); $old = Request::param ('old_entries', 3); + $mail = Request::param ('mail_login', false); $this->view->conf->_postsPerPage (intval ($nb)); $this->view->conf->_defaultView ($view); $this->view->conf->_displayPosts ($display); $this->view->conf->_sortOrder ($sort); $this->view->conf->_oldEntries ($old); + $this->view->conf->_mailLogin ($mail); $values = array ( 'posts_per_page' => $this->view->conf->postsPerPage (), @@ -82,11 +93,13 @@ class configureController extends ActionController { 'display_posts' => $this->view->conf->displayPosts (), 'sort_order' => $this->view->conf->sortOrder (), 'old_entries' => $this->view->conf->oldEntries (), + 'mail_login' => $this->view->conf->mailLogin (), ); $confDAO = new RSSConfigurationDAO (); $confDAO->update ($values); Session::_param ('conf', $this->view->conf); + Session::_param ('mail', $this->view->conf->mailLogin ()); } } diff --git a/app/controllers/entryController.php b/app/controllers/entryController.php index 3d9734ca9..cf510e362 100755 --- a/app/controllers/entryController.php +++ b/app/controllers/entryController.php @@ -2,6 +2,13 @@ class entryController extends ActionController { public function firstAction () { + if (login_is_conf ($this->view->conf) && !is_logged ()) { + Error::error ( + 403, + array ('error' => array ('Vous n\'avez pas le droit d\'accéder à cette page')) + ); + } + $ajax = Request::param ('ajax'); if ($ajax) { $this->view->_useLayout (false); diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php index 4ef4039f6..0c0528202 100755 --- a/app/controllers/feedController.php +++ b/app/controllers/feedController.php @@ -2,46 +2,53 @@ class feedController extends ActionController { public function addAction () { - if (Request::isPost ()) { - $url = Request::param ('url_rss'); + if (login_is_conf ($this->view->conf) && !is_logged ()) { + Error::error ( + 403, + array ('error' => array ('Vous n\'avez pas le droit d\'accéder à cette page')) + ); + } else { + if (Request::isPost ()) { + $url = Request::param ('url_rss'); - try { - $feed = new Feed ($url); - $feed->load (); - - $feedDAO = new FeedDAO (); - $values = array ( - 'id' => $feed->id (), - 'url' => $feed->url (), - 'category' => null, - 'name' => $feed->name (), - 'website' => $feed->website (), - 'description' => $feed->description (), - ); - $feedDAO->addFeed ($values); + try { + $feed = new Feed ($url); + $feed->load (); - $entryDAO = new EntryDAO (); - $entries = $feed->entries (); - foreach ($entries as $entry) { + $feedDAO = new FeedDAO (); $values = array ( - 'id' => $entry->id (), - 'guid' => $entry->guid (), - 'title' => $entry->title (), - 'author' => $entry->author (), - 'content' => $entry->content (), - 'link' => $entry->link (), - 'date' => $entry->date (true), - 'is_read' => $entry->isRead (), - 'is_favorite' => $entry->isFavorite (), - 'id_feed' => $feed->id () + 'id' => $feed->id (), + 'url' => $feed->url (), + 'category' => null, + 'name' => $feed->name (), + 'website' => $feed->website (), + 'description' => $feed->description (), ); - $entryDAO->addEntry ($values); + $feedDAO->addFeed ($values); + + $entryDAO = new EntryDAO (); + $entries = $feed->entries (); + foreach ($entries as $entry) { + $values = array ( + 'id' => $entry->id (), + 'guid' => $entry->guid (), + 'title' => $entry->title (), + 'author' => $entry->author (), + 'content' => $entry->content (), + 'link' => $entry->link (), + 'date' => $entry->date (true), + 'is_read' => $entry->isRead (), + 'is_favorite' => $entry->isFavorite (), + 'id_feed' => $feed->id () + ); + $entryDAO->addEntry ($values); + } + } catch (Exception $e) { + // TODO ajouter une erreur : url non valide } - } catch (Exception $e) { - // TODO ajouter une erreur : url non valide - } - Request::forward (array (), true); + Request::forward (array (), true); + } } } @@ -78,64 +85,78 @@ class feedController extends ActionController { } public function massiveImportAction () { - $entryDAO = new EntryDAO (); - $feedDAO = new FeedDAO (); - $catDAO = new CategoryDAO (); + if (login_is_conf ($this->view->conf) && !is_logged ()) { + Error::error ( + 403, + array ('error' => array ('Vous n\'avez pas le droit d\'accéder à cette page')) + ); + } else { + $entryDAO = new EntryDAO (); + $feedDAO = new FeedDAO (); + $catDAO = new CategoryDAO (); - $categories = Request::param ('categories', array ()); - $feeds = Request::param ('feeds', array ()); + $categories = Request::param ('categories', array ()); + $feeds = Request::param ('feeds', array ()); - foreach ($categories as $cat) { - $values = array ( - 'id' => $cat->id (), - 'name' => $cat->name (), - 'color' => $cat->color () - ); - $catDAO->addCategory ($values); - } + foreach ($categories as $cat) { + $values = array ( + 'id' => $cat->id (), + 'name' => $cat->name (), + 'color' => $cat->color () + ); + $catDAO->addCategory ($values); + } - foreach ($feeds as $feed) { - $feed->load (); - $entries = $feed->entries (); + foreach ($feeds as $feed) { + $feed->load (); + $entries = $feed->entries (); - // Chargement du flux - foreach ($entries as $entry) { + // Chargement du flux + foreach ($entries as $entry) { + $values = array ( + 'id' => $entry->id (), + 'guid' => $entry->guid (), + 'title' => $entry->title (), + 'author' => $entry->author (), + 'content' => $entry->content (), + 'link' => $entry->link (), + 'date' => $entry->date (true), + 'is_read' => $entry->isRead (), + 'is_favorite' => $entry->isFavorite (), + 'id_feed' => $feed->id () + ); + $entryDAO->addEntry ($values); + } + + // Enregistrement du flux $values = array ( - 'id' => $entry->id (), - 'guid' => $entry->guid (), - 'title' => $entry->title (), - 'author' => $entry->author (), - 'content' => $entry->content (), - 'link' => $entry->link (), - 'date' => $entry->date (true), - 'is_read' => $entry->isRead (), - 'is_favorite' => $entry->isFavorite (), - 'id_feed' => $feed->id () + 'id' => $feed->id (), + 'url' => $feed->url (), + 'category' => $feed->category (), + 'name' => $feed->name (), + 'website' => $feed->website (), + 'description' => $feed->description (), ); - $entryDAO->addEntry ($values); + $feedDAO->addFeed ($values); } - - // Enregistrement du flux - $values = array ( - 'id' => $feed->id (), - 'url' => $feed->url (), - 'category' => $feed->category (), - 'name' => $feed->name (), - 'website' => $feed->website (), - 'description' => $feed->description (), - ); - $feedDAO->addFeed ($values); - } - Request::forward (array ('c' => 'configure', 'a' => 'importExport')); + Request::forward (array ('c' => 'configure', 'a' => 'importExport')); + } } public function deleteAction () { - $id = Request::param ('id'); + if (login_is_conf ($this->view->conf) && !is_logged ()) { + Error::error ( + 403, + array ('error' => array ('Vous n\'avez pas le droit d\'accéder à cette page')) + ); + } else { + $id = Request::param ('id'); - $feedDAO = new FeedDAO (); - $feedDAO->deleteFeed ($id); + $feedDAO = new FeedDAO (); + $feedDAO->deleteFeed ($id); - Request::forward (array ('c' => 'configure', 'a' => 'flux')); + Request::forward (array ('c' => 'configure', 'a' => 'flux')); + } } } diff --git a/app/controllers/indexController.php b/app/controllers/indexController.php index e7e3797ef..6db825ea6 100755 --- a/app/controllers/indexController.php +++ b/app/controllers/indexController.php @@ -2,6 +2,10 @@ class indexController extends ActionController { public function indexAction () { + View::appendScript (Url::display ('/scripts/smoothscroll.js')); + View::appendScript (Url::display ('/scripts/shortcut.js')); + View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'main'))); + $entryDAO = new EntryDAO (); $catDAO = new CategoryDAO (); @@ -42,4 +46,39 @@ class indexController extends ActionController { Request::forward (array (), true); } + + public function loginAction () { + $this->view->_useLayout (false); + + $url = 'https://verifier.login.persona.org/verify'; + $assert = Request::param ('assertion'); + $params = 'assertion=' . $assert . '&audience=' . + urlencode (Url::display () . ':80'); + $ch = curl_init (); + $options = array ( + CURLOPT_URL => $url, + CURLOPT_RETURNTRANSFER => TRUE, + CURLOPT_POST => 2, + CURLOPT_POSTFIELDS => $params + ); + curl_setopt_array ($ch, $options); + $result = curl_exec ($ch); + curl_close ($ch); + + $res = json_decode ($result, true); + if ($res['status'] == 'okay' && $res['email'] == $this->view->conf->mailLogin ()) { + Session::_param ('mail', $res['email']); + } else { + $res = array (); + $res['status'] = 'failure'; + $res['reason'] = 'L\'identifiant est invalide'; + } + + $this->view->res = json_encode ($res); + } + + public function logoutAction () { + $this->view->_useLayout (false); + Session::_param ('mail'); + } } |
