<commit_before><?php

namespace Application\Model;

use Zend\Db\TableGateway\TableGateway;

class UsersTable {
    
    protected $tableGateway;
    
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
    }
    
    public function fetchAll()    {
        
        $resultSet = $this->tableGateway->select();
        return $resultSet;
    }
    
    public function getUsers($id)
    {
        $id  = (int) $id;
        $rowset = $this->tableGateway->select(array('id' => $id));
        $row = $rowset->current();
        if (!$row) {
            throw new \Exception("Could not find row $id");
        }
        return $row;
    }    
    
  
    public function saveUsers(Users $user)
    {
        if ($user->password)
        {
            $data = array(            
            'name'           => $user->name,
            'surname'        => $user->surname,
            'login'          => $user->login,
            'email'          => $user->email,
            'password'       => $<PASSWORD>,
            'role'           => $user->role,
            'verified'       => $user->verified,
                );
        } else {
            $data = array(            
            'name'           => $user->name,
            'surname'        => $user->surname,
            'login'          => $user->login,
            'email'          => $user->email,            
            'role'           => $user->role,
            'verified'       => $user->verified,
                );
        }
            

        $id = (int)$user->id;
        if ($id == 0) {
            $this->tableGateway->insert($data);
        } else {
            if ($this->getUsers($id)) {
                $this->tableGateway->update($data, array('id' => $id));
            } else {
                throw new \Exception('Form id does not exist');
            }
        }
    }
    
    /**
     * Sprawdza czy podany email istnieje w bazie. Funkcja dla ajxa
     * @param type $email
     * @return type
     */
    public function checkEmail($email)
    {
       
        $rowset = $this->tableGateway->select(array('email' => $email));
        $row = $rowset->count();
        
        return $row;
    }
    
    /**
     * Funkcja blokuje (ustawia verified na false) użytkownika
     * @param type $id
     */
    public function blockUsers($id)
    {
         $data = array(
            'verified'  =>  false
             );
        $this->tableGateway->update($data, array('id' => $id));
    }
    public function addUsers(Users $user)
    {
     
        $data = array(            
            'name'           => $user->name,
            'surname'        => $user->surname,
            'login'          => $user->login,
            'email'          => $user->email,
            'password'       => $<PASSWORD>,
            'role'           => $user->role,
            'verified'       => $user->verified,
            
        );
        $this->tableGateway->insert($data);
    }
    public function deleteUsers($id)
    {
        $this->tableGateway->delete(array('id' => $id));
    }
    
    /**
     * Zwraca id ostatniego dodanego rekordu
     * @return type
     */
    public function lastInsertId() {
        return $this->tableGateway->lastInsertValue;
    }
    
    public function verifiedUsers($id)
    {
        $data = array(
            'verified'  =>  '1'
        );
        $this->tableGateway->update($data, array('id' => $id));
    }
    /**
     * Zwraca wiersz apsujacy do pary login password
     * @param type $login
     * @param type $password
     * @return type
     * @throws \Exception
     */
    public function loginUsers($login,$password)
    {
        $rowset = $this->tableGateway->select(array('login' => $login,'password'=>$password,'verified'=>true));
        $row = $rowset->current();
        if (!$row) {
            throw new \Exception("Could not find row $login");
        }
        return $row;
    }
       
   
}

<commit_msg>- poprawka, przekierowanie w przypadku podania blednego hasla<commit_after><?php

namespace Application\Model;

use Zend\Db\TableGateway\TableGateway;

class UsersTable {
    
    protected $tableGateway;
    
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
    }
    
    public function fetchAll()    {
        
        $resultSet = $this->tableGateway->select();
        return $resultSet;
    }
    
    public function getUsers($id)
    {
        $id  = (int) $id;
        $rowset = $this->tableGateway->select(array('id' => $id));
        $row = $rowset->current();
        if (!$row) {
            throw new \Exception("Could not find row $id");
        }
        return $row;
    }    
    
  
    public function saveUsers(Users $user)
    {
        if ($user->password)
        {
            $data = array(            
            'name'           => $user->name,
            'surname'        => $user->surname,
            'login'          => $user->login,
            'email'          => $user->email,
            'password'       => $<PASSWORD>,
            'role'           => $user->role,
            'verified'       => $user->verified,
                );
        } else {
            $data = array(            
            'name'           => $user->name,
            'surname'        => $user->surname,
            'login'          => $user->login,
            'email'          => $user->email,            
            'role'           => $user->role,
            'verified'       => $user->verified,
                );
        }
            

        $id = (int)$user->id;
        if ($id == 0) {
            $this->tableGateway->insert($data);
        } else {
            if ($this->getUsers($id)) {
                $this->tableGateway->update($data, array('id' => $id));
            } else {
                throw new \Exception('Form id does not exist');
            }
        }
    }
    
    /**
     * Sprawdza czy podany email istnieje w bazie. Funkcja dla ajxa
     * @param type $email
     * @return type
     */
    public function checkEmail($email)
    {
       
        $rowset = $this->tableGateway->select(array('email' => $email));
        $row = $rowset->count();
        
        return $row;
    }
    
    /**
     * Funkcja blokuje (ustawia verified na false) użytkownika
     * @param type $id
     */
    public function blockUsers($id)
    {
         $data = array(
            'verified'  =>  false
             );
        $this->tableGateway->update($data, array('id' => $id));
    }
    public function addUsers(Users $user)
    {
     
        $data = array(            
            'name'           => $user->name,
            'surname'        => $user->surname,
            'login'          => $user->login,
            'email'          => $user->email,
            'password'       => $<PASSWORD>,
            'role'           => $user->role,
            'verified'       => $user->verified,
            
        );
        $this->tableGateway->insert($data);
    }
    public function deleteUsers($id)
    {
        $this->tableGateway->delete(array('id' => $id));
    }
    
    /**
     * Zwraca id ostatniego dodanego rekordu
     * @return type
     */
    public function lastInsertId() {
        return $this->tableGateway->lastInsertValue;
    }
    
    public function verifiedUsers($id)
    {
        $data = array(
            'verified'  =>  '1'
        );
        $this->tableGateway->update($data, array('id' => $id));
    }
    /**
     * Zwraca wiersz apsujacy do pary login password
     * @param type $login
     * @param type $password
     * @return type
     * @throws \Exception
     */
    public function loginUsers($login,$password)
    {
        $rowset = $this->tableGateway->select(array('login' => $login,'password'=>$password,'verified'=>true));
        $row = $rowset->current();
        if (!$row) {
            return false;
        }
        return $row;
    }
       
   
}


{'fraction_non_alphanumeric': 0.14075050953123128, 'fraction_numerical': 0.0004795588058985733, 'mean_word_length': 1.260092115957735, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 163, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5008429', 'n_tokens_mistral': 2455, 'n_tokens_neox': 2364, 'n_words': 462}