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