Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //session_start();
- include 'dbConnect.php';
- function loginaction(){
- include 'dbConnect.php';
- $time = time();
- if(isset($_REQUEST['login'])){
- //if(isset($_GET['Key'])){
- //$myusername = $_GET['operator_id'];
- $key = $_REQUEST['telegram_key'];
- $username=$_REQUEST['user'];
- $password=$_REQUEST['pass'];
- $query = $db->prepare("SELECT operators.operator_id, telegramlog.telegram_key FROM
- telegramlog LEFT JOIN operators ON telegramlog.operator_id = operators.operator_id WHERE telegramlog.telegram_key = ? ;");
- $query->execute(array($key));
- $result = $query->fetchAll();
- $squery = $db->prepare("SELECT * FROM operators WHERE email = ? and heslo = ?;");
- $sResult = $squery->execute(array($username,$password));
- // function generateRandomString($length) {
- // $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- // $charactersLength = strlen($characters);
- // $randomString = '';
- //for ($i = 0; $i < $length; $i++) {
- // $randomString .= $characters[rand(0, $charactersLength - 1)];
- // }
- //return $randomString;
- // }
- $json = json_decode($json);
- if($result){
- header('location: user.php');
- }
- elseif($sResult){
- while($row = $squery ->fetch(PDO::FETCH_ASSOC)){
- echo '<script type="text/javascript">alert("You are logged in as user '. $row['users'] . '")</script>';
- if($row['users']=="a"){
- header('location: admin.php');
- }
- elseif($row['users']=="b"){
- header('location: leader.php');
- }
- elseif($row['users']=="c"){
- header('location: user.php');
- }
- else {
- echo 'no result';
- }
- }
- }
- else{
- echo ' no result';
- }
- }
- else if($_SERVER['REQUEST_METHOD'] == 'POST'){
- if(isset($_GET['token'])) {
- if ($_GET['token'] == "yes") {
- $newtoken = generateRandomString();
- $time = (time()) + 61;
- $pquery= $db ->prepare ("UPDATE telegramlog SET telegram_key = ? and key_time = ? WHERE ;");
- $presult = $pquery ->execute (array($newtoken, $time));
- }
- }
- }
- }
- function generateRandomString($length) {
- $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $charactersLength = strlen($characters);
- $randomString = '';
- for ($i = 0; $i < $length; $i++) {
- $randomString .= $characters[rand(0, $charactersLength - 1)];
- }
- return $randomString;
- }
- loginaction();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement