Advertisement
enos

tes

Nov 16th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.39 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Auth extends CI_Controller {
  5.    
  6.     function __construct(){
  7.         parent::__construct();     
  8.         $this->load->model('m_login'); // Berfungsi untuk memanggil Login_model
  9.  
  10.     }
  11.    
  12.     // Berfungsi untuk menampilkan halaman login
  13.     public function index()
  14.     {
  15.        
  16.         //$this->load->view('admin/login_view', $data);
  17.     }
  18.     // Berfungsi untuk melakukan validasi login
  19.     function aksi_login(){
  20.        
  21.          require_once(APPPATH.'views/utama/steamauth/openid.php');
  22.          
  23.          try
  24.         {
  25.             $openid = new LightOpenID('http://'.$_SERVER['SERVER_NAME'].'/');
  26.             if (!$openid->mode) {
  27.                 $openid->identity = 'http://steamcommunity.com/openid/?l=id';
  28.                 header('Location: ' .$openid->authUrl());
  29.             } elseif ($openid->mode == 'cancel') {
  30.                 echo '';
  31.             } else {
  32.                 if ($openid->validate()) {
  33.  
  34.                     $id = $openid->identity;
  35.                     $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
  36.                     preg_match($ptn, $id, $matches);
  37.  
  38.                     $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=8767724B906265376260A60A99E08CB6&steamids=$matches[1]";
  39.                     $json_object = file_get_contents($url);
  40.                     $json_decoded = json_decode($json_object);
  41.                     foreach ($json_decoded->response->players as $player) {
  42.                         $steamid = $player->steamid;
  43.                         $name = $player->personaname;
  44.                         $avatar = $player->avatar;
  45.                     }
  46.  
  47.                     $hash = md5($steamid . time() . rand(1, 50));
  48.                     $sql = $db->query("SELECT * FROM `users` WHERE `steamid` = '" . $steamid . "'");
  49.                     $row = $sql->fetchAll(PDO::FETCH_ASSOC);
  50.                     if (count($row) == 0) {
  51.                         $db->exec("INSERT INTO `users` (`hash`, `steamid`, `name`, `avatar`) VALUES ('" . $hash . "', '" . $steamid . "', " . $db->quote($name) . ", '" . $avatar . "')");
  52.                     } else {
  53.                         $db->exec("UPDATE `users` SET `hash` = '" . $hash . "', `name` = " . $db->quote($name) . ", `avatar` = '" . $avatar . "' WHERE `steamid` = '" . $steamid . "'");
  54.                     }
  55.                     setcookie('hash', $hash, time() + 3600 * 24 * 7, '/');
  56.                     //header('Location: http://localhost/steam/Script/Script/sets.php?id=' . $hash);
  57.                     echo "<meta http-equiv='refresh' content='0; url='.base_url().'member/daftar'>";
  58.                 }
  59.             }
  60.         } catch (ErrorException $e) {
  61.             exit($e->getMessage());
  62.         }
  63.     }
  64.  
  65.        
  66.        
  67.        
  68.        
  69.        
  70.    
  71.     function logout(){
  72.         $this->session->sess_destroy();
  73.         redirect(base_url('utama/index'));
  74.     }
  75.    
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement