本文整理汇总了PHP中identity::guest方法的典型用法代码示例。如果您正苦于以下问题:PHP identity::guest方法的具体用法?PHP identity::guest怎么用?PHP identity::guest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类identity
的用法示例。
在下文中一共展示了identity::guest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create_comment_for_guest_test
public function create_comment_for_guest_test()
{
$comment = ORM::factory("comment");
$comment->item_id = item::root()->id;
$comment->text = "text";
$comment->author_id = identity::guest()->id;
$comment->guest_name = "name";
$comment->guest_email = "email@email.com";
$comment->guest_url = "http://url.com";
$comment->save();
$this->assert_equal("name", $comment->author_name());
$this->assert_equal("email@email.com", $comment->author_email());
$this->assert_equal("http://url.com", $comment->author_url());
$this->assert_equal("text", $comment->text);
$this->assert_equal(1, $comment->item_id);
$this->assert_equal("REMOTE_ADDR", $comment->server_remote_addr);
$this->assert_equal("HTTP_USER_AGENT", $comment->server_http_user_agent);
$this->assert_equal("HTTP_ACCEPT", $comment->server_http_accept);
$this->assert_equal("HTTP_ACCEPT_CHARSET", $comment->server_http_accept_charset);
$this->assert_equal("HTTP_ACCEPT_ENCODING", $comment->server_http_accept_encoding);
$this->assert_equal("HTTP_ACCEPT_LANGUAGE", $comment->server_http_accept_language);
$this->assert_equal("HTTP_CONNECTION", $comment->server_http_connection);
$this->assert_equal("HTTP_HOST", $comment->server_http_host);
$this->assert_equal("HTTP_REFERER", $comment->server_http_referer);
$this->assert_equal("HTTP_USER_AGENT", $comment->server_http_user_agent);
$this->assert_equal("QUERY_STRING", $comment->server_query_string);
$this->assert_equal("REMOTE_ADDR", $comment->server_remote_addr);
$this->assert_equal("REMOTE_HOST", $comment->server_remote_host);
$this->assert_equal("REMOTE_PORT", $comment->server_remote_port);
$this->assert_true(!empty($comment->created));
}
示例2: create_comment_for_guest_test
public function create_comment_for_guest_test()
{
$rand = rand();
$root = ORM::factory("item", 1);
$comment = comment::create($root, identity::guest(), "text_{$rand}", "name_{$rand}", "email_{$rand}", "url_{$rand}");
$this->assert_equal("name_{$rand}", $comment->author_name());
$this->assert_equal("email_{$rand}", $comment->author_email());
$this->assert_equal("url_{$rand}", $comment->author_url());
$this->assert_equal("text_{$rand}", $comment->text);
$this->assert_equal(1, $comment->item_id);
$this->assert_equal("REMOTE_ADDR", $comment->server_remote_addr);
$this->assert_equal("HTTP_USER_AGENT", $comment->server_http_user_agent);
$this->assert_equal("HTTP_ACCEPT", $comment->server_http_accept);
$this->assert_equal("HTTP_ACCEPT_CHARSET", $comment->server_http_accept_charset);
$this->assert_equal("HTTP_ACCEPT_ENCODING", $comment->server_http_accept_encoding);
$this->assert_equal("HTTP_ACCEPT_LANGUAGE", $comment->server_http_accept_language);
$this->assert_equal("HTTP_CONNECTION", $comment->server_http_connection);
$this->assert_equal("HTTP_HOST", $comment->server_http_host);
$this->assert_equal("HTTP_REFERER", $comment->server_http_referer);
$this->assert_equal("HTTP_USER_AGENT", $comment->server_http_user_agent);
$this->assert_equal("QUERY_STRING", $comment->server_query_string);
$this->assert_equal("REMOTE_ADDR", $comment->server_remote_addr);
$this->assert_equal("REMOTE_HOST", $comment->server_remote_host);
$this->assert_equal("REMOTE_PORT", $comment->server_remote_port);
$this->assert_true(!empty($comment->created));
}
示例3: deleting_an_item_deletes_its_comments_too_test
public function deleting_an_item_deletes_its_comments_too_test()
{
$rand = rand();
$album = album::create(ORM::factory("item", 1), "test_{$rand}", "test_{$rand}");
$comment = comment::create($album, identity::guest(), "text_{$rand}", "name_{$rand}", "email_{$rand}", "url_{$rand}");
$album->delete();
$deleted_comment = ORM::factory("comment", $comment->id);
$this->assert_false($deleted_comment->loaded);
}
示例4: deleting_an_item_deletes_its_comments_too_test
public function deleting_an_item_deletes_its_comments_too_test()
{
$album = test::random_album();
$comment = ORM::factory("comment");
$comment->item_id = $album->id;
$comment->author_id = identity::guest()->id;
$comment->guest_name = "test";
$comment->text = "text";
$comment->save();
$album->delete();
$this->assert_false(ORM::factory("comment", $comment->id)->loaded());
}
示例5: viewable_test
public function viewable_test()
{
$root = ORM::factory("item", 1);
$album = album::create($root, rand(), rand(), rand());
$item = self::_create_random_item($album);
identity::set_active_user(identity::guest());
// We can see the item when permissions are granted
access::allow(identity::everybody(), "view", $album);
$this->assert_equal(1, ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all());
// We can't see the item when permissions are denied
access::deny(identity::everybody(), "view", $album);
$this->assert_equal(0, ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all());
}
示例6: viewable_test
public function viewable_test()
{
$album = test::random_album();
$item = test::random_photo($album);
$album->reload();
identity::set_active_user(identity::guest());
// We can see the item when permissions are granted
access::allow(identity::everybody(), "view", $album);
$this->assert_equal(1, ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all());
// We can't see the item when permissions are denied
access::deny(identity::everybody(), "view", $album);
$this->assert_equal(0, ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all());
}
示例7: post_fails_without_permissions_test
public function post_fails_without_permissions_test()
{
access::deny(identity::everybody(), "edit", item::root());
identity::set_active_user(identity::guest());
try {
$request->params->name = "test tag";
tags_rest::post($request);
} catch (Exception $e) {
$this->assert_equal(403, $e->getCode());
return;
}
$this->assert_true(false, "Shouldnt get here");
}
示例8: cant_view_comments_for_unviewable_items_test
public function cant_view_comments_for_unviewable_items_test()
{
$root = ORM::factory("item", 1);
$album = album::create($root, rand(), rand(), rand());
$comment = comment::create($album, identity::guest(), "text", "name", "email", "url");
identity::set_active_user(identity::guest());
// We can see the comment when permissions are granted on the album
access::allow(identity::everybody(), "view", $album);
$this->assert_equal(1, ORM::factory("comment")->viewable()->where("comments.id", "=", $comment->id)->count_all());
// We can't see the comment when permissions are denied on the album
access::deny(identity::everybody(), "view", $album);
$this->assert_equal(0, ORM::factory("comment")->viewable()->where("comments.id", "=", $comment->id)->count_all());
}
示例9: setup
public function setup()
{
Input::instance()->ip_address = "1.1.1.1";
request::set_user_agent("Akismet_Helper_Test");
$root = ORM::factory("item", 1);
$this->_comment = comment::create($root, identity::guest(), "This is a comment", "John Doe", "john@gallery2.org", "http://gallery2.org");
foreach ($this->_comment->list_fields("comments") as $name => $field) {
if (strpos($name, "server_") === 0) {
$this->_comment->{$name} = substr($name, strlen("server_"));
}
}
$this->_comment->save();
module::set_var("akismet", "api_key", "TEST_KEY");
}
示例10: cant_view_comments_for_unviewable_items_test
public function cant_view_comments_for_unviewable_items_test()
{
$album = test::random_album();
$comment = ORM::factory("comment");
$comment->item_id = $album->id;
$comment->author_id = identity::admin_user()->id;
$comment->text = "text";
$comment->save();
identity::set_active_user(identity::guest());
// We can see the comment when permissions are granted on the album
access::allow(identity::everybody(), "view", $album);
$this->assert_true(ORM::factory("comment")->viewable()->where("comments.id", "=", $comment->id)->count_all());
// We can't see the comment when permissions are denied on the album
access::deny(identity::everybody(), "view", $album);
$this->assert_false(ORM::factory("comment")->viewable()->where("comments.id", "=", $comment->id)->count_all());
}
示例11: set_active_user
static function set_active_user($access_token)
{
if (empty($access_token)) {
identity::set_active_user(identity::guest());
return;
}
$key = ORM::factory("user_access_token")->where("access_key", "=", $access_token)->find();
if (!$key->loaded()) {
throw new Rest_Exception("Forbidden", 403);
}
$user = identity::lookup_user($key->user_id);
if (empty($user)) {
throw new Rest_Exception("Forbidden", 403);
}
identity::set_active_user($user);
}
示例12: post_fails_without_permissions_test
public function post_fails_without_permissions_test()
{
// We have to remove edit permissions from everywhere
Database::instance()->query("UPDATE {access_caches} SET edit_1=0");
identity::set_active_user(identity::guest());
try {
$request = new stdClass();
$request->params = new stdClass();
$request->params->name = "test tag";
tags_rest::post($request);
} catch (Exception $e) {
$this->assert_equal(403, $e->getCode());
return;
}
$this->assert_true(false, "Shouldnt get here");
}
示例13: illegal_access_test
public function illegal_access_test()
{
$album = test::random_album();
$photo = test::random_photo($album);
$album->reload();
access::deny(identity::everybody(), "view", $album);
identity::set_active_user(identity::guest());
$request = new stdClass();
$request->url = rest::url("data", $photo, "thumb");
$request->params = new stdClass();
$request->params->size = "thumb";
try {
data_rest::get($request);
$this->assert_true(false);
} catch (Kohana_404_Exception $e) {
// pass
}
}
示例14: _make_comment
private function _make_comment()
{
$comment = ORM::factory("comment");
$comment->item_id = item::root()->id;
$comment->author_id = identity::guest()->id;
$comment->text = "This is a comment";
$comment->guest_name = "John Doe";
$comment->guest_email = "john@gallery2.org";
$comment->guest_url = "http://gallery2.org";
$comment->save();
// Set the server fields to a known placeholder
foreach ($comment->list_fields("comments") as $name => $field) {
if (strpos($name, "server_") === 0) {
$comment->{$name} = substr($name, strlen("server_"));
}
}
return $comment->save();
}
示例15: set_active_user
static function set_active_user($access_key)
{
if (empty($access_key)) {
if (module::get_var("rest", "allow_guest_access")) {
identity::set_active_user(identity::guest());
return;
} else {
throw new Rest_Exception("Forbidden", 403);
}
}
$key = ORM::factory("user_access_key")->where("access_key", "=", $access_key)->find();
if (!$key->loaded()) {
throw new Rest_Exception("Forbidden", 403);
}
$user = identity::lookup_user($key->user_id);
if (empty($user)) {
throw new Rest_Exception("Forbidden", 403);
}
identity::set_active_user($user);
}