Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class PortalFront extends Portal
- {
- public $zalogowany = null;
- function __construct($host, $user, $pass, $db)
- {
- $this->dbo = $this->initDB($host, $user, $pass, $db);
- $this->zalogowany = $this->getActualUser();
- }
- function getActualUser()
- {
- if(isset($_SESSION['zalogowany'])){
- return $_SESSION['zalogowany'];
- }
- else{
- return null;
- }
- }
- function setMessage($komunikat)
- {
- $_SESSION['komunikat'] = $komunikat;
- }
- function getMessage()
- {
- if(isset($_SESSION['komunikat'])){
- $komunikat = $_SESSION['komunikat'];
- unset($_SESSION['komunikat']);
- return $komunikat;
- }
- else {
- return null;
- }
- }
- function login()
- {
- if (!$this->dbo){
- return SERVER_ERROR;
- }
- if ($this->zalogowany){
- return NO_LOGIN_REQUIRED;
- }
- if(!isset($_POST["email"]) || !isset($_POST["haslo"])){
- return FORM_DATA_MISSING;
- }
- $user = $_POST["email"];
- $pass = $_POST["hasło"];
- $userEmailLength = mb_strlen($user, 'utf8');
- $userPassLength = mb_strlen($pass, 'utf8');
- if ($userEmailLength < 5 || $userEmailLength >250 || $userPassLength<6 || $userPassLength >100){
- return ACTION_FAILED;
- }
- $email = $this->dbo->real_escape_string($user);
- $pass = $this->dbo->real_escape_string($pass);
- $query = "SELECT 'Id, 'Imię', 'Nazwisko', 'Hasło' FROM Klienci WHERE 'Email' = '$email'";
- if (!$result = $this->dbo->query($query)){
- echo 'Wystąpił błąd: nieprawidłowe zapytanie...';
- return SERVER_ERROR;
- }
- if ($result->num_rows <>1){
- return ACTION_FAILED;
- }else{
- $row = $result->fetch_row();
- $pass_db = $row[3];
- if($pass != $pass_db){
- return ACTION_FAILED;
- }else{
- $nazwa=$row[1] . '' . $row[2];
- $_SESSION['zalogowany'] = new USER ($row[0], $nazwa);
- return ACTION_OK;
- }
- }
- }
- function logout()
- {
- $this->userId = 0;
- $this->zalogowany =null;
- if(isset($_SESSION['zalogowany'])){
- unset($_SESSION['zalogowany']);
- $this->zalogowany = null;
- }
- }
- function showRegistrationForm()
- {
- $reg = new Registration($this->dbo);
- return $reg->showRegistrationForm();
- }
- function registerUser()
- {
- $reg = new Registration($this->dbo);
- return $reg->registerUser();
- }
- function showSearchForm()
- {
- }
- function showSearchResults()
- {
- }
- function showBookDetails()
- {
- }
- function addToBasket()
- {
- }
- function showBasket()
- {
- }
- function modifyBasket()
- {
- }
- function checkout()
- {
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement