Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 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. if(isset($_REQUEST['login'])){
  10. //if(isset($_GET['Key'])){
  11. //$myusername = $_GET['operator_id'];
  12. $key = $_REQUEST['telegram_key'];
  13. $username=$_REQUEST['user'];
  14. $password=$_REQUEST['pass'];
  15.  
  16.  
  17. $query = $db->prepare("SELECT operators.operator_id, telegramlog.telegram_key FROM
  18. telegramlog LEFT JOIN operators ON telegramlog.operator_id = operators.operator_id WHERE telegramlog.telegram_key = ? ;");
  19. $query->execute(array($key));
  20. $result = $query->fetchAll();
  21.  
  22. $squery = $db->prepare("SELECT * FROM operators WHERE email = ? and heslo = ?;");
  23. $sResult = $squery->execute(array($username,$password));
  24.  
  25.  
  26. // function generateRandomString($length) {
  27. // $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  28. // $charactersLength = strlen($characters);
  29. // $randomString = '';
  30.  
  31. //for ($i = 0; $i < $length; $i++) {
  32. // $randomString .= $characters[rand(0, $charactersLength - 1)];
  33. // }
  34. //return $randomString;
  35. // }
  36. $json = json_decode($json);
  37. if($result){
  38. header('location: user.php');
  39. }
  40. elseif($sResult){
  41. while($row = $squery ->fetch(PDO::FETCH_ASSOC)){
  42. echo '<script type="text/javascript">alert("You are logged in as user '. $row['users'] . '")</script>';
  43.  
  44. if($row['users']=="a"){
  45. header('location: admin.php');
  46. }
  47. elseif($row['users']=="b"){
  48. header('location: leader.php');
  49. }
  50. elseif($row['users']=="c"){
  51. header('location: user.php');
  52. }
  53. else {
  54. echo 'no result';
  55. }
  56. }
  57. }
  58. else{
  59. echo ' no result';
  60. }
  61. }
  62. else if($_SERVER['REQUEST_METHOD'] == 'POST'){
  63. if(isset($_GET['token'])) {
  64.  
  65. if ($_GET['token'] == "yes") {
  66.  
  67. $newtoken = generateRandomString();
  68. $time = (time()) + 61;
  69. $pquery= $db ->prepare ("UPDATE telegramlog SET telegram_key = ? and key_time = ? WHERE ;");
  70. $presult = $pquery ->execute (array($newtoken, $time));
  71. }
  72. }
  73. }
  74. }
  75. function generateRandomString($length) {
  76. $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  77. $charactersLength = strlen($characters);
  78. $randomString = '';
  79.  
  80. for ($i = 0; $i < $length; $i++) {
  81. $randomString .= $characters[rand(0, $charactersLength - 1)];
  82. }
  83. return $randomString;
  84. }
  85.  
  86. loginaction();
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement