Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 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.  
  10.  
  11. if(isset($_REQUEST['login'])){
  12. $key = $_GET['telegram_key'];
  13. $username=$_REQUEST['user'];
  14. $password=$_REQUEST['pass'];
  15.  
  16. $query = $db->prepare("SELECT operators.operator_id, telegramlog.telegram_key FROM
  17. telegramlog LEFT JOIN operators ON telegramlog.operator_id = operators.operator_id WHERE telegramlog.telegram_key = ?, key_time = ? ;");
  18. $query->execute(array($key,$time));
  19. $result = $query->fetchAll();
  20.  
  21. $squery = $db->prepare("SELECT * FROM operators WHERE email = ? and heslo = ?;");
  22. $sResult = $squery->execute(array($username,$password));
  23.  
  24. if(isset($_REQUEST['error'])){
  25. $error= $_REQUEST['error'];
  26. echo errorDefine($err);
  27.  
  28.  
  29. if($time > $row['key_time']){
  30. if($result){
  31. header('location: user.php');
  32. }
  33. }
  34. elseif($sResult){
  35. while($row = $squery ->fetch(PDO::FETCH_ASSOC)){
  36. echo '<script type="text/javascript">alert("You are logged in as user '. $row['users'] . '")</script>';
  37.  
  38. if($row['users']=="a"){
  39. header('location: admin.php');
  40. }
  41. elseif($row['users']=="b"){
  42. header('location: leader.php');
  43. }
  44. elseif($row['users']=="c"){
  45. header('location: user.php');
  46. }
  47. else{
  48. header("location: function.php?error=2");
  49. }
  50. }
  51. }
  52. else if ($time < $row['key_time']) {
  53. header("location: function.php?error=1");
  54. }
  55. if('empty'){
  56. header("location: function.php?error=3");
  57. }
  58. }
  59.  
  60.  
  61. }
  62. }
  63. else if($_SERVER['REQUEST_METHOD'] == 'POST'){
  64.  
  65. if(isset($_GET['token'])) {
  66.  
  67. if ($_GET['token'] == "yes") {
  68.  
  69.  
  70. $newtoken = generateRandomString();
  71. $time = time() + (0 * 0 * 0 * 60);
  72. $pquery= $db ->prepare ("UPDATE telegramlog SET telegram_key = ? and key_time = ? WHERE telegram_key = ? ;");
  73. $presult = $pquery ->execute (array($newtoken, $time,$key));
  74. }
  75.  
  76. }
  77. }
  78.  
  79. //external
  80. //$error = errorDefine(2);
  81. // echo $error;
  82. //funkce se string bude volaná na jiné stránce
  83. //if isset get error
  84.  
  85.  
  86. }
  87. function generateRandomString($length) {
  88. $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  89. $charactersLength = strlen($characters);
  90. $randomString = '';
  91.  
  92. for ($i = 0; $i < $length; $i++) {
  93. $randomString .= $characters[rand(0, $charactersLength - 1)];
  94. }
  95. return $randomString;
  96. }
  97. function errorDefine($err){
  98. if ($err=="1"){
  99. $deferr="Čas vypršel";
  100. }
  101. else if ($err=="2"){
  102. $deferr="Špatné příhlášení";
  103. }
  104. else if ($err=="3"){
  105. $deferr="Vyplňte všechna pole";
  106. }
  107. return $deferr;
  108. }
  109.  
  110. }
  111.  
  112. loginaction();
  113. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement