Game-Jaming/Backend/Controllers/Group/UpdatePassword.php

29 lines
821 B
PHP

<?php
require_once "../../../bootstrap.php";
require_once "Group.php";
use Backend\Models\Password;
if (isLogin()) {
if (isset($_POST['updatePassword'])) {
$password = Password::firstWhere("group_id", groupViaToken($_SESSION["token"])->id);
if (passwordValidate($pass = $_POST['password'])) {
$password->password = password_hash($pass, PASSWORD_DEFAULT);
if (!$password->save()) {
http_response_code(500);
} else {
http_response_code(201);
}
} else {
http_response_code(400);
echo json_encode(["message" => "password not valid"]);
}
} else {
http_response_code(400);
}
} else {
http_response_code(401);
echo json_encode(["message" => "is not login"]);
}