hugocabral/visualcaptcha-laravel-jquery
Composer 安装命令:
composer require hugocabral/visualcaptcha-laravel-jquery
包简介
Laravel library for visualCaptcha using jQuery. VisualCaptcha is created by EmotionLoop
README 文档
README
A visual and cleaner alternative to the traditional text based Captcha
This is a Laravel version using jQuery of the Captcha alternative from http://visualcaptcha.net VisualCaptcha is the easiest to implement secure Captcha with images instead of text (and mobile-friendly).
- A better alternative to text based Captchas.
- Decrease user frustration and improve conversion rates.
- Server side validation.
- Easy to style and add custom images.
- Easily translated text.
- Can be used in Views and Controllers.
Pre-Requisites
- Laravel
-
PHP 5.3
Installation Back-End
- Begin by installing this package through Composer.
{ "require": { "hugocabral/visualcaptcha-laravel-jquery": "~1.0" } }
- Add these lines top the "app.php" file in the config folder where is the "aliases" category :
// app.php 'Captcha' => 'visualCaptcha\Captcha', 'SessionCaptcha' => 'visualCaptcha\SessionCaptcha',
- Update composer in terminal:
composer update
Note
- Example/ folder contains the app/ and public/ files used for the laravel example shown here: http://www.hugocabral.pt/visualCaptcha-Laravel-jQuery
Usage
Note: This implementation uses Localization from Laravel (Languages). No need to freak out. Its easy to use and you can check the explanation in this readme under Localization.
Add routes:
// routes.php // Check Locale selected and show demo view. If your app will be English only, you can remove: $lang = Config::get('app.locale'); and remove: ,compact('lang'). Route::get('/', array('as' => 'demo', function() { $lang = Config::get('app.locale'); return View::make('demo', compact('lang')); })); // Send method to validate captcha Route::post('captchacheck','CaptchaController@send'); // Routes for app.visualcaptcha.js. Route::group(array('prefix' => 'captcha'), function() { Route::get('start/{howmany}', array('as' => 'captcha/start', 'uses'=>'CaptchaController@start')); Route::get('audio/{type?}', array('as' => 'captcha/audio', 'uses'=>'CaptchaController@audio')); Route::get('image/{index?}', array('as' => 'captcha/image', 'uses'=>'CaptchaController@image')); });
Create CaptchaController.php to create captcha, refresh, validade and do action (ex send email, update database)
// app/controllers/CaptchaController.php class CaptchaController extends BaseController { /** * Generate a Captcha * @return Response */ public function start($howmany) { $session = new SessionCaptcha(); $captcha = new Captcha($session); $captcha->generate($howmany); return Response::json($captcha->getFrontEndData()); } /** * Get an audio file * @param string $type Song type (mp3/ogg) * @return File */ public function audio($type = 'mp3') { $session = new SessionCaptcha(); $captcha = new Captcha($session); return $captcha->streamAudio(array(), $type); } /** * Get an image file * @param string $index Image index * @return File */ public function image($index) { $session = new SessionCaptcha(); $captcha = new Captcha($session); return $captcha->streamImage(array(), $index, 0 ); } /** * Check if the Captcha result is good * @return Mixed */ public function send() { $data = Input::all(); //Validation rules $rules = array( 'name' => 'required' ); //Validate data $validator = Validator::make($data, $rules); //If everything is correct than run passes. if ($validator->passes()) { $session = new SessionCaptcha(); $captcha = new Captcha($session); $frontendData = $captcha->getFrontendData(); if (!$frontendData) { return Redirect::back()->withInput()->withErrors(array('message' => Lang::get('text.captcha.none'))); } else { // If an image field name was submitted, try to validate it if ($imageAnswer = Input::get($frontendData['imageFieldName'])) { if ($captcha->validateImage($imageAnswer)) { // Return true if the result is correct (... DO ACTION HERE, ex send email, update db...) // This return back to form to show sucess, thats why i use status=1 return Redirect::back()->with('status', 1); } else { return Redirect::back()->withInput()->withErrors(array('message' => Lang::get('text.captcha.image'))); } } else if ($audioAnswer = Input::get($frontendData['audioFieldName'])) { if ($captcha->validateAudio($audioAnswer)) { // Return true if the result is correct (... DO ACTION HERE, ex send email, update db...) // This return back to form to show sucess, thats why i use status=1 return Redirect::back()->with('status', 1); } else { return Redirect::back()->withInput()->withErrors(array('message' => Lang::get('text.captcha.audio'))); } } else { return Redirect::back()->withInput()->withErrors(array('message' => Lang::get('text.captcha.incomplete'))); } } } else { //return "contact form with errors"; return Redirect::back()->withErrors($validator)->with('status', 2);; } } }
Note: The Lang::get('xxx.xxx.xxx') code is the implementation of Localization (Languages). If your app will be English only, you can hardcore and replace this with your messages/errors.
Include jQuery library, jQuery visualCaptcha front-end library and app.js in you view or main layout or wherever you will be using visualCaptcha
// contact.blade.php
{{ HTML::script(js/jquery.min.js) }}
{{ HTML::script(js/visualcaptcha.jquery.js) }}
{{ HTML::script(js/app.js') }}) }}
README INCOMPLETE / will finish soon
hugocabral/visualcaptcha-laravel-jquery 适用场景与选型建议
hugocabral/visualcaptcha-laravel-jquery 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 169 次下载、GitHub Stars 达 6, 最近一次更新时间为 2015 年 01 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「jquery」 「captcha」 「laravel」 「laravel4」 「visualCaptcha」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hugocabral/visualcaptcha-laravel-jquery 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hugocabral/visualcaptcha-laravel-jquery 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hugocabral/visualcaptcha-laravel-jquery 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
Provide a way to secure accesses to all routes of an symfony application.
Two Captcha
It's a barebone security class written on PHP
This is a laravel 4 package for the server and client side of datatables at http://datatables.net/
统计信息
- 总下载量: 169
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-07