本文整理汇总了PHP中Captcha::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Captcha::instance方法的具体用法?PHP Captcha::instance怎么用?PHP Captcha::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Captcha
的用法示例。
在下文中一共展示了Captcha::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_register
public function action_register()
{
if (isset($_POST['submit'])) {
$data = Arr::extract($_POST, array('username', 'password', 'first_name', 'password_confirm', 'email', 'phone', 'address', 'country_id', 'zone_id', 'city_id', 'agree'));
$users = ORM::factory('user');
// $content->message = '';
// $content->message = Captcha::valid($_POST['captcha'])? 'Не угадал';
try {
$regdate = date("Y-M-D");
$users->create_user($_POST, array('username', 'first_name', 'password', 'email', 'phone', 'address', 'country_id', 'zone_id', 'city_id', 'regdate' => $regdate));
$role = ORM::factory('role', array('name' => 'login'));
$users->add('roles', $role);
// $users->add('roles', 1);
$email = Email::factory('Регистрация на сайте', 'Регистрация на сайте успешно завешена')->to($data['email'], $data['first_name'])->from('admin@mykohana.loc', 'mykohan')->send();
$this->action_login();
$this->request->redirect('account');
// $this->reg_ok = "<p><b>Ваш профил успешно созданно</b></p>";
$this->action_login();
$this->request->redirect('account');
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors('user');
}
}
$captcha = Captcha::instance();
$captcha_image = $captcha->render();
$country = ORM::factory('country')->find_all();
$zones = ORM::factory('zone')->where('country_id', '=', 176)->find_all();
$form_register = View::factory('v_registration', array('country' => $country, 'zones' => $zones))->bind('errors', $errors)->bind('data', $data)->bind('captcha_image', $captcha_image);
// Выводим в шаблон
$this->template->title = 'Регистрация';
$this->template->page_title = 'Регистрация новога пользователя';
$this->template->block_center = array('form_register' => $form_register);
}
示例2: action_login
public function action_login()
{
$captcha = Captcha::instance();
$this->template->captcha = $captcha;
$this->template->message = '';
if (Auth::instance()->logged_in()) {
$this->redirect('/');
}
$username = Arr::get($_POST, 'username', '');
$password = Arr::get($_POST, 'password', '');
$remember = (bool) Arr::get($_POST, 'remember', false);
$error = false;
$message = false;
if ($this->request->method() == Request::POST) {
$cpt = Captcha::valid($_POST['captcha']);
if ($cpt) {
if (Auth::instance()->login($username, $password, $remember)) {
$this->redirect('manage');
} else {
$error = true;
//$this->set('error', true);
}
} else {
$message = true;
//$this->set('error', true);
}
}
$this->set('username', $username)->set('remember', $remember ? 'checked' : '')->set('error', $error)->set('message', $message);
}
示例3: action_register
public function action_register()
{
//check user logged in or not
if (Auth::instance()->logged_in()) {
Request::instance()->redirect('/');
//go to home page
}
$captcha = Captcha::instance('login');
if (Request::$method == "POST") {
if (Captcha::valid($_POST['captcha'])) {
$user = new User();
$post = $user->validate_register($_POST);
if ($post->check()) {
$post = $post->as_array();
$user->email = $post['email'];
$user->username = $post['username'];
$user->active = false;
$user->sex = $post['sex'];
$user->active_code = md5(time());
$user->save();
Session::set('reg_email', $user->email);
Request::instance()->redirect('/site/register_done');
} else {
$_POST = $post->as_array();
$data['errors'] = $post->errors();
}
} else {
$data['errors'] = array('captcha' => 'Mã bảo mật không đúng!');
}
}
$this->template->title = __('Đăng ký tài khoản');
$data['captcha'] = $captcha;
$this->template->content = View::factory('frontend/site/register', $data);
}
示例4: action_index
/**
* Output the captcha challenge
*
* @param string $group Config group name
*/
public function action_index($group = 'default')
{
// Output the Captcha challenge resource (no html)
// Pull the config group name from the URL
$captcha = Captcha::instance($group)->render(FALSE);
$this->request->headers['Content-Type'] = File::mime($captcha);
$this->request->headers['Content-length'] = filesize($captcha);
$this->request->response = $captcha;
}
示例5: instance
public static function instance($group = 'alpha')
{
if (!isset(Captcha::$instance)) {
$config = Kohana::config('captcha');
Captcha::$config = $config;
//$style = $config['style'];
$class = 'Captcha_' . ucfirst($group);
Captcha::$instance = new $class($config);
}
return Captcha::$instance;
}
示例6: action_index
public function action_index($options = array())
{
Resources::add_scripts(array("js/classes/LexComments.js", "js/modules/comments/comments.js"), get_class());
Resources::add_styles(array("css/modules/comments/default.less"), get_class());
$model = array();
$model["captcha"] = Captcha::instance()->render();
$model["comments"] = array();
$model["comments"][] = array("name" => "lexa4ok", "comment" => "test1");
$model["comments"][] = array("name" => "lexa4ok2", "comment" => "test2");
$this->set_template("/widgets/comments/default.php", "twig")->render($model)->body();
}
示例7: action_default
/**
* Output the captcha challenge
*
* @param string $group Config group name
*/
public function action_default($group = 'default')
{
// Output the Captcha challenge resource (no html)
// Pull the config group name from the URL
$captcha = Captcha::instance($group)->render(FALSE);
$this->request->headers['Content-Type'] = File::mime($captcha);
// The necessity of this header is questionable and causes problems in Safari and other WebKit browsers.
// Uncomment at your own peril, scheduled for removal unless a case can be made to keep it.
//$this->request->headers['Content-Length'] = filesize($captcha);
$this->request->headers['Connection'] = 'close';
$this->request->response = $captcha;
}
示例8: getCaptcha
/**
* The function returns Captcha object.
*
* @static
* @access public
* @return object The Captcha.
*/
public static function getCaptcha()
{
if (self::$instance === null) {
include_once Runtime::get('LIBS_DIR') . '/secureimage/securimage.php';
self::$instance = new Securimage();
self::$instance->code_length = 4;
self::$instance->image_width = 80;
self::$instance->shadow_text = true;
self::$instance->line_color = '#3399ee';
self::$instance->arc_line_colors = '#3399ee';
self::$instance->text_color = '#1177cc';
}
return self::$instance;
}
示例9: action_signin
public function action_signin()
{
//echo Auth::instance()->hash_password('hungxalo');
#If user already signed-in
if (Auth::instance()->logged_in() != 0) {
#redirect to the user account
Request::instance()->redirect('admin/site/index');
}
$captcha = Captcha::instance();
$data = array();
$data['captcha'] = $captcha;
#If there is a post and $_POST is not empty
if ($_POST) {
//print_r($_POST);
if (Captcha::valid($_POST['captcha'])) {
#Instantiate a new user
$array = Validate::factory($_POST)->rules('email', array('not_empty' => NULL, 'min_length' => array(4), 'max_length' => array(127), 'email' => NULL))->rules('password', array('not_empty' => null))->filter(TRUE, 'trim');
// Get the remember login option
$remember = isset($array['remember']);
// Login starts out invalid
$status = FALSE;
if ($array->check()) {
$user = Auth::instance();
#Check Auth
$status = $user->login($array['email'], $array['password'], $remember);
#If the post data validates using the rules setup in the user model
if ($status) {
#redirect to the user account
Request::instance()->redirect('admin/site/index');
} else {
$array->error('email', 'username_available');
#Get errors for display in view
$data['errors'] = $array->errors('admin/login');
}
} else {
$data['errors'] = $array->errors('admin/login');
}
} else {
$data['errors'] = array('captcha' => 'Captcha invalid!');
}
// Captcha::invalid_count()
//echo $captcha->invalid_count();
}
$this->template->title = "Đăng nhập vào hệ thống";
$this->template->section_title = "Đăng nhập vào hệ thống";
$this->template->content = View::factory('/admin/site/login', $data);
}
示例10: action_mail
/**
* Sending mails
*
* @since 1.0.0 First time this method was introduced
* @since 1.1.0 Added jQuery Textarea Characters Counter Plugin
*
* @link http://roy-jin.appspot.com/jsp/textareaCounter.jsp
*
* @uses Request::query
* @uses Route::get
* @uses Route::uri
* @uses URL::query
* @uses URL::site
* @uses Validation::rule
* @uses Config::get
* @uses Config::load
* @uses Assets::js
*/
public function action_mail()
{
$this->title = __('Contact us');
$config = Config::load('contact');
Assets::js('textareaCounter', 'media/js/jquery.textareaCounter.plugin.js', array('jquery'), FALSE, array('weight' => 10));
Assets::js('greet/form', 'media/js/greet.form.js', array('textareaCounter'), FALSE, array('weight' => 15));
//Add schema.org support
$this->schemaType = 'ContactPage';
// Set form destination
$destination = !is_null($this->request->query('destination')) ? array('destination' => $this->request->query('destination')) : array();
// Set form action
$action = Route::get('contact')->uri(array('action' => $this->request->action())) . URL::query($destination);
// Get user
$user = User::active_user();
// Set mail types
$types = $config->get('types', array());
$view = View::factory('contact/form')->set('destination', $destination)->set('action', $action)->set('config', $config)->set('types', $types)->set('user', $user)->bind('post', $post)->bind('errors', $this->_errors);
// Initiate Captcha
if ($config->get('use_captcha', FALSE) and !$this->_auth->logged_in()) {
$captcha = Captcha::instance();
$view->set('captcha', $captcha);
}
if ($this->valid_post('contact')) {
$post = Validation_Contact::factory($this->request->post());
if ($post->check()) {
// Create the email subject
$subject = __('[:category] :subject', array(':category' => $types[$post['category']], ':subject' => Text::plain($post['subject'])));
// Create the email body
$body = View::factory('email/contact')->set('name', $post['name'])->set('body', $post['body'])->set('config', Config::load('site'))->render();
// Create an email message
$email = Email::factory()->to(Text::plain($this->_config->get('site_email', 'webmaster@gleezcms.org')), __('Webmaster :site', array(':site' => Template::getSiteName())))->subject($subject)->from($post['email'], Text::plain($post['name']))->message($body, 'text/html');
// @todo message type should be configurable
// Send the message
$email->send();
Log::info(':name sent an e-mail regarding :cat', array(':name' => Text::plain($post['name']), ':cat' => $types[$post['category']]));
Message::success(__('Your message has been sent.'));
// Always redirect after a successful POST to prevent refresh warnings
$this->request->redirect(Route::get('contact')->uri(), 200);
} else {
$this->_errors = $post->errors('contact', TRUE);
}
}
$this->response->body($view);
}
示例11: action_register
/**
* Register a new user
*
* @uses Auth::logged_in
* @uses Auth::instance
* @uses Auth::login
* @uses Request::redirect
* @uses Request::action
* @uses Route::get
* @uses Route::uri
* @uses Config::get
* @uses Captcha::instance
* @uses Message::success
*
* @throws HTTP_Exception_403
*/
public function action_register()
{
// set the template title (see Template for implementation)
$this->title = __('User Registration');
// If user already signed-in
if ($this->_auth->logged_in()) {
// redirect to the user account
$this->request->redirect(Route::get('user')->uri(array('action' => 'profile')), 200);
}
/** @var $post Model_User */
$post = ORM::factory('user');
/** @var $config Config_Group */
$config = Config::load('auth');
if (!$config->register) {
// If user registration disabled, we return access denied.
throw HTTP_Exception::factory(403, __('User registration not allowed'));
}
$action = Route::get('user')->uri(array('action' => $this->request->action()));
$male = (isset($post->gender) and $post->gender == 1) ? TRUE : FALSE;
$female = (isset($post->gender) and $post->gender == 2) ? TRUE : FALSE;
// Load the view
$view = View::factory('user/register')->set('config', $config)->set('action', $action)->set('post', $post)->bind('male', $male)->bind('female', $female)->bind('errors', $this->_errors);
if ($config->get('use_captcha', FALSE)) {
$captcha = Captcha::instance();
$view->set('captcha', $captcha);
}
// If there is a post and $_POST is not empty
if ($this->valid_post('register')) {
try {
// creating user, adding roles and sending verification mail
$form = $this->request->post();
$post->signup($form);
// sign the user in
Auth::instance()->login($post->name, $post->pass);
Log::info('Account :title created successful.', array(':title' => $post->nick));
Message::success(__('Account %title created successful!', array('%title' => $post->nick)));
$this->request->redirect(Route::get('user')->uri(array('action' => 'profile')));
} catch (ORM_Validation_Exception $e) {
$this->_errors = $e->errors('models', TRUE);
}
}
$this->response->body($view);
}
示例12: form
public static function form($controller, $item, $_action = FALSE, $captcha = FALSE)
{
// Set default comment form action
$action = Request::current()->uri();
$view = View::factory('comment/form')->set('use_captcha', $captcha)->set('action', $action)->set('is_edit', FALSE)->set('auth', Auth::instance())->set('destination', array())->set('item', $item)->bind('errors', $errors)->bind('post', $post);
// Set form action either from model or action param
if ($item->url) {
$action = (string) $item->url;
} elseif ($_action) {
$action = $_action;
}
// Set if captcha necessary
if ($captcha) {
$captcha = Captcha::instance();
$view->set('captcha', $captcha);
}
// Load the comment model
$post = ORM::factory('comment');
if ($controller->valid_post('comment')) {
$values = Arr::merge(array('post_id' => $item->id, 'type' => $item->type), $_POST);
try {
$post->values($values)->save();
if ($post->status != 'publish') {
Message::success(__('Your comment has been queued for review by site administrators and will be published after approval.'));
} else {
Message::success(__('Your comment has been posted.', array(':title' => $post->title)));
}
// Save the anonymous user information to a cookie for reuse.
if (User::is_guest()) {
User::cookie_save(array('name' => $post->guest_name, 'email' => $post->guest_email, 'url' => $post->guest_url));
}
Log::info('Comment: :title has posted.', array(':title' => $post->title));
// Redirect to post page
$controller->request->redirect(Request::current()->uri());
} catch (ORM_Validation_Exception $e) {
// @todo Add messages
$errors = $e->errors('models', TRUE);
}
}
return $view;
}
示例13: action_index
public function action_index()
{
$template = View::factory("template");
$content = View::factory("registration");
$captcha = Captcha::instance();
$root_page = "registration";
$template->root_page = $root_page;
$username = Arr::get($_POST, 'username', '');
$email = Arr::get($_POST, 'email', '');
$phone = Arr::get($_POST, 'username', '');
$name = Arr::get($_POST, 'name', '');
$content->username = $username;
$content->email = $email;
$content->phone = $phone;
$content->name = $name;
$content->error = "";
$content->captcha = $captcha;
if (!Auth::instance()->logged_in()) {
if (isset($_POST['reg'])) {
if (Arr::get($_POST, 'username', '') == "") {
$error = View::factory('error');
$error->zag = "Не указан логин!";
$error->mess = " Укажите Ваш логин.";
$content->error = $error;
} else {
if (Arr::get($_POST, 'email', '') == "") {
$error = View::factory('error');
$error->zag = "Не указана почта!";
$error->mess = " Укажите Вашу почту.";
$content->error = $error;
} else {
if (Arr::get($_POST, 'password', '') == "") {
$error = View::factory('error');
$error->zag = "Не указан пароль!";
$error->mess = " Укажите Ваш пароль.";
$content->error = $error;
} else {
if (Arr::get($_POST, 'password', '') != Arr::get($_POST, 'password2', '')) {
$error = View::factory('error');
$error->zag = "Пароли не совпадают!";
$error->mess = " Проверьте правильность подтверждения пароля.";
$content->error = $error;
} else {
if (!Captcha::valid($_POST['checkcode'])) {
$error = View::factory('error');
$error->zag = "Контрольный текст не совпадает!";
$error->mess = " Укажите правильно контрольный текст.";
$content->error = $error;
} else {
if (strlen(preg_replace("/[^0-9]+/i", "", $_POST['username'])) != 11) {
$error = View::factory('error');
$error->zag = "Некорректный номер телефона!";
$error->mess = " Укажите правильно номер телефона.";
$content->error = $error;
} else {
$user = ORM::factory('User');
$user->values(array('username' => $_POST['username'], 'email' => $_POST['email'], 'password' => $_POST['password'], 'password_confirm' => $_POST['password2']));
$some_error = false;
try {
$user->save();
$user->add("roles", ORM::factory("Role", 1));
} catch (ORM_Validation_Exception $e) {
$some_error = $e->errors('models');
}
if ($some_error) {
$error = View::factory('error');
$error->zag = "Ошибка регистрационных данных!";
$error->mess = " Проверьте правильность ввода данных.";
if (isset($some_error['username'])) {
if ($some_error['username'] == "models/user.username.unique") {
$error->zag = "Такое имя уже есть в базе!";
$error->mess = " Придумайте новое.";
}
} else {
if (isset($some_error['email'])) {
if ($some_error['email'] == "email address must be an email address") {
$error->zag = "Некорректный формат почты!";
$error->mess = " Проверьте правильность написания почты.";
}
if ($some_error['email'] == "models/user.email.unique") {
$error->zag = "Такая почта есть в базе!";
$error->mess = " Укажите другую почту.";
}
}
}
$content->error = $error;
} else {
Auth::instance()->login($_POST['username'], $_POST['password'], true);
Model::factory("Users")->addNewUser($_POST);
$to = $_POST['email'];
$subj_tpl = View::factory('register_subject');
$body_tpl = View::factory('register_body');
$subject = $subj_tpl->render();
$from = 'site@teleantenna25.ru';
$body_tpl->login = $_POST['username'];
$body_tpl->password = $_POST['password'];
$message = $body_tpl->render();
$bound = "0";
$header = "From: Teleantenna25.ru<site@teleantenna25.ru>\r\n";
$header .= "Subject: {$subject}\n";
//.........这里部分代码省略.........
示例14: after
public function after()
{
Captcha::instance($this->group)->update_response_session();
}
示例15: action_imgcode
/**
* 图片验证码
*
*/
public function action_imgcode()
{
$captcha = Captcha::instance();
exit($captcha->render());
}