コード例 #1
0
ファイル: oauth.php プロジェクト: anush-cr/campusbookie
        $msg = $_SERVER['REQUEST_METHOD'] . " not allowed. Use POST.";
        throw new BadMethodCallException($msg, 403);
    }
    if (!isset($_POST['grant_type'])) {
        throw new InvalidArgumentException("grant type cannot be empty", 400);
    }
    if (!isset($_POST['email'])) {
        throw new InvalidArgumentException("email cannot be empty", 400);
    }
    if (!isset($_POST['password'])) {
        throw new InvalidArgumentException("password cannot be empty", 400);
    }
    if ($_POST['grant_type'] != 'password') {
        $msg = "Grant type: " . $_POST['grant_type'] . " not implemented yet.";
        throw new DomainException($msg, 501);
    }
    $email = $_REQUEST['email'];
    $password = $_REQUEST['password'];
    $auth = new oauth_server();
    $uid = oauth_server::authenticateUser($email, $password);
    $res = array("status" => "success", "message" => null);
    $res['data'] = oauth_server::generate_token($uid);
    $res['data']['_links']['user_info']['href'] = "/user/" . $uid;
    response($res, 200);
    exit;
} catch (Exception $e) {
    $errMsg = $e->getMessage();
    $res = array("status" => "error", "message" => $errMsg, "data" => null);
    response($res, $e->getCode());
    exit;
}
コード例 #2
0
ファイル: user.php プロジェクト: anush-cr/campusbookie
 public function user_login()
 {
     unset($this->_params['0']);
     $email = isset($this->_params['email']) ? $this->_params['email'] : '';
     $password = isset($this->_params['password']) ? $this->_params['password'] : '';
     require_once '../oauth/oauth_class.php';
     $auth = new oauth_server();
     $uid = $auth->authenticateUser($email, $password);
     $token = $auth->generate_token($uid);
     $this->_user_id = $token['user_id'];
     $token = array_merge($token, $this->user_get()['data']['data']);
     unset($token['id']);
     $retData = array();
     $retData['staus'] = "success";
     $retData['message'] = null;
     $retData['data'] = $token;
     return array('data' => $retData, 'status' => 200);
 }