Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [OOP][SMARTY] Logowanie
wembleyos
post
Post #1





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 24.10.2010

Ostrzeżenie: (0%)
-----


Witam, dręczy mnie pewien problem...nie potrafię logicznie wpaść na to, jak powinienem połączyć smarty z logowaniem w klasach. Napisałem na razie orientacyjnie proste sprawdzanie użytkownika (logowanie) Mam wszystko w osobnych plikach:

Klasa użytkownika znajduje się w classes/class.user.php
  1. <?
  2. class User {
  3. var $Login;
  4. var $Haslo;
  5. var $Zalogowany;
  6. var $DataTeraz;
  7. var $PodajLogin;
  8. var $PoprawDane;
  9.  
  10. public function __construct() {
  11. $this->Login=$_POST['login'];
  12. $this->Haslo=md5(md5($_POST['password']));
  13. $this->Zalogowany=$_SESSION['login'];
  14. $this->DataTeraz=date("d.m.Y, H:i:s");
  15. $this->PodajLogin="<b>Wystąpił błąd</b>: podaj login oraz hasło.";
  16. $this->PoprawDane="<b>Wystąpił błąd</b>: podane dane nie są poprawne.";
  17. }
  18.  
  19.  
  20.  
  21.  
  22. public function Autoryzacja($user, $haslo){
  23. $dane=mysql_fetch_assoc("SELECT * FROM `users` WHERE `login` = '".$this->Login."'");
  24.  
  25. if(isset($Login) && isset($Haslo)){
  26. if($dane['Login'] == $this->Login && $dane['Haslo'] == $this->Haslo){
  27.  
  28. /* ustawia zmienną sesyjną*/ $this->Zalogowany="".$dane['users_id']."";
  29. /* ustawia ciasteczko */ setcookie ("log" , "log", time()+3600, "/","", 0);
  30. /* OSTATNIA AKTYWNOŚĆ */ Wykonaj("UPDATE `users` SET `lastactive` = '".$this->DataTeraz."' WHERE `users_id` = '".$this->Zalogowany."'");
  31. /* przenosi na stronę główną */ header( "Location: index.php");
  32.  
  33. } else {
  34. $this->PoprawDane;);
  35. }
  36. } else {
  37. print $this->PodajLogin;
  38. }
  39.  
  40. }
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. }
  48.  
  49. ?>


Plik główny:
  1. <?
  2.  
  3. /* DOŁĄCZANIE WSZYSTKICH NIEZBĘDNYCH PLIKÓW */
  4. require("var/inc.default.php");
  5. require("var/config.php");
  6.  
  7. /* PRZYŁĄCZANIE KLAS */
  8. require_once("classes/class.user.php");
  9.  
  10.  
  11. Polacz("".$db_host."", "".$db_user."", "".$db_password."", "".$db."");
  12.  
  13. ...
  14.  
  15.  
  16. /* ---------------------------------------------------*/
  17. /* sekcja dla smarty */
  18. $styl="default"; // nazwa katalogu danego stylu strony
  19. require('smarty/Smarty.class.php');
  20. $smarty = new Smarty;
  21.  
  22. // przypisywanie zmiennych dla styli
  23. $smarty -> assign('tytul', 'Nasz strona testowa');
  24. $smarty -> assign('tekst', 'Jakis tam tekst');
  25.  
  26. // WYŚWIETLANIE STRONY Z WYKORZYSTANIEM SZABLONÓW
  27.  
  28. $smarty -> display(''.$styl.'/profil.tpl'); // *** TABELA PROFILU UŻYTKONIKA ***
  29. $smarty -> display(''.$styl.'/notifications.tpl'); // *** TABELA POWIADOMIEŃ ***
  30. $smarty -> display(''.$styl.'/body.tpl'); // *** WYŚWIETLAJĄCA SIĘ ZAWARTOŚĆ STRONY ***
  31. $smarty -> display(''.$styl.'/footer.tpl'); // *** STOPKA ***
  32. /* */
  33. /* ---------------------------------------------------*/
  34. ?>


Jak zaimplementować do smarty obiekt logowania?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 11:12