huacnlee / rucaptcha

Captcha Gem for Rails, which generates captcha image by Rust.
https://huacnlee.github.io/rucaptcha
MIT License
693 stars 133 forks source link

add warning when session is invalid #66

Closed EarlyZhao closed 6 years ago

EarlyZhao commented 6 years ago

Add warning for situation that session is not created. Make it easy for trouble shooting when the captcha failed to verify in this situation.

Sometimes, request for some simple pages in your Rails application may not create a session, as the session in Rails is created lazily. It will be created when it is explicitly used, for example:

<%= csrf_meta_tags %>

or

# controller layer
session[:some_key] = some_value

If not, you can get #<ActionDispatch::Request::Session:0x7f9b28a670c8 not yet loaded> when called session in controller. And the session key you seted will not exist in broswer.

Rucaptcha use the session to distinguish the user or current captcha. So you need ensure the session is exist, when use Rucaptcha. Otherwise, it will let you in trouble.

EarlyZhao commented 6 years ago

@huacnlee I have updated the code and comments.