Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. <?php
  2.  
  3. //session_start();
  4. include 'dbConnect.php';
  5. function loginaction(){
  6. include 'dbConnect.php';
  7. $time = time();
  8.  
  9. //$_SESSION['login']['user_type'] = $user[0]['operator_title'];
  10. // $_SESSION['login']['token'] = $company[0]['token'];
  11. // $_SESSION['login']['operator_token'] = $user[0]['auth_key'];
  12. // $_SESSION['login']['operator_name'] = $user[0]['operator_name'];
  13. // $_SESSION['login']['online_photo'] = $user[0]['online_avatar'];
  14. // if(isset($user[0]['users'])){
  15. // $_SESSION['login']['users'] = $user[0]['users'];
  16. // } else if(!isset($user[0]['users'])) {
  17. // $_SESSION['login']['users']='c';
  18. // }
  19. //
  20. // if($user[0]['users'] == 'a'){
  21. // $_SESSION['administrace']='admin';
  22. // } else if($user[0]['users'] == 'b') {
  23. // $_SESSION['administrace']='lead';
  24. // } else if($user[0]['users'] == 'c'){
  25. // $_SESSION['administrace']='adv';
  26. // } else if( is_null($user[0]['users'])){
  27. // $_SESSION['administrace']='adv';
  28. // }
  29.  
  30. //setcookie("tmp_operator_id", $_SESSION['login']['operator_id'], time()+3600, "/");
  31. //setcookie("tmp_company_id", $_SESSION['login']['company_id'], time()+3600, "/");
  32. //setcookie("tmp_user_type", $_SESSION['login']['user_type'], time()+3600, "/");
  33. //setcookie("tmp_oper_token", $_SESSION['login']['operator_token'], time()+3600, "/");
  34. //setcookie("tmp_token", $_SESSION['login']['token'], time()+3600, "/");
  35. //setcookie("tmp_users", $user[0]['users'], time()+3600, "/");
  36. //setcookie("tmp_name", $user[0]['operator_name'], time()+3600, "/");
  37. //setcookie("tmp_online_photo", $user[0]['online_avatar'], time()+3600, "/");
  38.  
  39.  
  40. if(isset($_REQUEST['login'])){
  41. //if(isset($_GET['Key'])){
  42. //$myusername = $_GET['operator_id'];
  43. $key = $_REQUEST['telegram_key'];
  44. $username=$_REQUEST['user'];
  45. $password=$_REQUEST['pass'];
  46.  
  47.  
  48. $query = $db->prepare("SELECT operators.operator_id, telegramlog.telegram_key FROM
  49. telegramlog LEFT JOIN operators ON telegramlog.operator_id = operators.operator_id WHERE telegramlog.telegram_key = ? and key_time > ? ;");
  50. $query->execute(array($key,$time));
  51. $result = $query->fetchAll();
  52.  
  53. $squery = $db->prepare("SELECT * FROM operators WHERE email = ? and heslo = ?;");
  54. $sResult = $squery->execute(array($username,$password));
  55.  
  56.  
  57. $json = json_decode($json);
  58. if($result){
  59. header('location: user.php');
  60. }
  61. elseif($sResult){
  62. while($row = $squery ->fetch(PDO::FETCH_ASSOC)){
  63. echo '<script type="text/javascript">alert("You are logged in as user '. $row['users'] . '")</script>';
  64.  
  65. if($row['users']=="a"){
  66. header('location: admin.php');
  67. }
  68. elseif($row['users']=="b"){
  69. header('location: leader.php');
  70. }
  71. elseif($row['users']=="c"){
  72. header('location: user.php');
  73. }
  74. else {
  75. echo 'no result';
  76. }
  77. }
  78. }
  79. else{
  80. echo ' no result';
  81. }
  82. }
  83. else if($_SERVER['REQUEST_METHOD'] == 'POST'){
  84. echo "$randomString";
  85. if(isset($_GET['token'])) {
  86.  
  87. if ($_GET['token'] == "yes") {
  88.  
  89.  
  90. $newtoken = generateRandomString();
  91. $time = (time()) + 61;
  92. $pquery= $db ->prepare ("UPDATE telegramlog SET telegram_key = ? and key_time = ? WHERE telegram_key = ? ;");
  93. $presult = $pquery ->execute (array($newtoken, $time,$key));
  94. }
  95. }
  96. }
  97. function generateRandomString($length) {
  98. $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  99. $charactersLength = strlen($characters);
  100. $randomString = '';
  101.  
  102. for ($i = 0; $i < $length; $i++) {
  103. $randomString .= $characters[rand(0, $charactersLength - 1)];
  104. }
  105. return $randomString;
  106. }
  107. function verifytime($variable){
  108.  
  109.  
  110.  
  111. }
  112. }
  113.  
  114.  
  115. loginaction();
  116. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement