diff --git a/app/api/apiclient.php b/app/api/apiclient.php index b108284..24a0b7c 100644 --- a/app/api/apiclient.php +++ b/app/api/apiclient.php @@ -32,6 +32,83 @@ function api_login($login, $password){ } +function api_restore_mail($mail){ + + $date = date("Y-m-d H:i:s"); + $hash = md5($mail.$date); + + $add = []; + + $add['mail'] = $mail; + $add['restore'] = false; + $add['date'] = $date; + $add['hash'] = $hash; + + $res = db_insert('restorations', $add); + + if ($res > 0) + return $hash; + +} + +function api_restore_hash($hash){ + + $re_sql = " + SELECT + `id`, `restore`, `mail` + FROM + `restorations` + WHERE + `hash` = '$hash' + LIMIT + '1' + "; + $res = db_get($re_sql); + + if (isset($res['restore']) AND $res['restore'] == 0){ + + db_get(" + UPDATE + `restorations` + SET + `restore` = '1' + WHERE + `id` = '${res['id']}' + "); + + db_get(" + UPDATE + `clients` + SET + `clientpassword` = '' + WHERE + `clientmail` = '${res['mail']}' + "); + + $client_hash = db_get(" + SELECT + `clienthash` + FROM + `clients` + WHERE + `client_mail` = '${res['mail']}' + LIMIT + 1"); + + if (isset($client_hash['clienthash'])) + return $client_hash; + else + return false; + } + else + return false; + +} + + + + + function clientbuys_kuri($client_mail, $page = 1, $category_id = 1, $group_id = null, $filter = null){ if ($group_id == 1 or $group_id == 2){ diff --git a/app/composer.json b/app/composer.json index 747bdf8..40c1ff4 100644 --- a/app/composer.json +++ b/app/composer.json @@ -4,7 +4,8 @@ "php":">=5.3.0", "masterforweb/kuri":"dev-master", "masterforweb/db_lite":"dev-master", - "mobiledetect/mobiledetectlib": "^2.8" + "mobiledetect/mobiledetectlib": "^2.8", + "phpmailer/phpmailer": "^6.1" }, "repositories":[ diff --git a/app/confg.php b/app/confg.php index ca3c6bd..fffa1dd 100644 --- a/app/confg.php +++ b/app/confg.php @@ -1,6 +1,6 @@ 'noreply@argumenti.ru', + 'name' => 'Аргументы Недели', + 'password'=>'eessoj8Let', + 'port'=>465, + 'host'=>'smtp.mail.ru', + 'secure' => 'ssl' +]); + db_config('argumentiru', 'mysql:host=mysql;dbname=argumentiru', 'newser', 'Chjk90yuiREY'); db_config('reader', 'mysql:host=mysql;dbname=argumentiru', 'reader', 'ghjyjkUIOhg56Fh'); diff --git a/app/routes/client.php b/app/routes/client.php index ac6ba89..6518514 100644 --- a/app/routes/client.php +++ b/app/routes/client.php @@ -80,7 +80,48 @@ function addcard($id, $date) { } +function restoration_kuri(){ + if (isset($_POST['reset_mail'])){ + $email = $_POST['reset_mail']; + $title = 'Восстановление пароля'; + + $hash = api_restore_mail($mail); + + if ($hash !== false) { + $hashlink = SITE.'resetlink/'.$hash; + } + + echo $hashlink; + + $tempcontent = VIEWPATH.'restore_add.phtml'; + include VIEWPATH.'layout.phtml'; + } + else { + $title = 'Восстановление пароля'; + $tempcontent = VIEWPATH.'restore.phtml'; + include VIEWPATH.'layout.phtml'; + } + + return true; + +} + + +function resetlink_kuri($hash){ + + $res = api_restore_hash($hash); + + if (!$res){ + + } + else { + header("HTTP/1.1 301 Moved Permanently"); + header("Location: ${SITE}/resetpwd/"); exit(); + } + + +} diff --git a/app/routes/email.php b/app/routes/email.php new file mode 100644 index 0000000..22352e0 --- /dev/null +++ b/app/routes/email.php @@ -0,0 +1,34 @@ +isSMTP(); + //$send->SMTPDebug=3; // Set mailer to use SMTP + $send->Host = $config['host']; // Specify main and backup SMTP servers + $send->Username = $config['login']; // SMTP username + $send->Password = $config['password']; + + if (isset($frommail['secure'])) { + $send->SMTPSecure = $frommail['secure']; + $send->SMTPAuth = true; + } + else { + $mail->SMTPSecure = false; + $mail->SMTPAutoTLS = false; + } + + $send->Port = $config['port']; // TCP port to connect to + $send->setFrom($config['mail'], $config['name']); + $send->addAddress($mail, $mail); // Add a recipient + $send->CharSet = 'UTF-8'; + $send->isHTML(True); // Set email format to HTML + $send->Subject = $mail['subject']; + $send->Body = $mail['message']; + + return $send->send(); + +} \ No newline at end of file diff --git a/app/views/login.phtml b/app/views/login.phtml index 0aec2c7..c402513 100644 --- a/app/views/login.phtml +++ b/app/views/login.phtml @@ -4,6 +4,7 @@
+ diff --git a/app/views/restore.phtml b/app/views/restore.phtml new file mode 100644 index 0000000..38db8f3 --- /dev/null +++ b/app/views/restore.phtml @@ -0,0 +1,9 @@ +
Ссылка для восстановление пароля отправлена на =$email?>
+