Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. error_reporting(E_ALL | E_STRICT);
  6. ini_set('display_errors', '1');
  7. ini_set("log_errors", 1);
  8. ini_set("error_log", 'php_error.log');
  9. error_log ('Hlášení o chybě', 0);
  10.  
  11. include 'dbConnect.php';
  12. $email = '';
  13. $_SESSION['email'] = $email;
  14. $json = '{"false":"telegramlogin.php","a":"user.php","b":"user.php","c":"admin.php"}';// data pro výběr přesměrování
  15.  
  16. // vstup do rozhrani-----------------------z ----------------------------------------
  17. if(isset($_REQUEST['telegram_key']) && $_REQUEST['telegram_key']){
  18. $redirects = telegram($_REQUEST['telegram_key'], $json, $db);
  19. header('Location: '.$redirects);
  20. exit;
  21. }
  22.  
  23. elseif((isset($_REQUEST['user']) && isset($_REQUEST['pass'])) && ($_REQUEST['user'] && $_REQUEST['pass'])){
  24. echo 'Login with User name and Password';
  25. }
  26. elseif(isset($_REQUEST['new_key'])){
  27.  
  28. $new_key = $_REQUEST['new_key'];
  29. new_pass($db,$new_key);
  30.  
  31.  
  32.  
  33. }
  34.  
  35. else{
  36. echo 'Authentication failure';
  37. }
  38.  
  39.  
  40. //konec vstupu ---------------------------------------------------------------------
  41. function new_pass($db,$new_key){
  42. $time = time();
  43. echo $new_key;
  44. $tmp = $db->prepare("SELECT * FROM change_pass WHERE token = ? AND time > ?;");
  45. $tmp->execute(array($new_key, $time));
  46. $data = $tmp->fetchAll();
  47. $token = $data[0]['token'];
  48. var_dump($token);
  49. exit;
  50.  
  51. if(isset($token)){
  52. $_SESSION['email'] = $data[0]['email'];
  53. header('location: newpass.php');
  54. echo "hmm";
  55. }
  56. else {
  57. echo time();
  58. echo "nope";
  59.  
  60. }
  61.  
  62.  
  63.  
  64. }
  65. function telegram($telegram_key, $json, $db){
  66. $redirects = json_decode($json, true);
  67. $tmp = $db->prepare("SELECT * FROM telegram_log WHERE telegram_key=:tg_key AND time < :tm");
  68.  
  69. $tmp->execute(array('tg_key'=>$telegram_key, 'tm'=>time()));
  70. $data = $tmp->fetch();
  71. if($data){
  72. $tmp = $db->prepare("SELECT * FROM operators WHERE operator_id=:op_id");
  73. $tmp->execute(array('op_id'=>$data[0]));
  74. $operator = $tmp->fetch();
  75. if($operator){
  76. if(!set_my_sessions($operator, $db)){ // neco je spatne z funkce set_my_sessions
  77. return $redirects['false'];
  78. }
  79. return $redirects[$operator['users']]."?err=3";// vyber presmerovani
  80.  
  81. }
  82. }
  83. return $redirects['false'];// neco je spatne
  84. exit;
  85. }
  86. function set_my_sessions(array $operator, $db){
  87. $tmp = $db->prepare("SELECT * FROM companies WHERE company_id = :comp_id");
  88. $tmp->execute(array('comp_id'=>$operator['company_id']));
  89. $company = $tmp->fetchAll();
  90. if($company){
  91. $_SESSION['login']['operator_id'] = $operator['operator_id'];
  92. $_SESSION['login']['company_id'] = $operator['company_id'];
  93. $_SESSION['login']['user_type'] = $operator['operator_title'];
  94. $_SESSION['login']['token'] = $company[0]['token'];
  95. $_SESSION['login']['operator_token'] = $operator['auth_key'];
  96. $_SESSION['login']['operator_name'] = $operator['operator_name'];
  97. $_SESSION['login']['online_photo'] = $operator['online_avatar'];
  98. if(isset($operator['users'])){
  99. $_SESSION['login']['users'] = $operator['users'];
  100. } else if(!isset($operator['users'])) {
  101. $_SESSION['login']['users']='c';
  102. }
  103.  
  104. if($operator['users'] == 'a'){
  105. $_SESSION['administrace']='admin';
  106. } else if($operator['users'] == 'b') {
  107. $_SESSION['administrace']='lead';
  108. } else if($operator['users'] == 'c'){
  109. $_SESSION['administrace']='adv';
  110. } else if( is_null($operator['users'])){
  111. $_SESSION['administrace']='adv';
  112. }
  113.  
  114. setcookie("tmp_operator_id", $_SESSION['login']['operator_id'], time()+3600, "/");
  115. setcookie("tmp_company_id", $_SESSION['login']['company_id'], time()+3600, "/");
  116. setcookie("tmp_user_type", $_SESSION['login']['user_type'], time()+3600, "/");
  117. setcookie("tmp_oper_token", $_SESSION['login']['operator_token'], time()+3600, "/");
  118. setcookie("tmp_token", $_SESSION['login']['token'], time()+3600, "/");
  119. setcookie("tmp_users", $operator['users'], time()+3600, "/");
  120. setcookie("tmp_name", $operator['operator_name'], time()+3600, "/");
  121. setcookie("tmp_online_photo", $operator['online_avatar'], time()+3600, "/");
  122.  
  123. setcookie("operator_id", $_SESSION['login']['operator_id'], time() + (86400*30), "/");
  124. setcookie("company_id", $_SESSION['login']['company_id'], time() + (86400*30), "/");
  125. setcookie("user_type", $operator['operator_title'], time() + (86400*30), "/");
  126. setcookie("oper_token", $operator['auth_key'], time() + (86400*30), "/");
  127. setcookie("token", $company[0]['token'], time() + (86400*30), "/");
  128. setcookie("name", $operator['operator_name'], time() + (86400*30), "/");
  129. setcookie("users", $operator['users'], time() + (86400*30), "/");
  130. setcookie("online_photo", $operator['online_avatar'], time() + (86400*30), "/");
  131. return true;
  132. }
  133. else
  134. return false;
  135. }
  136.  
  137.  
  138. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement