2 /********************************************************************
6 Copyright 2008 Radosław Pietruszewski
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ********************************************************************/
23 class User
extends Plugin
26 * private Model_User $User
28 * Instancja klasy Model_User
35 * Konstruktor. Uzupełnia pole $User.
38 public function User()
42 $this->User
= $this->load
->model('user');
46 * public bool Login(string $user, string $password, bool $autologin)
48 * Loguje użytkownika. Zwraca true, jeśli logowanie wypadło pomyślnie, w
49 * przeciwnym wypadku zwraca false.
51 * string $user - Nazwa użytkownika
52 * string $password - Hasło użytkownika (w czystej postaci)
53 * bool $autologin - Zalogować usera automatycznie przy każdej wizycie?
54 * TRUE - Tak, loguj mnie automatycznie
55 * FALSE - Nie loguj mnie automatycznie!
58 public function Login($user, $password, $autologin)
60 // Walidacja wprowadzonych danych
66 $errors[] = 'Pole <em>login</em> musi być wypełnione.';
71 $errors[] = 'Pole <em>hasło</em> musi być wypełnione.';
76 setH1('Błąd logowania');
78 echo $this->load
->view('login_loginerrors', array('errors' => $errors));
82 // sprawdzamy, czy user istnieje
84 $userdata = $this->User
->LoginUserData($user);
86 if($userdata->num_rows() == 0)
88 setH1('Błąd logowania');
90 $errors[] = 'Użytkownik <em>' . $user . '</em> nie istnieje.';
92 echo $this->load
->view('login_loginerrors', array('errors' => $errors));
96 // sprawdzamy poprawność hasła
98 $userdata = $userdata->to_obj();
100 if($userdata->password
!= strHash($password . $userdata->salt
, intval($userdata->hashalgo
)))
102 setH1('Błąd logowania');
104 $errors[] = 'Niepoprawne hasło.';
106 echo $this->load
->view('login_loginerrors', array('errors' => $errors));
110 echo 'bez błędów :P';
115 public function Register($user, $password, $password2, $email, $email2, $data)
120 public function GetUserData($dataname)
125 public function Logout()