本文整理汇总了PHP中Captcha::valid方法的典型用法代码示例。如果您正苦于以下问题:PHP Captcha::valid方法的具体用法?PHP Captcha::valid怎么用?PHP Captcha::valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Captcha
的用法示例。
在下文中一共展示了Captcha::valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_login
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 . '/');
}
}
}
示例2: 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);
}
示例3: 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);
}
示例4: action_index
function action_index()
{
// Check if already logged in
if ($this->admin->islogged() === TRUE) {
$this->template->content = $this->admin->genpage();
} else {
$this->template->content = $this->admin->showlogin();
}
// Check if login data sended
if (isset($_POST['login']) and isset($_POST['password']) and isset($_POST['captcha'])) {
if (Captcha::valid($_POST['captcha'])) {
// Check auth
$auth = $this->admin->checklogin();
if ($auth === TRUE) {
Session::instance()->set('islogged', 'on');
$this->request->redirect('admin');
} else {
if (gettype($auth) == 'string') {
$this->template->err = $auth;
}
}
} else {
$this->template->err = 'Неверно введена капча';
}
}
}
示例5: action_doreg
public function action_doreg()
{
$mobile = Arr::get($_POST, 'mobile');
$pwd = Arr::get($_POST, 'password');
$checkcode = Arr::get($_POST, 'checkcode');
$backurl = Arr::get($_POST, 'backurl');
//验证码
$checkcode = strtolower($checkcode);
$flag = Model_Member::checkExist('mobile', $mobile);
if (!$flag) {
Common::showMsg('手机号码重复,请重新填写', '-1');
}
if (!Captcha::valid($checkcode)) {
Common::showMsg('验证码错误', '-1');
}
$model = ORM::factory('member');
$model->mobile = $mobile;
$model->pwd = md5($pwd);
$model->logintime = time();
$model->nickname = substr_replace($mobile, '***', 3, 3);
$model->save();
if ($model->saved()) {
Model_Member::login($mobile, $pwd);
Common::showMsg('注册成功', $backurl);
} else {
//Common::showMsg('注册失败,请联系网站管理员','-1');
}
}
示例6: action_register
public function action_register()
{
if (!empty($_POST)) {
$username = Arr::get($_POST, 'username');
$password = Arr::get($_POST, 'password');
$password2 = Arr::get($_POST, 'password2');
$vcode = Arr::get($_POST, 'vcode');
if ($password !== $password2) {
exit('两次密码不匹配');
}
if (!Captcha::valid($vcode)) {
exit('验证码错误');
}
$auth = Auth::instance('member');
$password = $auth->hash($password);
$user_data = array('username' => $username, 'password' => $password, 'created_at' => time());
$m_member = Model::factory('member', 'admin');
$user_exist = $m_member->has(array('username' => $username));
if (!$user_exist) {
$ret = $m_member->insert($user_data);
if ($ret !== false) {
$user_data['id'] = $ret[0];
if ($auth->force_login($user_data)) {
$this->redirect(Request::$referrer);
}
} else {
exit('注册失败');
}
} else {
exit('用户名已存在');
}
}
$this->content = View::factory('common/user_register');
}
示例7: rule_captcha
protected function rule_captcha()
{
if ($this->value === '' or $this->value === NULL) {
$this->errors['required'] = TRUE;
} elseif (Captcha::valid($this->value, $this->group) == FALSE) {
$this->errors['captcha'] = TRUE;
}
}
示例8: validate_this
protected function validate_this()
{
// use Captcha's buit-in validation
if (!Captcha::valid(Input::instance()->post($this->name))) {
$this->error = $this->error_msg;
return $this->error;
}
}
示例9: action_login
function action_login()
{
if ($_POST) {
if (Captcha::valid($_POST['captcha']) and $this->auth->login($_POST['username'], $_POST['password'], !empty($_POST['remember']) ? TRUE : FALSE) == TRUE) {
$this->request->redirect('admin');
} else {
$this->request->redirect('admin');
}
}
}
示例10: index
/**
* The default action - show the home page
*/
public function index()
{
if ($this->request->isPost()) {
var_dump(Captcha::valid($this->request->getParam('vcode')));
} else {
//echo '<p><img src="' . $this->getBaseUrl(). 'captcha/basic"></p>';
echo '<p><img src="' . $this->getBaseUrl() . 'captcha/alpha"></p>';
//echo '<p><img src="' . $this->getBaseUrl(). 'captcha/black"></p>';
echo '<form method="post"><input type="text" name="vcode"><input type="submit" value="Valid"></form>';
}
exit;
}
示例11: 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);
}
示例12: page1
public function page1()
{
$view = new View('signup/page1');
// Load Captcha library, you can supply the name of the config group you would like to use.
$captcha = new Captcha();
// Form info
$form = array('username' => '', 'password' => '', 'password_confirm' => '', 'email' => '');
// copy the form as errors, so the errors will be stored with keys corresponding to the form field names
$errors = $form;
// Ban bots (that accept session cookies) after 50 invalid responses.
// Be careful not to ban real people though! Set the threshold high enough.
if ($captcha->invalid_count() > 49) {
exit('Bye! Stupid bot.');
}
// Form submitted
if ($_POST) {
// Add some rules, the input field, followed by a list of checks, carried out in order
$valid_c = Captcha::valid($this->input->post('captcha_response'));
$this->user = ORM::factory('user');
$post = $this->input->post();
if ($this->user->validate($post) && $valid_c) {
$this->user->save();
$this->session->set('uid', $this->user->id);
$this->user->add(ORM::factory('role', 'login'));
$this->auth->login($this->user, $post['password']);
url::redirect('/signup/page2');
exit(0);
} else {
// repopulate the form fields
$form = arr::overwrite($form, $post->as_array());
$errors = arr::overwrite($errors, $post->errors('signup_errors'));
if (!$valid_c) {
$errors['captcha_response'] = "Invalid";
}
}
}
// Put the vars in the template
$view->set("errors", $errors);
$this->template->content = $view;
$this->template->content->captcha = $captcha;
$this->template->content->form = $form;
}
示例13: action_ajax_login
public function action_ajax_login()
{
$checkcode = Arr::get($_POST, 'checkcode');
$username = Arr::get($_POST, 'username');
$password = Arr::get($_POST, 'password');
$out = array();
//验证码
$checkcode = strtolower($checkcode);
if (!Captcha::valid($checkcode)) {
$out['status'] = 'checkcode_err';
echo json_encode($out);
exit;
}
//用户名密码验证
$password = md5($password);
$userinfo = ORM::factory('admin')->where("username='{$username}' and password='{$password}'")->find();
if (!$userinfo->loaded()) {
$out['status'] = 'password_err';
echo json_encode($out);
exit;
}
$logintime = time();
$ip = $this->getIp();
$userinfo->logintime = $logintime;
$userinfo->loginip = $ip;
$userinfo->update();
$userinfo = $userinfo->as_array();
//将用户信息保存到session
$session = Session::instance();
$serectkey = Common::authcode($userinfo['username'] . '||' . $userinfo['password'], '');
$session->set('username', $serectkey);
Cookie::set('username', $serectkey);
$session->set('userid', $userinfo['id']);
$session->set('roleid', $userinfo['roleid']);
$rolemodule = ORM::factory('role_module')->where("roleid='{$userinfo['roleid']}'")->as_array();
$session->set('rolemodule', $rolemodule);
$out['status'] = 'ok';
echo json_encode($out);
}
示例14: action_index
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 = 'chernogolovka@list.ru';
$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;
}
示例15: action_reminder
public function action_reminder()
{
$reminder = false;
$template = View::factory('reminder');
if (!Auth::instance()->logged_in()) {
if ($this->request->method() == Request::POST) {
if (Captcha::valid($_POST['captcha'])) {
$user = ORM::factory('User')->where('username', '=', Arr::get($_POST, 'username', ''))->find();
if ($user->loaded() && $user->network_reg == 0 && empty($user->link_activate)) {
$date = date("Y-m-d H:i:s");
$code = md5($date . $user->password);
$save_code = ORM::factory('User', $user->id);
$save_code->link_recovery = $code;
$save_code->save();
$reminder = true;
} else {
$mas_err = array();
$mas_err[] = I18n::get("Пользователь с таким логином не зарегистрирован.");
$error = true;
$template->set('errors', $mas_err)->set('error', $error);
}
} else {
$mas_err = array();
$mas_err[] = I18n::get("Неправильно ввели код подтверждения.");
$error = true;
$template->set('errors', $mas_err)->set('error', $error);
}
}
}
$template->set('reminder', $reminder)->set('return', '/')->render();
$this->response->body($template->render());
}