huacnlee / rucaptcha Goto Github PK
View Code? Open in Web Editor NEWCaptcha Gem for Rails, which generates captcha image by Rust.
Home Page: https://huacnlee.github.io/rucaptcha
License: MIT License
Captcha Gem for Rails, which generates captcha image by Rust.
Home Page: https://huacnlee.github.io/rucaptcha
License: MIT License
刷新之后的验证码只有颜色改变没有改变数字
部署使用生产环境,启动报错。在本地测试环境使用正常。不知是哪里有问题
routes.rb
# rucaptcha
mount RuCaptcha::Engine => "/rucaptcha"
Exiting
/usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/route_set.rb:507:in `add_route': Invalid route name, already in use: 'ru_captcha' (ArgumentError)
You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here:
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created
from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/mapper.rb:1657:in `add_route'
from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/mapper.rb:1628:in `decomposed_match'
from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/mapper.rb:1927:in `block in map_match'
from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/mapper.rb:1910:in `each'
from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/mapper.rb:1910:in `map_match'
from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/mapper.rb:1599:in `match'
from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/mapper.rb:617:in `mount'
from /data/ruby-apps/siziwang_travel/config/routes.rb:28:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/route_set.rb:389:in `instance_exec'
from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/route_set.rb:389:in `eval_block'
from /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.2/lib/action_dispatch/routing/route_set.rb:371:in `draw'
from /data/ruby-apps/siziwang_travel/config/routes.rb:1:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in `load'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in `block in load'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:259:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.2/lib/active_support/dependencies.rb:287:in `load'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:40:in `each'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:40:in `load_paths'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:16:in `reload!'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:26:in `block in updater'
from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.2/lib/active_support/file_update_checker.rb:77:in `execute'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:27:in `updater'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application/finisher.rb:119:in `block in <module:Finisher>'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/initializable.rb:30:in `instance_exec'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/initializable.rb:30:in `run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/initializable.rb:54:in `run_initializers'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/application.rb:352:in `initialize!'
from /data/ruby-apps/siziwang_travel/config/environment.rb:5:in `<top (required)>'
from /data/ruby-apps/siziwang_travel/config.ru:3:in `require_relative'
from /data/ruby-apps/siziwang_travel/config.ru:3:in `block in <main>'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/builder.rb:55:in `instance_eval'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/builder.rb:55:in `initialize'
from /data/ruby-apps/siziwang_travel/config.ru:in `new'
from /data/ruby-apps/siziwang_travel/config.ru:in `<main>'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/builder.rb:49:in `eval'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/builder.rb:49:in `new_from_string'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/builder.rb:40:in `parse_file'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/server.rb:318:in `build_app_and_options_from_config'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/server.rb:218:in `app'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands/server.rb:59:in `app'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/server.rb:353:in `wrapped_app'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands/server.rb:124:in `log_to_stdout'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands/server.rb:77:in `start'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:90:in `block in server'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `tap'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `server'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.2/lib/rails/commands.rb:18:in `<top (required)>'
from /data/ruby-apps/siziwang_travel/bin/rails:9:in `require'
from /data/ruby-apps/siziwang_travel/bin/rails:9:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `load'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `call'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/client/command.rb:7:in `call'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/client.rb:30:in `run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.1/bin/spring:49:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `load'
from /usr/local/rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `<top (required)>'
from /data/ruby-apps/siziwang_travel/bin/spring:14:in `require'
from /data/ruby-apps/siziwang_travel/bin/spring:14:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
图片显示kaahl,存储值竟然是kyyhl,怪不得反映识别度低,经过多次测试发现,a会随机变为a,h,y
I konw that in the form, I can use the method verify_rucaptcha? to verify the code, is there any way that I can print or get the rucaptcha code in the back-end?
在本地调试,单步跟踪,发现 verify_rucaptcha?(@user) 一直返回false,请问可能是什么原因?
Keep getting this warning:
RuCaptcha's cache_store requirements are stored across processes and machines,
such as :mem_cache_store, :redis_store, or other distributed storage.
But your current set is file_store, it has changed to :file_store for working.
NOTE: :file_store is still not a good way, it only works with single server case.
Please make config file `config/initializers/rucaptcha.rb` to setup `cache_store`.
More infomation please read GitHub RuCaptcha README file.
https://github.com/huacnlee/rucaptcha
版本 2.1.3
as mentioned in title, my verify code picture cannot show completely, as link followed:
http://standard.cfda.pub:8800/rucaptcha
my os system is centos 6.5, and rails version is: 4.2.4
Would enable people to have an option other than using visual feedback. Example libraries with audio captcha include
Happy to implement one of these.
First request from mobile browser: Safari or Chrome in iOS
I, [2018-07-12T19:19:15.634746 #23750] INFO -- : [8faf25ee-2b3a-4634-b76e-5ba8f0c9a0a3] Started GET "/rucaptcha/" for 220.248.44.178 at 2018-07-12 19:19:15 +0800
I, [2018-07-12T19:19:15.637015 #23750] INFO -- : [8faf25ee-2b3a-4634-b76e-5ba8f0c9a0a3]
Processing by RuCaptcha::CaptchaController#index as HTML
I, [2018-07-12T19:19:15.638189 #23750] INFO -- : [8faf25ee-2b3a-4634-b76e-5ba8f0c9a0a3] rucapcha : session_id =
I, [2018-07-12T19:19:15.638253 #23750] INFO -- : [8faf25ee-2b3a-4634-b76e-5ba8f0c9a0a3] rucapcha : session.id =
I, [2018-07-12T19:19:15.638316 #23750] INFO -- : [8faf25ee-2b3a-4634-b76e-5ba8f0c9a0a3] rucapcha : session[:session_id] =
I, [2018-07-12T19:19:15.638375 #23750] INFO -- : [8faf25ee-2b3a-4634-b76e-5ba8f0c9a0a3] rucapcha : rucaptcha_sesion_key_key = rucaptcha-session:
I, [2018-07-12T19:19:15.638649 #23750] INFO -- : [8faf25ee-2b3a-4634-b76e-5ba8f0c9a0a3] rucapcha : $redis.get(rucaptcha_sesion_key_key) =
I, [2018-07-12T19:19:15.638939 #23750] INFO -- : [8faf25ee-2b3a-4634-b76e-5ba8f0c9a0a3] rucapcha : RuCaptcha.cache.read(rucaptcha_sesion_key_key) = {:code=>"rqam", :time=>1531394355}
I, [2018-07-12T19:19:15.639384 #23750] INFO -- : [8faf25ee-2b3a-4634-b76e-5ba8f0c9a0a3] Rendered text template (0.1ms)
I, [2018-07-12T19:19:15.639543 #23750] INFO -- : [8faf25ee-2b3a-4634-b76e-5ba8f0c9a0a3] Sent data (0.5ms)
I, [2018-07-12T19:19:15.639675 #23750] INFO -- : [8faf25ee-2b3a-4634-b76e-5ba8f0c9a0a3] Completed 200 OK in 3ms (Views: 0.4ms | ActiveRecord: 0.0ms)
Second Request: from Chrome in mac
I, [2018-07-12T19:19:19.428124 #23750] INFO -- : [bc11f394-6d5f-4056-9c87-f9efcc12caaf] Started GET "/rucaptcha/" for 220.248.44.178 at 2018-07-12 19:19:19 +0800
I, [2018-07-12T19:19:19.430369 #23750] INFO -- : [bc11f394-6d5f-4056-9c87-f9efcc12caaf] Processing by RuCaptcha::CaptchaController#index as HTML
I, [2018-07-12T19:19:19.431884 #23750] INFO -- : [bc11f394-6d5f-4056-9c87-f9efcc12caaf] rucapcha : session_id = 0bdfce54b6d1cab465e2abc48cee91d6
I, [2018-07-12T19:19:19.431973 #23750] INFO -- : [bc11f394-6d5f-4056-9c87-f9efcc12caaf] rucapcha : session.id = 0bdfce54b6d1cab465e2abc48cee91d6
I, [2018-07-12T19:19:19.432050 #23750] INFO -- : [bc11f394-6d5f-4056-9c87-f9efcc12caaf] rucapcha : session[:session_id] = 0bdfce54b6d1cab465e2abc48cee91d6
I, [2018-07-12T19:19:19.432101 #23750] INFO -- : [bc11f394-6d5f-4056-9c87-f9efcc12caaf] rucapcha : rucaptcha_sesion_key_key = rucaptcha-session:0bdfce54b6d1cab465e2abc48cee91d6
I, [2018-07-12T19:19:19.432329 #23750] INFO -- : [bc11f394-6d5f-4056-9c87-f9efcc12caaf] rucapcha : $redis.get(rucaptcha_sesion_key_key) =
I, [2018-07-12T19:19:19.432692 #23750] INFO -- : [bc11f394-6d5f-4056-9c87-f9efcc12caaf] rucapcha : RuCaptcha.cache.read(rucaptcha_sesion_key_key) = {:code=>"bfdd", :time=>1531394359}
It can cause many users refresh the same rucaptcha_sesion_key_key:
"rucaptcha-session:"
简体和繁体的翻译放错文件了。
你好:
我使用了devise,不想将验证码失败的error放在user里,想将注册时字段错误信息和验证码失败信息分开,所以想调用verify_rucaptcha? nil,如下例子:
class Users::RegistrationsController < Devise::RegistrationsController
def create
build_resource(sign_up_params)
if verify_rucaptcha?
resource.save
yield resource if block_given?
if resource.persisted?
if resource.active_for_authentication?
set_flash_message! :notice, :signed_up
sign_up(resource_name, resource)
respond_with resource, location: after_sign_up_path_for(resource)
else
set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
expire_data_after_sign_in!
respond_with resource, location: after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
set_minimum_password_length
respond_with resource
end
else
#resource.errors.clear
flash.now[:alert] = t('rucaptcha.invalid')
clean_up_passwords resource
respond_with resource
end
end
end
随后看了一下代码,应该是rucaptcha-2.5.0/lib/rucaptcha/controller_helpers.rb里的75行
add_rucaptcha_validation_error方法里resource引用的是全局resource,不是verify_rucaptcha?传进去的resource。
Centos7下安装ImageMegick后,引用RuCaptcha,图片显示不出来,报如下错误,是什么原因
RuntimeError (RuCaptcha: convert: no encode delegate for this image format
LABEL' @ error/constitute.c/WriteImage/1171.):
app/middleware/request_throttle.rb:59:in block in call' app/middleware/request_throttle.rb:257:in
reserve_capacity'
app/middleware/request_throttle.rb:54:in call' app/middleware/request_context_session.rb:25:in
call'
app/middleware/sessions_timeout.rb:22:in call' app/middleware/load_account.rb:12:in
call'
app/middleware/request_context_generator.rb:49:in call' app/middleware/prevent_non_multipart_parse.rb:32:in
call'`
原来是在web里用的图形验证码,使用Grape的接口服务里怎么使用啊?
请问有没有方法去改变生成的验证码的长度?貌似这一块的生成逻辑时靠 rucaptcha.c 来实现的,有没有方法改一下?
在Docker上部署,使用Rails:4.2.4 Image,出现如下错误:
I, [2016-09-25T07:50:07.888809 #1] INFO -- : Processing by RuCaptcha::CaptchaController#index as HTML
E, [2016-09-25T07:50:07.943286 #1] ERROR -- : RuCaptcha RuCaptcha convert: unable to read font `(null)' @ error/annotate.c/RenderFreetype/1127.
convert: unable to read font `(null)' @ error/annotate.c/RenderFreetype/1127.
convert: no images defined `png:-' @ error/convert.c/ConvertImageCommand/3210.
Link: https://www.fineprintnyc.com/estimate
When I press on the refresh image link, it loads the snippet of HTML correctly.
Except in Firefox, the HTML is updated but the same CAPTCHA image is showing
$(document).on 'click touchstart', '.refresh-captcha', (e)->
$.ajax
url: '/captcha'
method: 'get'
cache: false
dataType: "html"
success: (data)->
$('#captcha').html data
Hello @huacnlee.
I noticed a bug that was produced with the following version:
rucaptcha (2.5.3)
railties (>= 3.2)
After I've integrated rucaptcha for login form, every next visit with fresh browser history/cache the first generated captcha keeps being the same.
After researching the forks of your gem, I noticed that this bug is not reproduced with the following version:
GIT
remote: https://github.com/insales/rucaptcha.git
revision: 3fe084ee93b552393c961ec90cf08b10985048c5
specs:
rucaptcha (2.1.3)
railties (>= 3.2)
Please consider pulling changes and let me know if you need assistance. The mentioned fork's master branch is
insales:master branch is 19 commits ahead, 38 commits behind huacnlee:master.
I can fork insales:master to rebase it on your huacnlee:master branch to create a pull request in case you are willing to merge but too busy to do this.
Please also let me know if the mentioned vulnerability is a result of gem misuse/misconfiguration.
RuntimeError (RuCaptcha: convert: not authorized `-' @ error/constitute.c/ReadImage/453.
convert: missing an image filename `png:-' @ error/convert.c/ConvertImageCommand/3015.):
rucaptcha (0.4.5) lib/rucaptcha/captcha.rb:81:in `create'
rucaptcha (0.4.5) lib/rucaptcha/cache.rb:18:in `block in create_with_cache'
activesupport (4.2.5) lib/active_support/cache.rb:299:in `block in fetch'
activesupport (4.2.5) lib/active_support/cache.rb:585:in `block in save_block_result_to_cache'
activesupport (4.2.5) lib/active_support/cache.rb:547:in `block in instrument'
activesupport (4.2.5) lib/active_support/notifications.rb:166:in `instrument'
activesupport (4.2.5) lib/active_support/cache.rb:547:in `instrument'
activesupport (4.2.5) lib/active_support/cache.rb:584:in `save_block_result_to_cache'
activesupport (4.2.5) lib/active_support/cache.rb:299:in `fetch'
rucaptcha (0.4.5) lib/rucaptcha/cache.rb:17:in `create_with_cache'
rucaptcha (0.4.5) lib/rucaptcha/controller_helpers.rb:13:in `generate_rucaptcha'
rucaptcha (0.4.5) app/controllers/ru_captcha/captcha_controller.rb:10:in `index'
actionpack (4.2.5) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.5) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.5) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.5) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
activesupport (4.2.5) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:498:in `block (2 levels) in around'
activesupport (4.2.5) lib/active_support/callbacks.rb:313:in `block (2 levels) in halting'
marginalia (1.3.0) lib/marginalia.rb:77:in `record_query_comment'
activesupport (4.2.5) lib/active_support/callbacks.rb:432:in `block in make_lambda'
activesupport (4.2.5) lib/active_support/callbacks.rb:312:in `block in halting'
activesupport (4.2.5) lib/active_support/callbacks.rb:497:in `block in around'
activesupport (4.2.5) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
activesupport (4.2.5) lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
activesupport (4.2.5) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.5) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.5) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.5) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.5) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.5) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.5) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.5) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.5) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.5) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.5) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:45:in `serve'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:817:in `call'
railties (4.2.5) lib/rails/engine.rb:518:in `call'
railties (4.2.5) lib/rails/railtie.rb:194:in `public_send'
railties (4.2.5) lib/rails/railtie.rb:194:in `method_missing'
actionpack (4.2.5) lib/action_dispatch/routing/mapper.rb:51:in `serve'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:817:in `call'
oneapm_rpm (1.3.6) lib/one_apm/rack/middleware_hooks.rb:13:in `traced_call'
oneapm_rpm (1.3.6) lib/one_apm/rack/middleware_tracing.rb:65:in `call'
oneapm_rpm (1.3.6) lib/one_apm/rack/browser_monitoring.rb:19:in `traced_call'
oneapm_rpm (1.3.6) lib/one_apm/rack/middleware_tracing.rb:65:in `call'
warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
warden (1.2.6) lib/warden/manager.rb:34:in `catch'
warden (1.2.6) lib/warden/manager.rb:34:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.5) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.5) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.5) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.5) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.5) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
airbrake (4.0.0) lib/airbrake/rails/middleware.rb:13:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.5) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.5) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.5) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
airbrake (4.0.0) lib/airbrake/user_informer.rb:16:in `_call'
airbrake (4.0.0) lib/airbrake/user_informer.rb:12:in `call'
railties (4.2.5) lib/rails/engine.rb:518:in `call'
railties (4.2.5) lib/rails/application.rb:165:in `call'
oneapm_rpm (1.3.6) lib/one_apm/rack/middleware_tracing.rb:65:in `call'
puma (2.9.0) lib/puma/configuration.rb:71:in `call'
puma (2.9.0) lib/puma/server.rb:490:in `handle_request'
puma (2.9.0) lib/puma/server.rb:361:in `process_client'
puma (2.9.0) lib/puma/server.rb:254:in `block in run'
puma (2.9.0) lib/puma/thread_pool.rb:92:in `block in spawn_thread'
imagemagick 的 convert 命令的版本:
Version: ImageMagick 6.7.2-7 2016-05-09 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP
生成的代码
<src="http://xxx.com">
产生警告
was loaded over HTTPS, but requested an insecure image 'http://www.xxx.com/rucaptcha/'. This content should also be served over HTTPS.
exam : I want transparent backgroup , or need backgroup white or black . or more ?
How set ?
在initializers/rucaptcha.rb文件中配置length和strikethrough无效。
我想使用这个gem .可是我的应用是在子路径上的, 如 www.qq.com/xx/xx/,所以路由能不能自定义一下, 让rucaptcha 支持子路径,/xx/xx/rucaptcha ?
add the type email the html5 will parse to input must email validate
rails 6.0.2是正常的,更新到6.0.2.1后报错如下
Started GET "/rucaptcha/" for 127.0.0.1 at 2019-12-19 21:42:42 +0800
Processing by RuCaptcha::CaptchaController#index as HTML
Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.0ms | Allocations: 720)
RuntimeError ():
rack (2.0.8) lib/rack/session/abstract/id.rb:31:in to_s' rucaptcha (2.5.1) lib/rucaptcha/controller_helpers.rb:13:in
join'
rucaptcha (2.5.1) lib/rucaptcha/controller_helpers.rb:13:in rucaptcha_sesion_key_key' rucaptcha (2.5.1) lib/rucaptcha/controller_helpers.rb:23:in
generate_rucaptcha'
rucaptcha (2.5.1) app/controllers/ru_captcha/captcha_controller.rb:7:in index' actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in
send_action'
actionpack (6.0.2.1) lib/abstract_controller/base.rb:196:in process_action' actionpack (6.0.2.1) lib/action_controller/metal/rendering.rb:30:in
process_action'
actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:42:in block in process_action' activesupport (6.0.2.1) lib/active_support/callbacks.rb:135:in
run_callbacks'
actionpack (6.0.2.1) lib/abstract_controller/callbacks.rb:41:in process_action' actionpack (6.0.2.1) lib/action_controller/metal/rescue.rb:22:in
process_action'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:33:in block in process_action' activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in
block in instrument'
activesupport (6.0.2.1) lib/active_support/notifications/instrumenter.rb:24:in instrument' activesupport (6.0.2.1) lib/active_support/notifications.rb:180:in
instrument'
actionpack (6.0.2.1) lib/action_controller/metal/instrumentation.rb:32:in process_action' actionpack (6.0.2.1) lib/action_controller/metal/params_wrapper.rb:245:in
process_action'
activerecord (6.0.2.1) lib/active_record/railties/controller_runtime.rb:27:in process_action' actionpack (6.0.2.1) lib/abstract_controller/base.rb:136:in
process'
actionview (6.0.2.1) lib/action_view/rendering.rb:39:in process' actionpack (6.0.2.1) lib/action_controller/metal.rb:191:in
dispatch'
actionpack (6.0.2.1) lib/action_controller/metal.rb:252:in dispatch' actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:51:in
dispatch'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:33:in serve' actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:49:in
block in serve'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in each' actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in
serve'
actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:837:in call' railties (6.0.2.1) lib/rails/engine.rb:526:in
call'
railties (6.0.2.1) lib/rails/railtie.rb:190:in public_send' railties (6.0.2.1) lib/rails/railtie.rb:190:in
method_missing'
actionpack (6.0.2.1) lib/action_dispatch/routing/mapper.rb:19:in block in <class:Constraints>' actionpack (6.0.2.1) lib/action_dispatch/routing/mapper.rb:48:in
serve'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:49:in block in serve' actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in
each'
actionpack (6.0.2.1) lib/action_dispatch/journey/router.rb:32:in serve' actionpack (6.0.2.1) lib/action_dispatch/routing/route_set.rb:837:in
call'
rack-attack (6.2.2) lib/rack/attack.rb:170:in call' rack-cors (1.1.0) lib/rack/cors.rb:100:in
call'
rack (2.0.8) lib/rack/tempfile_reaper.rb:15:in call' rack (2.0.8) lib/rack/etag.rb:25:in
call'
rack (2.0.8) lib/rack/conditional_get.rb:25:in call' rack (2.0.8) lib/rack/head.rb:12:in
call'
actionpack (6.0.2.1) lib/action_dispatch/http/content_security_policy.rb:18:in call' rack (2.0.8) lib/rack/session/abstract/id.rb:259:in
context'
rack (2.0.8) lib/rack/session/abstract/id.rb:253:in call' actionpack (6.0.2.1) lib/action_dispatch/middleware/cookies.rb:648:in
call'
activerecord (6.0.2.1) lib/active_record/migration.rb:567:in call' actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in
block in call'
activesupport (6.0.2.1) lib/active_support/callbacks.rb:101:in run_callbacks' actionpack (6.0.2.1) lib/action_dispatch/middleware/callbacks.rb:26:in
call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in call' actionpack (6.0.2.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in
call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:32:in call' web-console (4.0.1) lib/web_console/middleware.rb:132:in
call_app'
web-console (4.0.1) lib/web_console/middleware.rb:28:in block in call' web-console (4.0.1) lib/web_console/middleware.rb:17:in
catch'
web-console (4.0.1) lib/web_console/middleware.rb:17:in call' actionpack (6.0.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in
call'
railties (6.0.2.1) lib/rails/rack/logger.rb:38:in call_app' railties (6.0.2.1) lib/rails/rack/logger.rb:26:in
block in call'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in block in tagged' activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:28:in
tagged'
activesupport (6.0.2.1) lib/active_support/tagged_logging.rb:80:in tagged' railties (6.0.2.1) lib/rails/rack/logger.rb:26:in
call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in call' actionpack (6.0.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in
call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/request_id.rb:27:in call' rack (2.0.8) lib/rack/method_override.rb:22:in
call'
rack (2.0.8) lib/rack/runtime.rb:22:in call' activesupport (6.0.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in
call'
actionpack (6.0.2.1) lib/action_dispatch/middleware/executor.rb:14:in call' actionpack (6.0.2.1) lib/action_dispatch/middleware/static.rb:126:in
call'
rack (2.0.8) lib/rack/sendfile.rb:111:in call' actionpack (6.0.2.1) lib/action_dispatch/middleware/host_authorization.rb:83:in
call'
webpacker (4.2.2) lib/webpacker/dev_server_proxy.rb:23:in perform_request' rack-proxy (0.6.5) lib/rack/proxy.rb:57:in
call'
railties (6.0.2.1) lib/rails/engine.rb:526:in call' puma (4.3.1) lib/puma/configuration.rb:228:in
call'
puma (4.3.1) lib/puma/server.rb:681:in handle_request' puma (4.3.1) lib/puma/server.rb:472:in
process_client'
puma (4.3.1) lib/puma/server.rb:328:in block in run' puma (4.3.1) lib/puma/thread_pool.rb:134:in
block in spawn_thread'
在mac下报如下错误:
RuntimeError at /
RuCaptcha: dyld: Library not loaded: /usr/X11/lib/libfontconfig.1.dylib
Referenced from: /usr/local/bin/convert
Reason: image not found
imagemagick和imagemagick已经安装
如果配置文件设置为redis_store, 但并不启动redis, 验证码能出来,但一直无法验证通过。
这可能是个小问题。
理想的方式是:
配置文件设置为redis_store, 但连接不到redis,就使用file_store.
请在 readme 中的 required 中 上添加:
sudo yum install -y ImageMagick ImageMagick-devel ghostscript
华顺请教一下,如果验证码我想换成全是数字,不含字母的,应该怎么设置或改代码啊?谢谢
配置是 self.cache_store = :redis_store
有关的gem:
gem 'rucaptcha', '~> 2.1.2'
gem 'redis-rails'
Started GET "/rucaptcha/" for 127.0.0.1 at 2017-03-22 14:42:25 +0800
Processing by RuCaptcha::CaptchaController#index as HTML
Sent file GIF89a一堆乱码(0.0ms)
Completed 500 Internal Server Error in 2833ms (ActiveRecord: 1.0ms)
ArgumentError (string contains null byte):
actionpack (5.0.2) lib/action_controller/metal/data_streaming.rb:67:in `file?'
actionpack (5.0.2) lib/action_controller/metal/data_streaming.rb:67:in `send_file'
调试后发现 gems/rucaptcha-2.1.2/app/controllers/ru_captcha/captcha_controller.rb
if Gem.win_platform?
send_file data, opts
else
send_data data, opts
end
如果是windows时,使用的send_file,修改为send_data就会正常显示图片了
建议把亮黄色去掉。
验证总是返回false,经过调试,发现 store_info = RuCaptcha.cache.read(rucaptcha_sesion_key_key)
中的store_info
一直返回nil
redis_rails
这个gem,把session存到redis,store_info
依然返回空。RuCaptcha.cache.read
方法也能正确读出hashverify_rucaptcha?
与 verify_rucaptcha?(resource)
方式使用也都是返回false
我的环境之前是 ruby2.4.4
和 rails 5.2.2.1
,redis和web服务在同一台服务器上。
最近新开了一台服务器(旧服务器关停),并将ruby升级到2.6.3
,rails升级到5.2.3
,redis使用内网连接(已确定可正常连接),就出现了这个问题。
全部按照官方的配置进行,但是在启动的时候后台报没有安装dalli。
日志如下:
Started GET "/rucaptcha/" for 127.0.0.1 at 2017-01-25 22:51:50 +0800
Processing by RuCaptcha::CaptchaController#index as HTML
You don't have dalli installed in your application. Please add it to your Gemfile and run bundle install
Completed 500 Internal Server Error in 82ms (ActiveRecord: 0.0ms)
RuntimeError (Could not find cache store adapter for mem_cache_store (cannot load such file -- dalli)):
activesupport (5.0.0) lib/active_support/cache.rb:106:in rescue in retrieve_store_class' activesupport (5.0.0) lib/active_support/cache.rb:104:in
retrieve_store_class'
activesupport (5.0.0) lib/active_support/cache.rb:60:in lookup_store' rucaptcha (2.0.0) lib/rucaptcha/cache.rb:7:in
cache'
rucaptcha (2.0.0) lib/rucaptcha/controller_helpers.rb:22:in generate_rucaptcha' rucaptcha (2.0.0) app/controllers/ru_captcha/captcha_controller.rb:6:in
index'
actionpack (5.0.0) lib/action_controller/metal/basic_implicit_render.rb:4:in send_action' actionpack (5.0.0) lib/abstract_controller/base.rb:188:in
process_action'
I am using this gem without devise, version == 2.1.3.
Not sure why but cannot get the invalid message. Just follow the instructions.
Now in order to get an error message, I have to manually add a line of code to make it happen.
if verify_rucaptcha?(@user) && @user.save
@user.send_activation_email
redirect_to activate_user_url(@user)
else
# this one below
@user.errors.add(:base, t('rucaptcha.invalid'))
render :new
end
undefined local variable or method `ru_captcha' for #<#Class:0xbc0a7e74:0xbc0a7424>
原本我是想在console 里直接 require,但发现执行不了,总是找不到文件。换到2.3.0,就可以了,是版本的问题吗?
版本
ruby 2.5.1
Rails 5.2.1
rucaptcha.rb配置用的
self.cache_store = :file_store
但是在控制器中报错,找不到verify_rucaptcha?这个方法
In development env. rucaptcha_image_tag will render
<img alt="Rucaptcha" class="rucaptcha-image" src="http://127.0.01:3000/rucaptcha/">
The src attribute include host info. It's ok in local machine.
Edge case: in a remote server, just run with development env and bind local address. use Nginx to listen to 80 and forward request.
rails server -b 0.0.0.0
In this case, the absolute path of Rucaptcha tag with not working.
Whether using the relative path of image would be better?
<img alt="Rucaptcha" class="rucaptcha-image" src="/rucaptcha/">
"abcdafahijklmnopqrstuvwxyz"
"abcdyfhhijklmnopqrstuvwxyz"
https://github.com/ITikhonov/captcha
https://github.com/huacnlee/rucaptcha/blob/master/ext/rucaptcha/rucaptcha.c#L154
如果配置了:redis_store,则会通过lookup_store获取一个cache的obj,但获取到的redis_store是默认配置,通常是指向127.0.0.1的,但如果这个redis_store不在::1上呢?
先在captcha 的索引是通过rucaptcha_sesion_key_key 来存在session 里面的。但是如果是无状态的API 接口的话(移动端),就不太好用了。
像这样把captcha 在存储中的key 返回,就可以支持不用cookie 的API了
def new_generate_rucaptcha
res = RuCaptcha.generate()
session_val = {
code: res[0],
time: Time.now.to_i
}
RuCaptcha.cache.write(rucaptcha_sesion_key_key, session_val, expires_in: RuCaptcha.config.expires_in)
opts = { disposition: 'inline', type: 'image/gif', filename: rucaptcha_sesion_key_key }
send_data res[1], opts
end
I know it is reasonable config for you to make :mem_cache or :redis as a default cache way in production due to cross machines issue. However, if you can leave a :file_store option for develop mode, it will be convenient for developers in their local machine. cheers.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.