Esempio n. 1
0
 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('*****@*****.**', '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);
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 /**
  * 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;
 }
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
 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();
 }
Esempio n. 7
0
 /**
  * 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;
 }
Esempio n. 8
0
 /**
  * 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;
 }
Esempio n. 9
0
 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);
 }
Esempio n. 10
0
 /**
  * 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 :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);
 }
Esempio n. 11
0
 /**
  * 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);
 }
Esempio n. 12
0
 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;
 }
Esempio n. 13
0
 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 = '*****@*****.**';
                                         $body_tpl->login = $_POST['username'];
                                         $body_tpl->password = $_POST['password'];
                                         $message = $body_tpl->render();
                                         $bound = "0";
                                         $header = "From: Teleantenna25.ru<*****@*****.**>\r\n";
                                         $header .= "Subject: {$subject}\n";
                                         $header .= "Mime-Version: 1.0\n";
                                         $header .= "Content-Type: multipart/mixed; boundary=\"{$bound}\"";
                                         $body = "\n\n--{$bound}\n";
                                         $body .= "Content-type: text/html; charset=\"utf-8\"\n";
                                         $body .= "Content-Transfer-Encoding: quoted-printable\n\n";
                                         $body .= "{$message}";
                                         $result = false;
                                         if (mail($to, $subject, $body, $header)) {
                                             $result = true;
                                         }
                                         if ($result) {
                                             $site_result = $result;
                                             $content = View::factory('alert_success');
                                             $content->zag = "Вы успешно зарегистрированы! ";
                                             $content->mess = "";
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $template->content = $content;
     $this->response->body($template);
 }
Esempio n. 14
0
 public function after()
 {
     Captcha::instance($this->group)->update_response_session();
 }
Esempio n. 15
0
 /**
  * 图片验证码
  *
  */
 public function action_imgcode()
 {
     $captcha = Captcha::instance();
     exit($captcha->render());
 }
Esempio n. 16
0
 public function action_index()
 {
     //смотрим шаблон для виджета
     $id = $this->request->param('id');
     $widget = new Model_Widget();
     $template = $widget->getTempalte('callback', $id);
     if ($template) {
         $this->template = View::factory('widgets/' . $template);
     }
     if (isset($_POST['callback-order'])) {
         if (Captcha::valid(Arr::get($_POST, 'comm-captcha'))) {
             $base = new Model_Base();
             $options = $base->getOptions();
             $vData = $_POST;
             $validation = Validation::factory($vData);
             $validation->rule('cb-name', 'not_empty');
             $validation->rule('cb-name', 'min_length', array(':value', '2'));
             $validation->rule('cb-name', 'max_length', array(':value', '250'));
             $validation->rule('cb-phone', 'not_empty');
             $validation->rule('cb-phone', 'phone');
             $validation->rule('cb-phone', 'min_length', array(':value', '6'));
             $validation->rule('cb-phone', 'max_length', array(':value', '15'));
             if (!$validation->check()) {
                 $this->errors = $validation->errors('callbackErrors');
             } else {
                 $name = Arr::get($_POST, 'cb-name', '');
                 $phone = Arr::get($_POST, 'cb-phone', '');
                 //отправляем письмо
                 $config = Kohana::$config->load('email');
                 Email::connect($config);
                 $to = $config['options']['callback_email'];
                 //$to = '*****@*****.**';
                 $subject = 'Поступила заявка с сайта ' . $options['sitename'] . ' от ' . $name . '';
                 $from = $config['options']['username'];
                 $message = '<h2>Новая заявка</h2>';
                 $message .= 'Отправитель: <b>' . $name . ', </b><br>';
                 $message .= 'Тел: <b>' . $phone . ', </b><br>';
                 $message .= '<em>Отправлено: ' . date("G:i:s M j Y") . '</em>';
                 Email::send($to, $from, $subject, $message, $html = TRUE);
                 if (count($this->errors) > 0) {
                     $base = new Model_Base();
                     $options = $base->getOptions();
                     $to = $options['admin_email'];
                     $subject = 'Ошибки на сайте ' . $options['sitename'];
                     $from = $config['options']['username'];
                     foreach ($this->errors as $error) {
                         $message = '<h2>Ошибка</h2>';
                         $message .= $error;
                         $message .= ' <em>Отправлено: ' . date("G:i:s M j Y") . '</em>';
                     }
                     Email::send($to, $from, $subject, $message, $html = TRUE);
                 } else {
                     $this->messages[] = 'Спасибо! Ваш вопрос успешно отправлен.';
                 }
             }
         } else {
             $this->errors['captcha'] = "Код введен неверно";
         }
     }
     $captcha_image = Captcha::instance()->render();
     $this->template->captcha = $captcha_image;
     $this->template->errors = $this->errors;
     $this->template->messages = $this->messages;
 }
Esempio n. 17
0
		</dd>
	</dl>
	<dl>
		<dt><?php 
echo form::label('password_confirm', 'Confirm password:'******'password_confirm', $post['password_confirm'], array('maxlength' => 20));
?>
</dd>
	</dl>
	
	<dl>
		<dt><?php 
echo Captcha::instance()->render();
?>
</dt>
		<dd><?php 
echo form::input('captcha', $post['captcha']);
?>
<br /><?php 
echo __('Type the characters you see in the picture.');
?>
</dd>
	</dl>
	
	<dl>
		<dt>&nbsp;</dt>
		<dd><?php 
echo form::label('tos', __(':checkbox I have read and agrees to the :tos', array(':checkbox' => form::checkbox('tos', 'yes'), ':tos' => html::anchor('account/tos', 'Terms of Service', array('target' => '_blank')))));
Esempio n. 18
0
 /**
  * Validates user's Captcha response and updates response counter.
  *
  * @staticvar integer $counted Captcha attempts counter
  * @param string $response User's captcha response
  * @return boolean
  */
 public static function valid($response)
 {
     // Maximum one count per page load
     static $counted;
     // User has been promoted, always TRUE and don't count anymore
     if (Captcha::instance()->promoted()) {
         return TRUE;
     }
     // Challenge result
     $result = (bool) (sha1(strtoupper($response)) === Session::instance()->get('captcha_response'));
     // Increment response counter
     if ($counted !== TRUE) {
         $counted = TRUE;
         // Valid response
         if ($result === TRUE) {
             Captcha::instance()->valid_count(Session::instance()->get('captcha_valid_count') + 1);
         } else {
             Captcha::instance()->invalid_count(Session::instance()->get('captcha_invalid_count') + 1);
         }
     }
     return $result;
 }
Esempio n. 19
0
 public function black()
 {
     $config = array('style' => 'black', 'width' => 100, 'height' => 50, 'complexity' => 4);
     $captcha = Captcha::instance('black');
     $captcha->render();
 }
Esempio n. 20
0
 /**
  * Edit blog post
  *
  * @uses    ACL::post
  * @uses    Gleez_Config::load
  * @uses    Request::query
  * @uses    Request::redirect
  * @uses    Route::get
  * @uses    Route::uri
  * @uses    URL::query
  * @uses    Tags::implode
  * @uses    Date::date_time
  * @uses    Path::load
  * @uses    Message::success
  * @uses    Log::add
  * @throws  HTTP_Exception_403
  */
 public function action_edit()
 {
     $id = (int) $this->request->param('id', 0);
     $post = ORM::factory('blog', $id);
     if (!ACL::post('edit', $post)) {
         // If the post was not loaded, we return access denied.
         throw HTTP_Exception::factory(403, 'Access denied!');
     }
     $this->title = $post->title;
     $config = Config::load('blog');
     // Set form destination
     $destination = !is_null($this->request->query('destination')) ? array('destination' => $this->request->query('destination')) : array();
     // Set form action
     $action = Route::get('blog')->uri(array('id' => $id, 'action' => 'edit')) . URL::query($destination);
     $view = View::factory('blog/form')->set('destination', $destination)->set('action', $action)->set('config', $config)->set('path', FALSE)->set('created', $post->created)->set('author', $post->user->name)->set('tags', Tags::implode($post->tags_form))->set('image', FALSE)->bind('errors', $this->_errors)->bind('terms', $terms)->bind('blog', $post);
     if ($config->get('use_captcha', FALSE)) {
         $captcha = Captcha::instance();
         $view->set('captcha', $captcha);
     }
     if ($path = Path::load($post->rawurl)) {
         $view->set('path', $path['alias']);
     }
     if ($config->get('use_category', FALSE)) {
         $terms = ORM::factory('term', array('type' => 'blog', 'lvl' => 1))->select_list('id', 'name', '--');
     }
     if ($config->get('primary_image', FALSE)) {
         $image = $post->image;
     }
     if ($this->valid_post('blog')) {
         try {
             $post->values($_POST)->save();
             Log::info('Blog :title updated.', array(':title' => $post->title));
             Message::success(__('Blog %title updated', array('%title' => $post->title)));
             $this->request->redirect(empty($destination) ? $post->url : $this->request->query('destination'));
         } catch (ORM_Validation_Exception $e) {
             // @todo Add messages
             $this->_errors = $e->errors('models', TRUE);
         }
     }
     $this->_tabs = array(array('link' => $post->url, 'text' => __('View')), array('link' => $post->edit_url, 'text' => __('Edit')));
     if (ACL::post('delete', $post)) {
         $this->_tabs[] = array('link' => $post->delete_url, 'text' => __('Delete'));
     }
     $this->response->body($view);
 }
Esempio n. 21
0
 public function action_login()
 {
     if (HTTP_Request::POST == $this->request->method() && Security::check(Arr::get($this->request->post(), 'csrf', '')) && Captcha::valid($_POST['captcha'])) {
         $remember = array_key_exists('remember', $this->request->post()) ? (bool) $this->request->post('remember') : FALSE;
         $user = Auth::instance()->login($this->request->post('username'), $this->request->post('password'), $remember);
         if ($user) {
             HTTP::redirect($this->config->get('admin_url'));
         } else {
             Session::instance()->set('error', 'Логин или пароль не верный');
             $errors = array('Логин или пароль не верный.');
         }
     }
     $this->template = 'login';
     parent::before();
     $captcha = Captcha::instance();
     $csrf = Security::token(true);
     $this->template->title = 'Вход в админ панель';
     $this->template->bind('errors', $errors)->bind('csrf', $csrf)->bind('captcha', $captcha);
     $errors = null;
     if (Auth::instance()->get_user()) {
         $auth = Auth::instance();
         $has_admin_role = $auth->logged_in('admin');
         if ($has_admin_role) {
             $session = Session::instance();
             $session->set('redirectAfterLogin', $_SERVER['REQUEST_URI']);
             HTTP::redirect('/' . $this->admin_url . '/');
         }
     }
 }
Esempio n. 22
0
 /**
  * add book
  */
 public function action_addguest()
 {
     $data = array('msg' => '');
     $captcha = Captcha::instance('default');
     $session = Session::instance();
     $data['page'] = $session->get("page", '');
     if (isset($_POST['btnSubmit'])) {
         $book = new Model_Guestbook();
         if (Captcha::valid($_POST['captcha'])) {
             if ($book->insBook()) {
                 $data['msg'] = 'Запись добавлена';
             } else {
                 $data['msg'] = 'Запись не добавлена';
             }
         } else {
             $data['msg'] = 'Капча не верна';
         }
     }
     $content = View::factory('addguestview');
     $content->captcha = $captcha;
     $content->bind('data', $data);
     $this->template->content = $content;
 }
Esempio n. 23
0
 /**
  * Validates user's Captcha response and updates response counter.
  *
  * @staticvar integer $counted Captcha attempts counter
  * @param string $response User's captcha response
  * @return boolean
  */
 public static function valid($response)
 {
     // Maximum one count per page load
     static $counted;
     // User has been promoted, always TRUE and don't count anymore
     if (Captcha::instance()->promoted()) {
         return TRUE;
     }
     // Challenge result
     //	var_dump(Session::instance()->get('captcha_response'));
     //die();
     $result = (bool) (sha1(strtoupper($response)) === Session::instance()->get('captcha_response'));
     //error_log("END: ".$response ."\t\n".  sha1(strtoupper($response)) ."\t\n".
     //Session::instance()->get('captcha_response')
     //."\t\n" . (int)$result
     //."\t\n\n", 3 , '/tmp/abc.log');
     // Increment response counter
     if ($counted !== TRUE) {
         $counted = TRUE;
         // Valid response
         if ($result === TRUE) {
             Captcha::instance()->valid_count(Session::instance()->get('captcha_valid_count') + 1);
         } else {
             Captcha::instance()->invalid_count(Session::instance()->get('captcha_invalid_count') + 1);
         }
     }
     return $result;
 }
Esempio n. 24
0
 public function action_index($group = 'default')
 {
     // Output the Captcha challenge resource (no html)
     // Pull the config group name from the URL
     $this->request->response = Captcha::instance($group)->render(FALSE);
 }
Esempio n. 25
0
 /**
  * Singleton instance of Captcha.
  *
  * @param string $group Config group name
  *
  * @return object
  */
 public static function instance($group = 'default')
 {
     if (!isset(Captcha::$instance)) {
         // Load the configuration for this group
         $config = Kohana::$config->load('captcha')->get($group);
         // Set the captcha driver class name
         $class = 'Captcha_' . ucfirst($config['style']);
         // Create a new captcha instance
         Captcha::$instance = $captcha = new $class($group);
         // Save captcha response at shutdown
         //register_shutdown_function(array($captcha, 'update_response_session'));
     }
     return Captcha::$instance;
 }
Esempio n. 26
0
 /**
  * 图形验证码
  */
 public function action_imgcode()
 {
     echo $captcha = Captcha::instance();
     $this->auto_render = false;
 }
Esempio n. 27
0
<?php

echo form::open('order', array('method' => 'post'));
echo '<table align="center">';
echo '<tr valign="top"><td><b>ФИО:</b></td><td>' . form::input('fio') . '</td></tr>';
echo '<tr valign="top"><td><b>Адрес:</b></td><td>' . form::input('address') . '</td></tr>';
echo '<tr valign="top"><td><b>Телефон:</b> +38</td><td>' . form::input('phone') . ' <br><font size="1"><i>Напр.</i> 0501234567,<br>без пробелов, скобок и тире</font></td></tr>';
echo '<tr valign="top"><td><b>EMail:</b></td><td>' . form::input('email') . '</td></tr>';
echo '<tr valign="top"><td>' . Captcha::instance()->render() . '</td><td valign="top">' . form::input('captcha', '', array('style' => 'width: 143px; height: 48px; font-size: 50px;')) . '</td></tr>';
echo '<tr valign="top"><td colspan="2" align="center">' . form::submit('submit', 'Отправить заказ') . '</td></tr>';
echo '</table>';
echo form::close();
if (!empty($err)) {
    echo $err;
}