fork download
  1. <?php
  2.  
  3.  
  4. include_once( 'integration.php' );
  5.  
  6. class Login extends Jigowatt_integration {
  7.  
  8. private $user;
  9. private $pass;
  10. private $token;
  11. private $valid;
  12. private $result;
  13.  
  14. public $use_emails = false;
  15. public $error;
  16. public $msg;
  17.  
  18. public $data = array();
  19.  
  20. function __construct() {
  21.  
  22. // Disable users from logging in?
  23. if (parent::getOption('disable-logins-enable')) {
  24. self::displayMessageEntry('The admin has disabled logins.');
  25. }
  26.  
  27. $this->use_emails = parent::getOption('email-as-username-enable');
  28. $this->username_type = ( $this->use_emails ) ? 'email' : 'username';
  29.  
  30. // Redirect the logging in user
  31. if ( parent::getOption('signin-redirect-referrer-enable') )
  32. $_SESSION['jigowatt']['referer'] = (!empty($_SESSION['jigowatt']['referer'])) ? $_SESSION['jigowatt']['referer'] : 'home.php';
  33. else
  34. $_SESSION['jigowatt']['referer'] = parent::getOption('signin-redirect-url');
  35.  
  36. // Are they attempting to access a secure page?
  37. $this->isSecure();
  38.  
  39. // Only allow guests to view this page
  40. parent::guestOnly();
  41.  
  42. // Generate a unique token for security purposes
  43. parent::generateToken();
  44.  
  45. // Login form post data
  46. if(isset($_POST['username'])) :
  47. $this->user = parent::secure($_POST['username']);
  48. $this->pass = parent::secure($_POST['password']);
  49.  
  50. $this->token = !empty($_POST['token']) ? $_POST['token'] : '';
  51. $this->process();
  52. endif;
  53.  
  54. if( !empty($_GET['login']) || !empty($_GET['link']) )
  55. !empty($_GET['link']) ? parent::link_account($_GET['link'], true) : parent::link_account($_GET['login'], true);
  56.  
  57. foreach (parent::$socialLogin as $provider) :
  58. if (!empty($_SESSION['jigowatt'][$provider])) {
  59. $this->social_login($provider);
  60. break;
  61. }
  62. endforeach;
  63.  
  64. // Display the errors and do not exit the page
  65. //return $data['msg'] = $this->error ? $this->error : $this->msg;
  66.  
  67. }
  68.  
  69. private function social_login($provider) {
  70.  
  71. $params = array( ':session' => $_SESSION['jigowatt'][$provider] );
  72. $stmt = parent::query("SELECT `user_id` FROM `login_integration` WHERE `$provider` = :session;", $params);
  73.  
  74. if ($stmt->rowCount() > 0) {
  75.  
  76. $result = $stmt->fetch();
  77.  
  78. $params = array( ':user_id' => $result['user_id'] );
  79. $stmt = parent::query("SELECT * FROM `login_users` WHERE `user_id` = :user_id;", $params);
  80.  
  81. $this->result = $stmt->fetch();
  82.  
  83. $username = $this->username_type;
  84. $this->user = $this->result[$username];
  85.  
  86. $this->login();
  87.  
  88. } else {
  89.  
  90. $_SESSION['jigowatt']['ot'],
  91. $_SESSION['jigowatt']['ots'],
  92. $_SESSION['jigowatt'][$provider]
  93. );
  94.  
  95. header('Location: sign_up.php?new_social');
  96. exit();
  97.  
  98. }
  99.  
  100. }
  101.  
  102. private function isSecure() {
  103.  
  104. if(isset($_GET['e'])) :
  105. if (parent::getOption('block-msg-out-enable'))
  106. return $data['msg'] = parent::getOption('block-msg-out');
  107. endif;
  108. }
  109.  
  110. private function process() {
  111.  
  112. // Check that the token is valid, prevents exploits
  113. if(!parent::valid_token($this->token)) {
  114. return $data['msg'] = 'Invalid login attempt.';
  115. }
  116.  
  117. // Confirm all details are correct
  118. $this->validate();
  119.  
  120. // Log the user in
  121. $this->login();
  122. }
  123.  
  124. private function validate() {
  125.  
  126. //if(!empty($this->error)) return false;
  127.  
  128. if(empty($this->user)) {
  129. $data['msg'] = (( $this->use_emails ) ? 'You must enter an email address.' : 'You must enter a username.');
  130. }
  131.  
  132. if(empty($this->pass)) {
  133. $data['msg'] = 'You forgot your password ;)';
  134. }
  135.  
  136. if (isset($data)) { return $data['msg']; }
  137.  
  138. $username = $this->username_type;
  139. $params = array( 'username' => $this->user );
  140. $stmt = parent::query("SELECT * FROM login_users WHERE {$username} = :username", $params);
  141.  
  142. $this->result = $stmt->fetch();
  143.  
  144. if(!parent::validatePassword($this->pass, $this->result['password'])) {
  145.  
  146. $username = $this->username_type;
  147. return $data['msg'] = "Incorrect $username or password.";
  148.  
  149. }
  150.  
  151. }
  152.  
  153. // Once everything's filled out
  154. public function login() {
  155.  
  156. global $image_handler;
  157.  
  158. // Just double check there are no errors first
  159. //if( !empty($data['msg']) ) return false;
  160.  
  161. return false;
  162.  
  163. // Session expiration
  164. $minutes = parent::getOption('default_session');
  165. ini_set('session.cookie_lifetime', 60 * $minutes);
  166.  
  167.  
  168. // See if the admin requires new users to activate
  169. if ( parent::getOption('user-activation-enable') ) :
  170.  
  171. // Check if user still requires activation
  172. $params = array( ':user' => $this->user );
  173. $username = $this->username_type;
  174. $stmt = parent::query("SELECT * FROM `login_confirm` WHERE `{$username}` = :user AND `type` = 'new_user'", $params);
  175.  
  176. if ($stmt->rowCount() > 0) $_SESSION['jigowatt']['activate'] = 1;
  177.  
  178. endif;
  179.  
  180. // Save if user is restricted
  181. if ( !empty($this->result['restricted']) ) $_SESSION['jigowatt']['restricted'] = 1;
  182.  
  183. // Are we forcing a password update if encryption is not the desired method?
  184. if (parent::getOption('pw-encrypt-force-enable')) :
  185.  
  186. $type = $this->getOption('pw-encryption');
  187.  
  188. if (strlen($this->result['password']) == 32 && $type == 'SHA256')
  189. $_SESSION['jigowatt']['forcePwUpdate'] = 1;
  190.  
  191. if (strlen($this->result['password']) != 32 && $type == 'MD5')
  192. $_SESSION['jigowatt']['forcePwUpdate'] = 1;
  193.  
  194. endif;
  195.  
  196. // Save user's current level
  197. $user_level = unserialize($this->result['user_level']);
  198. $_SESSION['jigowatt']['user_level'] = $user_level;
  199.  
  200. $_SESSION['jigowatt']['email'] = $this->result['email'];
  201.  
  202. //$_SESSION['jigowatt']['profile_img'] = $this->image->getProfilePicture($this->result['user_id'], true, 'small');
  203.  
  204. /** Check whether the user's level is disabled. */
  205. $params = array( ':level' => $user_level[0] );
  206. $stmt = parent::query("SELECT `level_disabled`, `redirect` FROM `login_levels` WHERE `id` = :level;", $params);
  207.  
  208. $disRow = $stmt->fetch();
  209.  
  210. if ( !empty($disRow['level_disabled']) ) $_SESSION['jigowatt']['level_disabled'] = 1;
  211. if ( !empty($disRow['redirect']) ) $redirect = $disRow['redirect'];
  212.  
  213. // Stay signed via checkbox?
  214. if(isset($_POST['remember'])) {
  215. ini_set('session.cookie_lifetime', 60*60*24*100); // Set to expire in 3 months & 10 days
  216. }
  217.  
  218. /** Store a timestamp. */
  219. if( parent::getOption('profile-timestamps-enable') ) {
  220.  
  221. $params = array(
  222. ':user_id' => $this->result['user_id'],
  223. ':ip' => $this->getIPAddress() == '::1' ? 'Localhost' : $this->getIPAddress()
  224. );
  225. $stmt = parent::query("INSERT INTO `login_timestamps` (`user_id` ,`ip` ,`timestamp`) VALUES (:user_id, :ip, CURRENT_TIMESTAMP);", $params);
  226.  
  227. }
  228.  
  229. // And our magic happens here! Let's sign them in
  230. $username = $this->username_type;
  231. $_SESSION['jigowatt']['username'] = $this->result[$username];
  232.  
  233. // User ID of the logging in user
  234. $_SESSION['jigowatt']['user_id'] = $this->result['user_id'];
  235.  
  236. if ( empty($redirect) ) $redirect = $_SESSION['jigowatt']['referer'];
  237.  
  238. $_SESSION['jigowatt']['referer'],
  239. $_SESSION['jigowatt']['token'],
  240. $_SESSION['jigowatt']['facebookMisc'],
  241. $_SESSION['jigowatt']['twitterMisc'],
  242. $_SESSION['jigowatt']['openIDMisc']
  243. );
  244.  
  245. // Redirect after it's all said and done
  246. header("Location: " . $redirect);
  247. exit();
  248.  
  249. }
  250.  
  251. }
  252. ?>
Runtime error #stdin #stdout #stderr 0.01s 20568KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Warning:  include_once(integration.php): failed to open stream: No such file or directory in /home/aVo2v3/prog.php on line 4
PHP Warning:  include_once(): Failed opening 'integration.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/aVo2v3/prog.php on line 4
PHP Fatal error:  Class 'Jigowatt_integration' not found in /home/aVo2v3/prog.php on line 6