reszta plikow watermelona
[watermeloncms.git] / cms / wtrmln / modules / plugins / user.php
blobb7b8bfec6e2c7920cdd621362d6a604ccdd6eb2d
1 <?php
2 /********************************************************************
4 Watermelon CMS
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
30 private $User;
33 * public void User()
35 * Konstruktor. Uzupełnia pole $User.
38 public function User()
40 parent::Plugin();
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
62 if(empty($user))
64 $errors[] = 'Pole <em>login</em> musi być wypełnione.';
67 if(empty($password))
69 $errors[] = 'Pole <em>hasło</em> musi być wypełnione.';
72 if(isset($errors))
74 setH1('Błąd logowania');
76 echo $this->load->view('login_loginerrors', array('errors' => $errors));
77 return false;
80 // sprawdzamy, czy user istnieje
82 $userdata = $this->User->LoginUserData($user);
84 if($userdata->num_rows() == 0)
86 setH1('Błąd logowania');
88 $errors[] = 'Użytkownik <em>' . $user . '</em> nie istnieje.';
90 echo $this->load->view('login_loginerrors', array('errors' => $errors));
91 return false;
94 $userdata = $userdata->to_obj();
96 var_dump(intval($userdata->hashalgo));
98 if($userdata->password != strHash($password . $userdata->salt, intval($userdata->hashalgo)))
100 setH1('Błąd logowania');
102 $errors[] = 'Niepoprawne hasło.';
104 echo $this->load->view('login_loginerrors', array('errors' => $errors));
105 return false;
108 echo 'bez błędów :P';
110 //TODO
113 public function Register($user, $password, $password2, $email, $email2, $data)
115 //TODO
118 public function GetUserData($dataname)
120 //TODO
123 public function Logout()
125 //TODO
128 // TODO