Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- error_reporting(E_ALL | E_STRICT);
- ini_set('display_errors', '1');
- ini_set("log_errors", 1);
- ini_set("error_log", 'php_error.log');
- error_log ('Hlášení o chybě', 0);
- include 'dbConnect.php';
- $email = '';
- $_SESSION['email'] = $email;
- $json = '{"false":"telegramlogin.php","a":"user.php","b":"user.php","c":"admin.php"}';// data pro výběr přesměrování
- // vstup do rozhrani-----------------------z ----------------------------------------
- if(isset($_REQUEST['telegram_key']) && $_REQUEST['telegram_key']){
- $redirects = telegram($_REQUEST['telegram_key'], $json, $db);
- header('Location: '.$redirects);
- exit;
- }
- elseif((isset($_REQUEST['user']) && isset($_REQUEST['pass'])) && ($_REQUEST['user'] && $_REQUEST['pass'])){
- echo 'Login with User name and Password';
- }
- elseif(isset($_REQUEST['new_key'])){
- $new_key = $_REQUEST['new_key'];
- new_pass($db,$new_key);
- }
- else{
- echo 'Authentication failure';
- }
- //konec vstupu ---------------------------------------------------------------------
- function new_pass($db,$new_key){
- $time = time();
- echo $new_key;
- $tmp = $db->prepare("SELECT * FROM change_pass WHERE token = ? AND time > ?;");
- $tmp->execute(array($new_key, $time));
- $data = $tmp->fetchAll();
- $token = $data[0]['token'];
- var_dump($token);
- exit;
- if(isset($token)){
- $_SESSION['email'] = $data[0]['email'];
- header('location: newpass.php');
- echo "hmm";
- }
- else {
- echo time();
- echo "nope";
- }
- }
- function telegram($telegram_key, $json, $db){
- $redirects = json_decode($json, true);
- $tmp = $db->prepare("SELECT * FROM telegram_log WHERE telegram_key=:tg_key AND time < :tm");
- $tmp->execute(array('tg_key'=>$telegram_key, 'tm'=>time()));
- $data = $tmp->fetch();
- if($data){
- $tmp = $db->prepare("SELECT * FROM operators WHERE operator_id=:op_id");
- $tmp->execute(array('op_id'=>$data[0]));
- $operator = $tmp->fetch();
- if($operator){
- if(!set_my_sessions($operator, $db)){ // neco je spatne z funkce set_my_sessions
- return $redirects['false'];
- }
- return $redirects[$operator['users']]."?err=3";// vyber presmerovani
- }
- }
- return $redirects['false'];// neco je spatne
- exit;
- }
- function set_my_sessions(array $operator, $db){
- $tmp = $db->prepare("SELECT * FROM companies WHERE company_id = :comp_id");
- $tmp->execute(array('comp_id'=>$operator['company_id']));
- $company = $tmp->fetchAll();
- if($company){
- $_SESSION['login']['operator_id'] = $operator['operator_id'];
- $_SESSION['login']['company_id'] = $operator['company_id'];
- $_SESSION['login']['user_type'] = $operator['operator_title'];
- $_SESSION['login']['token'] = $company[0]['token'];
- $_SESSION['login']['operator_token'] = $operator['auth_key'];
- $_SESSION['login']['operator_name'] = $operator['operator_name'];
- $_SESSION['login']['online_photo'] = $operator['online_avatar'];
- if(isset($operator['users'])){
- $_SESSION['login']['users'] = $operator['users'];
- } else if(!isset($operator['users'])) {
- $_SESSION['login']['users']='c';
- }
- if($operator['users'] == 'a'){
- $_SESSION['administrace']='admin';
- } else if($operator['users'] == 'b') {
- $_SESSION['administrace']='lead';
- } else if($operator['users'] == 'c'){
- $_SESSION['administrace']='adv';
- } else if( is_null($operator['users'])){
- $_SESSION['administrace']='adv';
- }
- setcookie("tmp_operator_id", $_SESSION['login']['operator_id'], time()+3600, "/");
- setcookie("tmp_company_id", $_SESSION['login']['company_id'], time()+3600, "/");
- setcookie("tmp_user_type", $_SESSION['login']['user_type'], time()+3600, "/");
- setcookie("tmp_oper_token", $_SESSION['login']['operator_token'], time()+3600, "/");
- setcookie("tmp_token", $_SESSION['login']['token'], time()+3600, "/");
- setcookie("tmp_users", $operator['users'], time()+3600, "/");
- setcookie("tmp_name", $operator['operator_name'], time()+3600, "/");
- setcookie("tmp_online_photo", $operator['online_avatar'], time()+3600, "/");
- setcookie("operator_id", $_SESSION['login']['operator_id'], time() + (86400*30), "/");
- setcookie("company_id", $_SESSION['login']['company_id'], time() + (86400*30), "/");
- setcookie("user_type", $operator['operator_title'], time() + (86400*30), "/");
- setcookie("oper_token", $operator['auth_key'], time() + (86400*30), "/");
- setcookie("token", $company[0]['token'], time() + (86400*30), "/");
- setcookie("name", $operator['operator_name'], time() + (86400*30), "/");
- setcookie("users", $operator['users'], time() + (86400*30), "/");
- setcookie("online_photo", $operator['online_avatar'], time() + (86400*30), "/");
- return true;
- }
- else
- return false;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement