2017-10-02 12 views
0

のドキュメントのどこにも見つかりません。コードIgniter - Community Auth単純な機能を使用してユーザーの資格情報をチェックする方法。私は関数を呼び出すだけです。Code Igniter Community Auth PHPでログイン資格情報をユーザ名とパスワードの両方でチェックするにはどうしたらいいですか?

例:checkIfValid( 'ユーザ名'、 'mypassword123')

 $uid = array_key_exists('uid', $_POST) ? (empty($_POST['uid']) ? '' : $_POST['uid']) : ''; 
     $pwd = array_key_exists('pwd', $_POST) ? (empty($_POST['pwd']) ? '' : $_POST['pwd']) : ''; 

     if ($uid == '' || $pwd == '') { echo $error_response; return; }; 

     $auth_model = $this->authentication->auth_model; 
     // HOW CAN I LOGIN WITH BOTH USERNAME AND PASSWORD LIKE CALLING A FUNCTION? THIS CODE ONLY LOGS IN USER UID ONLY 
     $auth_data = $this->{$auth_model}->get_auth_data($uid); 

     if ($auth_data) { 
      $this->authentication->maintain_state($auth_data); 
      echo 'login'; 
      return; 
     } 
+0

行われます。 –

+0

完全なコード[コントローラ、モデル、ライブラリ] –

+0

これはコミュニティの認証ライブラリです。コントローラ、モデルファイルはここにあります:https://bitbucket.org/skunkbad/community-auth-for-codeigniter -3/get/master.zip – jestrange

答えて

1

あなたのコントローラオン認証は、あなたがこれを達成するために、フォルダのライブラリに独自のライブラリを作成する必要があり、ここで

 $this->load->library('authentication'); 

     $res = $this->authentication->login($requirement, $user_string, $passwd); // requirement is user level 

     if ($res) 
     { 
      echo "User authenticated"; // or do something here 
     } 
     else 
     { 
      print_r($res); // or do something what ever 
     } 
+0

ありがとう! +1 これはドキュメントに記載されていないのが奇妙です。 – jestrange

0

私はよく分からないが、これを試してみてください。

// Get normal authentication data using username or password 
    if($auth_data = $this->{$auth_model}->get_auth_data($uid,$pwd)) 
    { 
     /** 
     * If redirect param exists, user redirected there. 
     * This is entirely optional, and can be removed if 
     * no redirect is desired. 
     */ 
     $_GET['redirect'] = 'somewhere'; 
     $this->authentication->redirect_after_login(); 

     // Set auth related session/cookies 
     $this->authentication->maintain_state($auth_data); 
    } 
} 
else 
{ 
    echo 'Example requires that you set a username or password.'; 
} 
+0

get_auth_dataはAuth_model.phpでそのように定義されていませんでした。 – jestrange

関連する問題