Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | None | 0 0
  1. class user
  2. {
  3. public $db;
  4.  
  5. public $username;
  6. public $twitch_channel;
  7. public $oauth_token;
  8. public $oauth_token_secret;
  9. public $tipeee;
  10. public $admin;
  11.  
  12.  
  13. function __construct($conn)
  14. {
  15. $this->db = $conn;
  16. if($this->isLoggedIn()){
  17. $this->username = $_SESSION['username'];
  18. if($this->twitterConnected()){
  19. $this->oauth_token = $this->getInfo('twitter_account_oauth_token');
  20. $this->oauth_token_secret = $this->getInfo('twitter_account_oauth_token_secret');
  21. }
  22. $this->twitch_channel = $this->getInfo('twitch_account');
  23. $this->tipeee = $this->getInfo('tipeee_auth');
  24. $this->admin = $this->getInfo('admin');
  25. }
  26. }
  27.  
  28. public function verify($username, $password){
  29. $username = strtolower($username);
  30. $stmt = $this->db->prepare("SELECT * FROM users WHERE username = :username");
  31. $stmt->bindParam(':username', $username);
  32. $stmt->execute();
  33. if($stmt->rowCount() > 0){
  34. $data = $stmt->fetch(PDO::FETCH_OBJ);
  35. if(password_verify($password, $data->password)){
  36. return true;
  37. } else {
  38. return false;
  39. }
  40. } else {
  41. return false;
  42. }
  43. return false;
  44. }
  45.  
  46.  
  47. public function updatePass($oldpass, $newpass, $newpassrepeat){
  48. if($this->verify($this->username, $oldpass)){
  49. if($newpass == $newpassrepeat){
  50. $options = [
  51. 'cost' => 12,
  52. ];
  53. $salt = sha1(md5('hottentottententententoonstelling'));
  54. $newpass = password_hash($newpass . $salt, PASSWORD_BCRYPT, $options);
  55. $stmt = $this->db->prepare("UPDATE users SET password = :password WHERE username = :username");
  56. $stmt->bindParam(':password', $newpass);
  57. $stmt->bindParam(':username', $this->username);
  58. $stmt->execute();
  59. echo('<div id="error" class="error error-green">Password Changed!</div>');
  60. } else {
  61. echo('<div id="error" class="error error-red">Password repeat wrong.</div>');
  62. }
  63. } else {
  64. echo('<div id="error" class="error error-red">Wrong old password.</div>');
  65. }
  66. }
  67.  
  68. public function updatePassword($info, $value){
  69. $stmt = $this->db->prepare("UPDATE users SET :info = :value WHERE username = :username");
  70. $stmt->bindParam(':info', $info);
  71. $stmt->bindParam(':value', $value);
  72. $stmt->bindParam(':username', $this->username);
  73. $stmt->execute();
  74. }
  75.  
  76. public function updateOrder($order){
  77. $stmt = $this->db->prepare("UPDATE usersettings SET column_order = :order WHERE username = :username");
  78. $stmt->bindParam(':order', $order);
  79. $stmt->bindParam(':username', $this->username);
  80. $stmt->execute();
  81. }
  82.  
  83. public function twitterConnected(){
  84. if(empty($this->getInfo('twitter_account_oauth_token')) || empty($this->getInfo('twitter_account_oauth_token_secret'))){
  85. return false;
  86. }
  87. return true;
  88. }
  89. public function tipeeeConnected(){
  90. if(empty($this->getInfo('tipeee_auth'))){
  91. return false;
  92. }
  93. return true;
  94. }
  95.  
  96. public function twitchConnected(){
  97. if(empty($this->getInfo('twitch_access_token')) || empty($this->getInfo('twitch_account'))){
  98. return false;
  99. }
  100. return true;
  101. }
  102. public function isLoggedIn(){
  103. if(isset($_SESSION['username'])){
  104. return true;
  105. } else {
  106. return false;
  107. }
  108. return false;
  109. }
  110.  
  111.  
  112. public function getSetting($setting){
  113. $stmt = $this->db->prepare("SELECT * FROM usersettings WHERE username=:username");
  114. $stmt->bindParam(':username', $this->username);
  115. $stmt->execute();
  116. if($stmt->rowCount() > 0){
  117. $data = $stmt->fetch(PDO::FETCH_OBJ);
  118. return $data->$setting;
  119. }
  120. return false;
  121. }
  122.  
  123. public function getInfo($info){
  124. $stmt = $this->db->prepare("SELECT * FROM users WHERE username=:username");
  125. $stmt->bindParam(':username', $this->username);
  126. $stmt->execute();
  127. if($stmt->rowCount() > 0){
  128. $data = $stmt->fetch(PDO::FETCH_OBJ);
  129. return $data->$info;
  130. }
  131. return false;
  132. }
  133.  
  134. public function isAdmin(){
  135. if($this->admin == 'yes'){
  136. return true;
  137. }
  138. return false;
  139. }
  140.  
  141. public function isLive(){
  142. if(!is_null($this->getTwitchData('streams')['stream'])){
  143. return true;
  144. }
  145. return false;
  146. }
  147.  
  148. public function getTwitchData($api){
  149. switch ($api){
  150. case 'streams':
  151. $api_link = 'streams';
  152. break;
  153. case 'channels':
  154. $api_link = 'channels';
  155. break;
  156. case 'games':
  157. $api_link = 'games';
  158. break;
  159. case 'follows':
  160. $api_link = 'follows';
  161. break;
  162. case 'users':
  163. $api_link = 'users';
  164. break;
  165. default:
  166. return 'Error';
  167. }
  168. if(!empty($api)){
  169. $url = 'https://api.twitch.tv/kraken/'.$api_link.'/';
  170. $channel = $this->twitch_channel;
  171. $clientId = 'eurdwdkcxshe3upj0lmef58iubno7o3';
  172. $ch = curl_init();
  173. curl_setopt_array($ch, array(
  174. CURLOPT_HTTPHEADER => array(
  175. 'Client-ID: ' . $clientId
  176. ),
  177. CURLOPT_RETURNTRANSFER => true,
  178. CURLOPT_URL => $url . $channel
  179. ));
  180. $response = curl_exec($ch);
  181. $json = json_decode($response, true);
  182. return $json;
  183. } else {
  184. return 'Error';
  185. }
  186.  
  187. }
  188.  
  189.  
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement