Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class user
- {
- public $db;
- public $username;
- public $twitch_channel;
- public $oauth_token;
- public $oauth_token_secret;
- public $tipeee;
- public $admin;
- function __construct($conn)
- {
- $this->db = $conn;
- if($this->isLoggedIn()){
- $this->username = $_SESSION['username'];
- if($this->twitterConnected()){
- $this->oauth_token = $this->getInfo('twitter_account_oauth_token');
- $this->oauth_token_secret = $this->getInfo('twitter_account_oauth_token_secret');
- }
- $this->twitch_channel = $this->getInfo('twitch_account');
- $this->tipeee = $this->getInfo('tipeee_auth');
- $this->admin = $this->getInfo('admin');
- }
- }
- public function verify($username, $password){
- $username = strtolower($username);
- $stmt = $this->db->prepare("SELECT * FROM users WHERE username = :username");
- $stmt->bindParam(':username', $username);
- $stmt->execute();
- if($stmt->rowCount() > 0){
- $data = $stmt->fetch(PDO::FETCH_OBJ);
- if(password_verify($password, $data->password)){
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- return false;
- }
- public function updatePass($oldpass, $newpass, $newpassrepeat){
- if($this->verify($this->username, $oldpass)){
- if($newpass == $newpassrepeat){
- $options = [
- 'cost' => 12,
- ];
- $salt = sha1(md5('hottentottententententoonstelling'));
- $newpass = password_hash($newpass . $salt, PASSWORD_BCRYPT, $options);
- $stmt = $this->db->prepare("UPDATE users SET password = :password WHERE username = :username");
- $stmt->bindParam(':password', $newpass);
- $stmt->bindParam(':username', $this->username);
- $stmt->execute();
- echo('<div id="error" class="error error-green">Password Changed!</div>');
- } else {
- echo('<div id="error" class="error error-red">Password repeat wrong.</div>');
- }
- } else {
- echo('<div id="error" class="error error-red">Wrong old password.</div>');
- }
- }
- public function updatePassword($info, $value){
- $stmt = $this->db->prepare("UPDATE users SET :info = :value WHERE username = :username");
- $stmt->bindParam(':info', $info);
- $stmt->bindParam(':value', $value);
- $stmt->bindParam(':username', $this->username);
- $stmt->execute();
- }
- public function updateOrder($order){
- $stmt = $this->db->prepare("UPDATE usersettings SET column_order = :order WHERE username = :username");
- $stmt->bindParam(':order', $order);
- $stmt->bindParam(':username', $this->username);
- $stmt->execute();
- }
- public function twitterConnected(){
- if(empty($this->getInfo('twitter_account_oauth_token')) || empty($this->getInfo('twitter_account_oauth_token_secret'))){
- return false;
- }
- return true;
- }
- public function tipeeeConnected(){
- if(empty($this->getInfo('tipeee_auth'))){
- return false;
- }
- return true;
- }
- public function twitchConnected(){
- if(empty($this->getInfo('twitch_access_token')) || empty($this->getInfo('twitch_account'))){
- return false;
- }
- return true;
- }
- public function isLoggedIn(){
- if(isset($_SESSION['username'])){
- return true;
- } else {
- return false;
- }
- return false;
- }
- public function getSetting($setting){
- $stmt = $this->db->prepare("SELECT * FROM usersettings WHERE username=:username");
- $stmt->bindParam(':username', $this->username);
- $stmt->execute();
- if($stmt->rowCount() > 0){
- $data = $stmt->fetch(PDO::FETCH_OBJ);
- return $data->$setting;
- }
- return false;
- }
- public function getInfo($info){
- $stmt = $this->db->prepare("SELECT * FROM users WHERE username=:username");
- $stmt->bindParam(':username', $this->username);
- $stmt->execute();
- if($stmt->rowCount() > 0){
- $data = $stmt->fetch(PDO::FETCH_OBJ);
- return $data->$info;
- }
- return false;
- }
- public function isAdmin(){
- if($this->admin == 'yes'){
- return true;
- }
- return false;
- }
- public function isLive(){
- if(!is_null($this->getTwitchData('streams')['stream'])){
- return true;
- }
- return false;
- }
- public function getTwitchData($api){
- switch ($api){
- case 'streams':
- $api_link = 'streams';
- break;
- case 'channels':
- $api_link = 'channels';
- break;
- case 'games':
- $api_link = 'games';
- break;
- case 'follows':
- $api_link = 'follows';
- break;
- case 'users':
- $api_link = 'users';
- break;
- default:
- return 'Error';
- }
- if(!empty($api)){
- $url = 'https://api.twitch.tv/kraken/'.$api_link.'/';
- $channel = $this->twitch_channel;
- $clientId = 'eurdwdkcxshe3upj0lmef58iubno7o3';
- $ch = curl_init();
- curl_setopt_array($ch, array(
- CURLOPT_HTTPHEADER => array(
- 'Client-ID: ' . $clientId
- ),
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_URL => $url . $channel
- ));
- $response = curl_exec($ch);
- $json = json_decode($response, true);
- return $json;
- } else {
- return 'Error';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement