<?php
require_once "../../../bootstrap.php";
require_once "../Admin/Admin.php";

use \Backend\Models\Password;

//session_start();
if(isAdmin()){
    if(isset($_POST['restPassword'])){
        $password = Password::firstWhere("group_id",$_POST['groupId']);
        if($password){
            $password->password =  password_hash($_POST['newPassword'], PASSWORD_DEFAULT);
            echo $password;
            if(!$password->save()){
                http_response_code(500);
            }else{
                http_response_code(201);
            }
        }else{
            http_response_code(400);
            echo json_encode(["message" => "group not found"]);
        }

    }else{
        http_response_code(400);
    }
}else{
    http_response_code(401);
    echo json_encode(["message" => "is not admin"]);
}