add client_add_password

This commit is contained in:
Andrey Kuvshinov
2020-05-10 12:14:54 +03:00
parent fc28ed1c9b
commit 603f1fd96f
4 changed files with 84 additions and 2 deletions

View File

@@ -54,6 +54,52 @@ function clientbuys_kuri($client_id, $page = 1){
function client_find_email($email){
$pwd_query = "SELECT * FROM `clients` WHERE `clientmail` = '$mail' LIMIT 1";
$client = db_get($pwd_query);
if (isset($client['client_id']))
return $client;
else
return false;
}
function client_add_password($mail, $pwd, $pwd2){
$maxlen = 5;
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
return 'некорректный email';
$find = client_find_email($email);
if ($find)
return 'email не найден';
if ($pwd == ''){
return 'пароль не задан';
}
if (strlen($pwd) < $maxlen) {
return "пароль должен быть не менее $maxlen символов";
}
if ($pwd == $pwd2){
return "пароли не совпадают";
}
$clientpassword = password_hash($pwd);
$sqlupdate = "UPDATE `clients` SET `clientpassword` = '$clientpassword' WHERE `clientmail` = '$mail'";
dbl_get($sqlupdate);
return True;
}
function clientmail($mail, $hash){ function clientmail($mail, $hash){
$client = db_get("SELECT * FROM `clients` WHERE `clientmail` = $mail LIMIT 1"); $client = db_get("SELECT * FROM `clients` WHERE `clientmail` = $mail LIMIT 1");

View File

@@ -1,7 +1,7 @@
<?php <?php
ini_set('display_errors', 0); ini_set('display_errors', 1);
ini_set('display_startup_errors', 0); ini_set('display_startup_errors', 1);
if (isset($_SERVER['HTTP_HOST'])) if (isset($_SERVER['HTTP_HOST']))

View File

@@ -0,0 +1,26 @@
<?php
function login(){
}
function resetpwd_kuri($mail){
$url = "/resetpwd/$mail";
if (isset($_POST['submit'])){
$result = client_add_password($mail, $_POST['pass'], $_POST['pass2']);
if ($result){
echo 'пароль установлен';
}
}
include VIEWPATH.'reset.phtml';
}

10
app/views/reset.phtml Normal file
View File

@@ -0,0 +1,10 @@
<form method="POST" action="<?=$url?>">
<p>Придумайте пароль не менее 5 символов</p>
<p>Пароль:<input name="pass" type="password" required></p>
<p>Повторить:<input name="pass2" type="password" required></p>
<input name="submit" type="submit" value="Сохранить пароль">
</form>
<?if (isset($result)):?>
<div id="error" style="color: red;"><?=$result?></div>
<?endif?>