jeudi 1 avril 2021

I want to update jwt token with login time in codeigniter

I want to update jwt token on time of login and set that jwt token into my database user's table. I hope You will definitely help me out with that. Thanks

this is my user controller

public function canLogin()
    {
        $method = $_SERVER['REQUEST_METHOD'];
        if ($method == 'GET') {
            json_output(404, array('message' => 'Method must be a POST'));
        } else {
            $params = (array) json_decode(file_get_contents('php://input'), true);
            $email = $params['email'];
            $password = $params['password'];
            // $tokenData = $this->authorization_token->generateToken($email, $password);
            // $final = array();
            // $final['token'] = $tokenData;
            // json_output(200, array('code' => 200, 'data' => $final));
            if ($email && $password == true) {
                $data = $this->Users_Model->canLogin($email);
                if ($data != null) {
                    $check_password = password_verify($password, $data[0]['password']);
                    if ($check_password) {
                        json_output(200, array('code' => 200, 'message' => "Successfully Login", "data" => $data));
                    } else {
                        json_output(200, array('code' => 400, 'message' => "Invalid Password"));
                    }
                } else {
                    json_output(200, array('code' => 400, 'message' => "Email not Found"));
                }
            } else {
                json_output(200, array('code' => 400, 'message' => "Email or Password Shouldn't be null"));
            }
        }
    }

this is my user model function:

public function canLogin($email)
    {
        $this->db->select('*');
        $this->db->where('email', $email);
        // $query  =   $this->db->get($this->users);
        $query = $this->db->get('users');
        // $row = $query->row();
        return $query->result_array();



Aucun commentaire:

Enregistrer un commentaire