File: public/login.php

Recommend this page to a friend!
  Classes of Joseluis Laso  >  PHP Telegram CLI Wrapper  >  public/login.php  >  Download  
File: public/login.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Telegram CLI Wrapper
Send messages and other commands to Telegram users
Author: By
Last change:
Date: 4 years ago
Size: 875 bytes
 

Contents

Class file image Download
<?php

session_start
();

include_once
__DIR__ . '/../vendor/autoload.php';

use
TelegramCliWrapper\Storage\LocalFilesStorage;
use
TelegramCliWrapper\Response;

if (!isset(
$_POST['phone'])) {
    return
Response::error('phone parameter missed');
}
if (!isset(
$_POST['code'])) {
    return
Response::error('code parameter missed');
}

$code = trim($_POST['code']);
$phone = trim($_POST['phone']);
if (!
preg_match("/^\d{9,15}$/", $phone)) {
    return
Response::error('phone parameter does not seems a phone number');
}

$userStorage = new LocalFilesStorage('user');
$user = $userStorage->getById($phone);
if (!
$user) {
    return
Response::error('phone does not exist in this system');
}

if (
$user->code <> $code) {
    return
Response::error('phone or code are wrong');
}

$user->logged = true;
$userStorage->save($user);

$_SESSION['user'] = $phone;

return
Response::ok();


For more information send a message to info at phpclasses dot org.