]> dev.renevier.net Git - syj.git/blob - application/controllers/PendingController.php
make release.py script simpler
[syj.git] / application / controllers / PendingController.php
1 <?php
2 /*  This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
3     and is published under the AGPL license. */
4
5 class PendingController extends Zend_Controller_Action
6 {
7
8     public function init() {
9         $this->view->headLink()->appendStylesheet('css/generic.css', 'all');
10         $this->view->headLink()->appendStylesheet('css/form.css', 'all');
11         $this->view->headLink()->appendStylesheet('css/pending.css', 'all');
12     }
13
14     public function indexAction() {
15         $request = $this->getRequest();
16         $response = $this->getResponse();
17         $hash = $request->idx;
18
19         $pendingMapper = new Syj_Model_PendingMapper();
20         $pending = $pendingMapper->fetchByHash($hash);
21         if (!isset($pending)) {
22             throw new Syj_Exception_NotFound('Not Found', 404);
23         }
24
25         $formData = $request->getPost();
26
27         switch ($pending->action) {
28             case 'validate_creation':
29             if (array_key_exists('pending_validate', $formData)) {
30                     if (!$pending->run()) {
31                         throw new Syj_Exception();
32                     }
33                     $title = $this->view->translate("account validated");
34                     $this->_helper->ViewRenderer->setViewScriptPathSpec(':controller/creation_validate.:suffix');
35
36                 } else if (array_key_exists('pending_cancel', $formData)) {
37                     if (!$pending->cancel()) {
38                         throw new Syj_Exception();
39                     }
40                     $title = $this->view->translate("account deleted");
41                     $this->_helper->ViewRenderer->setViewScriptPathSpec(':controller/creation_cancel.:suffix');
42                 } else {
43                     $this->view->form = new Syj_Form_Pending_ValidateCreation($pending, array('name' => 'pendingform'));
44                     $title = $this->view->translate('account creation validation');
45                 }
46             break;
47             case 'reset_password':
48                 if (array_key_exists('pending_validate', $formData)) {
49                     if (!$pending->run()) {
50                         throw new Syj_Exception();
51                     }
52                     $this->view->newpwd = $pending->newpwd;
53
54                     $title = $this->view->translate("password changed");
55                     $this->_helper->ViewRenderer->setViewScriptPathSpec(':controller/password_validate.:suffix');
56                     $this->_helper->SyjUserManager->logout();
57
58                 } else if (array_key_exists('pending_cancel', $formData)) {
59                     if (!$pending->cancel()) {
60                         throw new Syj_Exception();
61                     }
62                     $title = $this->view->translate("request canceled");
63                     $this->_helper->ViewRenderer->setViewScriptPathSpec(':controller/password_cancel.:suffix');
64                 } else {
65                     $this->view->form = new Syj_Form_Pending_ResetPassword($pending, array('name' => 'pendingform'));
66                     $title = $this->view->translate('password reset validation');
67                 }
68             break;
69             default:
70                 throw new Syj_Exception_Request();
71             break;
72         }
73
74         $this->view->headTitle($title);
75     }
76
77 }