Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Users
- {
- public $loggedIn = false,
- $id = 0,
- $userName = 'Guest',
- $data = '',
- $iCore;
- public function Users( Core $core )
- {
- $this->iCore = $core;
- $this->searchForSessions();
- }
- protected function searchForSessions()
- {
- $x = array('_userName', '_passWord', '_cacheData');
- $y = true;
- $z = md5( db::$prefix );
- foreach( $x as $q )
- {
- if( empty( $_SESSION[ $z . $q ] ) )
- {
- $y = false;
- break;
- }
- }
- if( !$y )
- {
- return false;
- }
- $this->loggedIn = (bool)
- $this->iCore->db()
- ->newQuery()
- ->Query("SELECT null FROM users WHERE username = ? AND password = ? LIMIT 1;")
- ->bind('ss', $_SESSION[ $z . $x[ 0 ] ], $_SESSION[ $z . $x[ 1 ] ] )
- ->count() > 0 ? true : false;
- $this->data = $_SESSION[ $z . '_cacheData' ];
- return $this->loggedIn;
- }
- public function login( $u = '', $p = '' )
- {
- //p:r
- if( !$u || !$p ) return 'All fields are required';
- $fetch = $this->iCore->db()
- ->newQuery()
- ->Query("
- SELECT
- u.*, b.expire, b.reason
- FROM
- users AS u
- LEFT JOIN
- bans AS b
- ON
- ( u.username = b.value OR b.value = ? ) AND ( UNIX_TIMESTAMP() - b.expire < 0 )
- WHERE
- u.username = ?
- AND
- u.password = ?
- LIMIT 1;
- ")
- ->bind( 'sss', $_SERVER['REMOTE_ADDR'], $u, $p )
- ->fetch();
- $x = md5( db::$prefix );
- if( !empty( $fetch['reason'] ) || !empty( $fetch['expire'] ) )
- {
- //p:r
- return sprintf( 'You are banned until %s because %s', date( 'd/m/Y h:i', $fetch['expire'] ), $fetch['reason'] );
- }
- $_SESSION[ $x . '_userName' ] = $fetch['username'];
- $_SESSION[ $x . '_passWord' ] = $fetch['password'];
- $_SESSION[ $x . '_cacheData' ] = $fetch;
- header('Location: /');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement