简体   繁体   English

登录前如何检查用户是否处于活动状态

[英]How to check user is active and inactive before login

I have field status which is set to inactive default only admin can make it active so what condition I can use to check it 我的字段状态已设置为非活动默认状态,只有管理员可以使其处于活动状态,因此我可以使用哪种条件进行检查

    public function loginUser($email, $password) {

      $db = $this -> db;

      if (!empty($email) && !empty($password)) {

        if ($db -> checkUserExist($email)) {

           $result =  $db -> checkLogin($email, $password);


           if(!$result) {

            $response["result"] = "failure";
            $response["message"] = "Invaild Login Credentials";
            return json_encode($response);

           } else {

            $response["result"] = "success";
            $response["message"] = "Login Successful";
            $response["user"] = $result;
            return json_encode($response);

           }

        } else {

          $response["result"] = "failure";
          $response["message"] = "Invaild Login Credentials";
          return json_encode($response);

        }
      } else {

          return $this -> getMsgParamNotEmpty();
        }

    }

       public function checkLogin($email, $password) {

    $sql = 'SELECT * FROM emp_registration WHERE  email = :email';
    $query = $this -> conn -> prepare($sql);
    $query -> execute(array(':email' => $email));
    $data = $query -> fetchObject();
    $salt = $data -> salt;
    $db_encrypted_password = $data -> password;
 $status = $data->status; // get status value
    if ($this -> verifyHash($password.$salt,$db_encrypted_password) ) {


        $user["name"] = $data -> full_name;
        $user["email"] = $data -> email;
        $user["unique_id"] = $data -> id;
        return $user;

    } else {

        return false;
    }

 }

I am checking status is active or not In table status type is enum('Active', 'InActive') 我正在检查状态是否为活动状态在表状态类型为enum('Active','InActive')

You can try it: 你可以试试:

$status = $data -> status;
if($status == "active"){
if ($this -> verifyHash($password.$salt,$db_encrypted_password) ) {
    $user["name"] = $data -> full_name;
$user["email"] = $data -> email;
$user["unique_id"] = $data -> id;
    $user["status"] = $data -> status;
    return $user;
} else {
    return false;
}
}else{ 

echo "inactive user";
}

For more information, please checkout the below thread: 有关更多信息,请签出以下线程:

Check if user is not active, not to log in 检查用户是否不活跃,不登录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM