Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Auth extends CI_Controller {
- function __construct(){
- parent::__construct();
- $this->load->model('m_login'); // Berfungsi untuk memanggil Login_model
- }
- // Berfungsi untuk menampilkan halaman login
- public function index()
- {
- //$this->load->view('admin/login_view', $data);
- }
- // Berfungsi untuk melakukan validasi login
- function aksi_login(){
- require_once(APPPATH.'views/utama/steamauth/openid.php');
- try
- {
- $openid = new LightOpenID('http://'.$_SERVER['SERVER_NAME'].'/');
- if (!$openid->mode) {
- $openid->identity = 'http://steamcommunity.com/openid/?l=id';
- header('Location: ' .$openid->authUrl());
- } elseif ($openid->mode == 'cancel') {
- echo '';
- } else {
- if ($openid->validate()) {
- $id = $openid->identity;
- $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
- preg_match($ptn, $id, $matches);
- $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=8767724B906265376260A60A99E08CB6&steamids=$matches[1]";
- $json_object = file_get_contents($url);
- $json_decoded = json_decode($json_object);
- foreach ($json_decoded->response->players as $player) {
- $steamid = $player->steamid;
- $name = $player->personaname;
- $avatar = $player->avatar;
- }
- $hash = md5($steamid . time() . rand(1, 50));
- $sql = $db->query("SELECT * FROM `users` WHERE `steamid` = '" . $steamid . "'");
- $row = $sql->fetchAll(PDO::FETCH_ASSOC);
- if (count($row) == 0) {
- $db->exec("INSERT INTO `users` (`hash`, `steamid`, `name`, `avatar`) VALUES ('" . $hash . "', '" . $steamid . "', " . $db->quote($name) . ", '" . $avatar . "')");
- } else {
- $db->exec("UPDATE `users` SET `hash` = '" . $hash . "', `name` = " . $db->quote($name) . ", `avatar` = '" . $avatar . "' WHERE `steamid` = '" . $steamid . "'");
- }
- setcookie('hash', $hash, time() + 3600 * 24 * 7, '/');
- //header('Location: http://localhost/steam/Script/Script/sets.php?id=' . $hash);
- echo "<meta http-equiv='refresh' content='0; url='.base_url().'member/daftar'>";
- }
- }
- } catch (ErrorException $e) {
- exit($e->getMessage());
- }
- }
- function logout(){
- $this->session->sess_destroy();
- redirect(base_url('utama/index'));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement