Файл: vfermu.ru/loginAPI.php
Строк: 110
<?php
/*
@ Author
@ Date 09.10.2015
@ VersionScript 1.0
@ package: vfermu.ru
*/
if(!isset($_SESSION))
{
session_name('SESS');
session_start();
}
Class DB {
protected static $getInstance;
public static function run() {
if( !isset( self::$getInstance ) ) {
try {
define('HOST', 'localhost');
define('NAME', '');
define('USER', '');
define('PASS', '');
self::$getInstance = new PDO('mysql:dbname=' . NAME . ';host=' . HOST, USER, PASS);
} catch( PDOException $error ) {
exit( $error->getMessage() );
}
}
return self::$getInstance;
}
final public function __destruct() {
self::$getInstance = null;
}
}
if (isset($_POST['token'])){
$s = file_get_contents('http://ulogin.ru/token.php?token=' . $_POST['token'] . '&host=' . $_SERVER['HTTP_HOST']); $_POST['loginAPI'] = true; }
if(isset($_POST['token'])) $users = json_decode($s, true);
if(isset($_POST['token']) && !isset($user) && $users['network'] && $users['identity'] && $_POST['loginAPI'] == true){
$stmt = DB::run()->prepare('SELECT `type_reg`, `identity` FROM `farm_user` WHERE `type_reg` = :type_reg AND `identity` = :identity LIMIT 1');
$stmt->execute(
array(
':type_reg' => $users['network'],
':identity' => $users['identity'] ));
$fetch_users = $stmt->fetch();
if($fetch_users == false){
if ($users['network'] == 'odnoklassniki')
$idi = 'ok';
else
$idi = null;
$identity = $users['identity'];
$identity = str_replace('http://www.facebook.com', '', $identity);
$identity = str_replace('http://openid.yandex.ru', '', $identity);
$identity = str_replace('http://vk.com', '', $identity);
$identity = str_replace('http://odnoklassniki.ru', '', $identity);
$identity = str_replace('http://my.mail.ru/mail', '', $identity);
$identity = str_replace('/', '', $identity);
$identity = str_replace('.', '', $identity);
$identity = $idi . $identity;
$password = sha1(mt_rand(1111111,99999999).time());
$stmt = DB::run()->prepare('SELECT `nick` FROM `farm_user` WHERE `nick` = :nick LIMIT 1');
$stmt->execute(
array(':nick' => $identity));
if($stmt->fetch() == true)
$identity = $identity . '_' . rand(0000, 9999);
$stmt = DB::run()->prepare('INSERT INTO `farm_user` (`nick`, `password`, `money`, `rubies`, `identity`, `type_reg`) VALUES (:nick, :password, :money, :rubies, :identity, :type_reg) ');
$stmt->execute(
array(
':nick' => $identity,
':password' => $password,
':money' => '10000',
':rubies' => '10000',
':identity' => $users['identity'],
':type_reg' => $users['network']));
$_SESSION['id_user'] = DB::run()->lastInsertId();
header('Location: /');
exit;
} else {
$stmt = DB::run()->prepare('SELECT * FROM `farm_user` WHERE `type_reg` = :type_reg AND `identity` = :identity LIMIT 1');
$stmt->execute(
array(
':type_reg' => $users['network'],
':identity' => $users['identity']));
$user = $stmt->fetch();
$_SESSION['id_user'] = $user['id'];
header('Location: /');
exit;
}
}
?>