LoginController.php

00001 <?php
00017 class User_LoginController extends Dsao_Controller_Action
00018 {
00019   public function preDispatch()
00020   {
00021     $this->_setDefaultModelClass('User_Login');
00022   }
00023 
00029   public function loginAction()
00030   {
00031     if ($this->getRequest()->isPost())
00032     {
00033       // Falls Benutzername leer, keine Fehlermeldung ausgeben.
00034       if (!$this->getRequest()->getPost('username'))
00035       {
00036         return false;
00037       }
00038 
00039       $username = $this->getRequest()->getPost('username');
00040       $password = $this->getRequest()->getPost('password');
00041 
00042       $validatorUsername = new Dsao_Validate_Username();
00043       $validatorPassword = new Dsao_Validate_Password();
00044 
00045       // Falls Benutzername und Passwort gueltig.
00046       if ($validatorUsername->isValid($username)
00047           && $validatorPassword->isValid($password))
00048       {
00049         // Benutzer anlegen.
00050         $user = new Dsao_User(array
00051           (
00052             'username' => $username,
00053             'password' => md5($password),
00054           ), false, true);
00055 
00056         // Falls Einloggen erfolgreich, auf vorherige Seite umleiten.
00057         if ($this->_getModel()->login($user, $this->getRequest()->getPost('autologin')))
00058         {
00059           $uriReturn = new Dsao_Uri_Http(str_replace('_', '/',
00060             $this->getUri()->getParameters('redirect', '_')));
00061 
00062           // Standardparameter setzen
00063           $uriReturn->setParameters(array(
00064             'action'      => 'show',
00065             'controller'  => 'index',
00066             'module'      => 'default'), false);
00067 
00068           // Weiterleiten
00069           $this->_gotoSimple($uriReturn->action, $uriReturn->controller,
00070             $uriReturn->module, $uriReturn->getParameters());
00071 
00072           return true;
00073         }
00074       }
00075       // Es wurden falsche Angaben gemacht.
00076       $this->getLog()->err('user_login_login_error_wrong_data');
00077     }
00078 
00079     // Link zum Umleiten zuweisen.
00080     $this->getView()->assign
00081       ('userLoginRedirect', $this->getUri()->redirect);
00082 
00083     return true;
00084   }
00085 
00091   public function logoutAction()
00092   {
00093     // Token
00094     if (!$this->getHelper('SessionToken')->hasValidToken())
00095     {
00096       return;
00097     }
00098 
00099     // Ausloggen
00100     $this->_getModel()->logout();
00101 
00102     // Auf Startseite umleiten
00103     $this->_gotoSimple('show', 'index', 'default');
00104   }
00105 
00116   public function passwordAction()
00117   {
00118     $this->getHelper('History')->setAddToHistory(true, false);
00119 
00120     // Falls Formular abgeschickt wurde
00121     if ($this->getRequest()->isPost())
00122     {
00123       // Falls weder Benutzername, noch E-Mail-Adresse angegeben wurden, abbrechen.
00124       if (!$this->getRequest()->getPost('username')
00125           && !$this->getRequest()->getPost('emailAddress'))
00126       {
00127         return false;
00128       }
00129 
00130       // Benutzerobjekt mit uebergebenen Daten erstellen.
00131       $user = new Dsao_User(array
00132         (
00133           'username'          => $this->getRequest()->getPost('username'),
00134           'emailAddress'     => $this->getRequest()->getPost('emailAddress'),
00135         ));
00136 
00137       // Falls kein gueltiger Benutzer gefunden werden konnte, abbrechen.
00138       if (!$user->isSynchronous(true))
00139       {
00140         // Fehlermeldung ausgeben.
00141         $this->getLog()->err('user_login_password_error_user_not_found');
00142 
00143         return false;
00144       }
00145 
00146       // neues Passwort erstellen
00147       $user->passwordNew = Dsao_Hash_Password::factory();
00148 
00149       // User-Hash erstellen
00150       $user->hash = Dsao_Hash_User::factory($user->passwordNew->getHash(),
00151         '/user/login/password', array('idUser'  => $user->getId()));
00152 
00153       // Hash in Tabelle einfügen
00154       $user->hash->insert();
00155 
00156       // Falls Verschicken der Mail mit neuem Passwort fehlschlug,
00157       // Fehlermeldung ausgeben.
00158       if (!$this->_getModel()->sendNewPasswordMail($user))
00159       {
00160         $this->getLog()->err('email_error_sent');
00161 
00162         return false;
00163       }
00164 
00165       // Bestaetigung anzeigen.
00166       $this->getLog()->affirm
00167         ('user_login_password_affirmation_email_sent');
00168 
00169       return true;
00170     }
00171 
00172     // Falls Parameter übergeben wurden
00173     // @todo Datenbankoperationen ins Modell auslagern
00174     if ($this->getUri()->hasParameters())
00175     {
00176       // User-Hash erstellen
00177       $hashUser = Dsao_Hash_User::factory(null, $this->getUri());
00178 
00179       // Falls Parameter ungültig sind, Fehlermeldung ausgeben
00180       if (!$hashUser->isValid())
00181       {
00182         $this->getLog()->err('user_login_password_error_invalid_link');
00183 
00184         return false;
00185       }
00186 
00187       // Benutzer erstellen.
00188       $user = new Dsao_User(array
00189         (
00190           'id'        => $hashUser->idUser,
00191           'password'  => $hashUser->hash,
00192         ));
00193 
00194       // Neues Passwort in der Datenbank setzen.
00195       $user->updateData('password');
00196 
00197       // Bestaetigung anzeigen.
00198       $this->getLog()->affirm
00199         ('user_login_password_affirmation_changed');
00200 
00201       return true;
00202     }
00203 
00204     // Hinweis fuer neues Passwort.
00205     $this->getLog()->info('user_login_password_info_new');
00206 
00207     return true;
00208   }
00209 }

Erzeugt am Fri Sep 18 19:04:11 2009 für DSA online - Morgendaemmerung von  doxygen 1.5.7.1