Files
anpdf/app/routes/auth.php

265 lines
6.4 KiB
PHP
Raw Normal View History

2020-05-10 12:14:54 +03:00
<?php
2020-05-12 21:15:26 +03:00
function login_kuri(){
if (isset($_POST['username']) and isset($_POST['password'])){
$result = api_login($_POST['username'], $_POST['password']);
if (isset($result['error'])){
$error = $result['error'];
}
if (isset($result['data'])) {
add_user_cookie($result['data']['client_id'], $result['data']['clientpassword']);
header('Location: '.SITE.'mybooks');
}
}
2020-05-12 22:56:44 +03:00
// if (isset($_COOKIE['chitatel'])){
// out();
// }
2020-05-12 21:15:26 +03:00
$tempcontent = VIEWPATH.'login.phtml';
include VIEWPATH.'layout_lite.phtml';
return true;
}
function out_kuri(){
2020-05-12 22:56:44 +03:00
if (isset($_COOKIE['chitatel'])) {
unset($_COOKIE['chitatel']);
setcookie('chitatel', null, -1,'/', $_SERVER['HTTP_HOST']);
}
if (isset($_COOKIE['code'])) {
unset($_COOKIE['code']);
setcookie('code', null, -1, '/', $_SERVER['HTTP_HOST']);
}
2020-05-12 21:15:26 +03:00
header('Location: '.SITE.'login');
2020-05-10 12:14:54 +03:00
}
2020-05-12 21:15:26 +03:00
function add_user_cookie($user, $pwd){
2020-05-10 12:14:54 +03:00
2020-05-12 21:15:26 +03:00
$timeout = time()+(60*60*24*30);
2020-05-10 12:14:54 +03:00
2020-05-12 21:15:26 +03:00
// ini_set ("session.use_trans_sid", true);
// session_start();
2020-05-12 22:56:44 +03:00
$secret = client_secret($user, $pwd);
setcookie ("chitatel", $user, $timeout, '/', $_SERVER['HTTP_HOST']);
setcookie ("code", $secret, $timeout, '/', $_SERVER['HTTP_HOST']);
2020-05-12 21:15:26 +03:00
}
function check_login_kuri(){
//ini_set ("session.use_trans_sid", true);
//session_start();
2020-05-10 12:14:54 +03:00
2020-05-12 22:56:44 +03:00
$client = client_check_auth($_COOKIE['chitatel'], $_COOKIE['code']);
2020-05-12 21:15:26 +03:00
if (!isset($client['data'])){
return $client;
2020-05-10 12:14:54 +03:00
}
2020-05-12 21:15:26 +03:00
else {
return $client['data'];
}
//$_SESSION['id'] = $row['id']; //записываем в сессию id пользователя
}
function redirect_login(){
header('Location: '.SITE.'login');
exit;
}
2020-05-29 20:34:26 +03:00
//имитируем заход под юзером
function test_client_hash_kuri($hash){
2020-05-12 21:15:26 +03:00
2020-05-29 20:34:26 +03:00
$client = client_find_hash($hash);
2020-05-29 21:29:27 +03:00
print_r($client);
if (!isset($client['error'])) {
2020-05-29 18:01:28 +00:00
out_kuri();
add_user_cookie($client['client_id'],$client['clientpassword']);
2020-05-29 20:34:26 +03:00
}
2020-05-29 21:29:27 +03:00
exit;
return;
2020-05-12 21:15:26 +03:00
2020-05-29 20:34:26 +03:00
}
2020-05-12 21:15:26 +03:00
2020-08-27 23:40:34 +03:00
function reminder_kuri(){
if (isset($_POST['resetmail'])){
$resetmail = trim(mb_strtolower($_POST['resetmail']));
$client = db_get("SELECT * FROM `clients` WHERE `clientmail` = '$resetmail' LIMIT 1");
if (count($client) > 0 ) {
$resetdate = date('Y-m-d G:i:s');
$items = array();
$items['resetmail'] = $resetmail;
$items['client_id'] = $client['client_id'];
$items['resetdate'] = $resetdate;
$items['resetstatus'] = 0;
$items['resethash'] = md5($resetmail.$resetdate);
2020-08-27 23:43:30 +03:00
$result = db_insert('resetpwd', $items, 'chitatel');
2020-08-27 23:40:34 +03:00
$link = SITE.'resetpassword/'.$items['resethash'];
2020-08-29 12:50:57 +03:00
$mailconfig = set('noreply');
$mail['mail'] = $resetmail;
$mail['subject'] = 'КЛАН: создание пароля';
$mail['message'] = "
2020-08-29 16:17:42 +03:00
Вы запросили изменения пароля для Вашей учетной записи.\n
2020-08-29 17:30:13 +03:00
Для установления пароля пройдите по ссылке -> $link\n\n
2020-08-29 16:17:42 +03:00
- Не передавайте эту ссылку сторонним лицам!\n
- Если Вы не запрашивали это действие просто проигнорируйте данное письмо.\n\n
По вопросам обращайтесь на почту: shop@argumenti.ru
";
2020-08-29 12:50:57 +03:00
sendmail($mailconfig, $mail);
2020-08-27 23:40:34 +03:00
$tempcontent = VIEWPATH.'reminder_end.phtml';
include VIEWPATH.'layout_lite.phtml'; //центральный шаблон
}
else {
$error = 'Адрес электронной почты не найден';
$tempcontent = VIEWPATH.'reminder.phtml';
include VIEWPATH.'layout_lite.phtml'; //центральный шаблон
}
}
else {
$tempcontent = VIEWPATH.'reminder.phtml';
include VIEWPATH.'layout_lite.phtml'; //центральный шаблон
}
}
function resetpassword_kuri($hash){
$url = "/resetpassword/$hash";
$minlen = 5;
$resetsql = "SELECT * FROM `resetpwd` WHERE `resethash` = '$hash' AND `resetstatus` = '0' LIMIT 1";
$resetclient = db_get($resetsql);
if (count($resetclient) > 0){
if (isset($_POST['reset-submit'])){
$result = client_add_password($resetclient['client_id'], $_POST['new-password'], $_POST['confirm-password'], $minlen);
if (isset($result['newpassword'])){
2020-08-29 13:18:05 +03:00
$updsql = "UPDATE `resetpwd` SET `resetstatus` = 1 WHERE `resetpwd_id` = '".$resetclient['resetpwd_id']."'" ;
db_get($updsql, 'chitatel');
2020-08-27 23:40:34 +03:00
add_user_cookie($client['client_id'], $result['newpassword']);
$linklab = SITE.'mybooks';
$viewform = False;
}
}
else {
$viewform = True;
}
$tempcontent = VIEWPATH.'reset.phtml';
include VIEWPATH.'layout_lite.phtml';
}
2020-08-29 13:18:05 +03:00
2020-08-27 23:40:34 +03:00
else {
echo 'неверная ссылка';
return false;
}
return True;
}
2020-05-12 21:15:26 +03:00
// if(password_verify($_POST["password"],$hashed_password))
function resetpwd_kuri($hash){
$url = "/resetpwd/$hash";
$minlen = 5;
$viewform = true;
$client = client_find_hash($hash);
if (isset($client['error'])) {
$error = $client['error'];
$viewform = False;
2020-05-10 12:14:54 +03:00
2020-05-12 21:15:26 +03:00
}
else if ($client['clientpassword'] !== ''){
$error = 'Пароль уже был изменен';
2020-05-29 20:34:26 +03:00
2020-05-12 21:15:26 +03:00
$viewform = False;
}
if (isset($_POST['reset-submit'])){ //пришла форма
$result = client_add_password($client['client_id'], $_POST['new-password'], $_POST['confirm-password'], $minlen);
2020-05-13 01:02:18 +03:00
if (isset($result['newpassword'])){
add_user_cookie($client['client_id'], $result['newpassword']);
2020-05-12 21:15:26 +03:00
$linklab = SITE.'mybooks';
$viewform = False;
}
else {
$error = $result['error'];
}
}
$tempcontent = VIEWPATH.'reset.phtml';
include VIEWPATH.'layout_lite.phtml'; //центральный шаблон
2020-05-10 12:14:54 +03:00
}