2021-03-11 08:28:30 +00:00
|
|
|
<?php
|
|
|
|
require_once "../../../bootstrap.php";
|
|
|
|
require_once "Group.php";
|
2021-04-19 07:15:15 +00:00
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
use Backend\Models\Password;
|
|
|
|
|
2021-04-19 07:15:15 +00:00
|
|
|
if (isLogin()) {
|
|
|
|
if (isset($_POST['updatePassword'])) {
|
2021-03-17 08:43:09 +00:00
|
|
|
$password = Password::firstWhere("group_id", groupViaToken($_SESSION["token"])->id);
|
2021-04-19 07:15:15 +00:00
|
|
|
if (passwordValidate($pass = $_POST['password'])) {
|
|
|
|
$password->password = password_hash($pass, PASSWORD_DEFAULT);
|
|
|
|
if (!$password->save()) {
|
2021-03-23 12:39:44 +00:00
|
|
|
http_response_code(500);
|
2021-04-19 07:15:15 +00:00
|
|
|
} else {
|
2021-03-23 12:39:44 +00:00
|
|
|
http_response_code(201);
|
2021-03-19 12:25:27 +00:00
|
|
|
}
|
2021-04-19 07:15:15 +00:00
|
|
|
} else {
|
2021-03-23 12:39:44 +00:00
|
|
|
http_response_code(400);
|
|
|
|
echo json_encode(["message" => "password not valid"]);
|
|
|
|
}
|
2021-04-19 07:15:15 +00:00
|
|
|
} else {
|
2021-03-23 12:39:44 +00:00
|
|
|
http_response_code(400);
|
2021-03-11 08:28:30 +00:00
|
|
|
}
|
|
|
|
|
2021-04-19 07:15:15 +00:00
|
|
|
} else {
|
2021-03-23 12:39:44 +00:00
|
|
|
http_response_code(401);
|
|
|
|
echo json_encode(["message" => "is not login"]);
|
2021-03-11 08:28:30 +00:00
|
|
|
}
|