Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$zka->setUser() not working properly #131

Open
WalidRH opened this issue Jun 2, 2024 · 0 comments
Open

$zka->setUser() not working properly #131

WalidRH opened this issue Jun 2, 2024 · 0 comments

Comments

@WalidRH
Copy link

WalidRH commented Jun 2, 2024

hello
Does anyone encountered the following issue while adding a new user to the device ?

Sometimes when I try to add a new user to the device, I got a response OK. But when I check the list of users I don't find the recently added user. And the same issue continue if I retried multiple times. but when I restart the device and resend the same user data, there it's added succefully.
the Code I used for adding a new user.

`public function setUser($device_ip, $port, Request $request)
{
$uid = $request['uid'];
$userid = $request['userid'];
$name = $request['name'];
$role = $request['role'];
$password = $request['password'];
$cardno = $request['cardno'];

    $userValidity = $this->isUserDataValid($uid,$userid,$name,$role,$password,$cardno);

    if($userValidity !== true){
        Log::info($userValidity);
        $error = [
            "error" => $userValidity
        ];
        Log::info($error);
        return response()->json($error, 400);
    }
    
    $zka = ConnectionUtils::connectDevice($device_ip, $port);
    if ($zka === false) {
        return response()->json("connection refused", 408);
    }
    $zka->disableDevice();

    $result = $zka->setUser($uid,$userid,$name,$password,$role,$cardno);
    Log::info($result);
    if ($result === false){
        $error = [
            "error" => "Error occurred while adding user to the device."
        ];
        
        return response()->json($error, 502);
    }
    $result = [
        "response" => "User has been successfully added to the device."
    ];
    $zka->enableDevice();
    $zka->disconnect();
    return response()->json($result, 200);
}



    private function isUserDataValid($uid,$userid,$name,$role,$password,$cardno){
    if ($uid > 65535){
        return "uid too large";
    }

    if (strlen($userid) > 9 || !preg_match('/^\d+$/', $userid)){
        return "User ID should contain a maximum of 9 digits.";
    }

    if (strlen($name) > 24){
        return "user name should have less than 24 characters";
    }

    if (strlen($password) > 8 || !preg_match('/^\d+$/', $password)){
        return "password should contain a maximum of 8 digits.";
    }

    if ( $role !== 0 && $role !== 14 ){
        return "user role should either be 0 (for user role), 14 (for admin role).";
    }

    if ( strlen($cardno) > 10 ){
        return "Cardno should contain a maximum of 10 digits.";
    }
    return true;
}`

The problem is that, I don't know HOW or WHEN should I add a user.
The device I use F18

{
"device_Version": "Ver 6.60 ",
"device_OSVersion": "1",
"device_Platform": "ZMM210_TFT",
"device_fmVersion": "10",
"device_fmEdition": "Ver 6.60 Apr 26 2016",
"device_workCode": "0",
"device_ssr": "1",
"device_pinWidth": "9",
"device_deviceName": "F18/ID",
}

Deos anyone have an explanation for this issue??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant