Exemple #1
0
 function indexAction()
 {
     $m = new Wtk_Form_Model('installation');
     $g = $m->addGroup('site', "Le site");
     $i = $g->addEnum('association', "Association", null, self::$associations);
     $m->addConstraintRequired($i);
     $g = $m->addGroup('admin', "Votre compte");
     $i = $g->addString('prenom', "Votre prénom");
     $m->addConstraintRequired($i);
     $i = $g->addString('nom', "Votre nom");
     $m->addConstraintRequired($i);
     $i = $g->addEnum('sexe', "Sexe", null, array('h' => 'Masculin', 'f' => 'Féminin'));
     $m->addConstraintRequired($i);
     $i = $g->addDate('naissance', "Date de naissance", 0);
     $m->addConstraintRequired($i);
     $i = $g->addString('adelec', "Adélec");
     $m->addConstraintRequired($i);
     $i = $i0 = $g->addString('motdepasse', "Mot de passe");
     $m->addConstraintRequired($i);
     $i = $i1 = $g->addString('confirmation', "Confirmation");
     $m->addConstraintEqual($i1, $i0);
     $this->view->model = $pm = new Wtk_Pages_Model_Form($m);
     if ($pm->validate()) {
         $installer = new Strass_Installer($m->get());
         $installer->run();
         /* Autologin. Écrire dans la session l'identité de l'admin */
         $t = new Users();
         $admin = $t->findByUsername($m->get('admin/adelec'));
         $auth = Zend_Auth::getInstance();
         $auth->getStorage()->write($admin->getIdentity());
         $this->_redirect('/', array('prependBase' => false, 'exit' => true));
     }
 }
Exemple #2
0
 function recouvrirAction()
 {
     $this->metas(array('DC.Title' => "Recouvrir l'accès à votre compte"));
     $token = $this->_getParam('confirmer');
     if ($token) {
         $t = new Users();
         try {
             $user = $t->findByRecoverToken($token);
         } catch (Strass_Db_Table_NotFound $e) {
             throw new Zend_Controller_Action_Exception("Jeton inconnu ou expiré", 404);
         }
         $this->view->set = $m = new Wtk_Form_Model('recouvrir');
         $i0 = $m->addString('nouveau', "Nouveau mot de passe");
         $i1 = $m->addString('confirmation', "Confirmer");
         $m->addConstraintRequired($i0);
         $m->addConstraintEqual($i1, $i0);
         $m->addNewSubmission('enregistrer', 'Enregistrer');
         if ($m->validate()) {
             $db = $t->getAdapter();
             $db->beginTransaction();
             try {
                 $this->view->individu = $individu = $user->findParentIndividus();
                 $user->username = $individu->adelec;
                 $user->setPassword($m->get('nouveau'));
                 $user->recover_token = null;
                 $user->save();
                 $this->logger->info("Recouvrement du compte", $this->_helper->Url('fiche', 'individus', null, array('individu' => $individu->slug)));
                 $db->commit();
             } catch (Exception $e) {
                 $db->rollBack();
                 throw $e;
             }
             $this->redirectSimple('index', 'unites');
         }
     } else {
         $this->view->send = $m = new Wtk_Form_Model('recouvrir');
         $m->addConstraintEMail($m->addString('adelec', "Votre adresse"));
         $m->addNewSubmission('envoyer', "Envoyer");
         if ($m->validate()) {
             $t = new Users();
             try {
                 $user = $t->findByEMail($m->get('adelec'));
             } catch (Zend_Db_Table_Exception $e) {
                 $m->errors[] = new Wtk_Form_Model_Exception('Adresse inconnue', $m->getInstance('adelec'));
                 return;
             }
             $individu = $user->findParentIndividus();
             $user->recover_token = md5(uniqid() . '-' . mt_rand(10000, 99999));
             /* Laisser une demi heure pour délivrer le message */
             $user->recover_deadline = time() + 30 * 60;
             $user->save();
             $this->view->mail = $mail = new Strass_Mail_Recover($user);
             $fn = trim(wtk_ucfirst($individu->prenom) . " " . $individu->capitalizedLastname());
             $mail->addTo($individu->adelec, $fn);
             $mail->send();
             $this->_helper->flash->info("Courriel envoyé", "Un courriel vous a été envoyé avec un lien vers la page " . "pour définir un nouveau mot de passe. Le lien expirera dans " . "une demi heure.");
             $this->redirectSimple('index', 'unites');
         }
     }
 }