New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add reCaptcha for registration #357
Conversation
@ralder просьба поревьювить |
@ralder тыц |
@amshkv призываю гуру рекапчи :D |
self.resource = resource_class.new sign_up_params | ||
resource.validate | ||
resource.errors.add(:recaptcha, t('recaptcha.errors.verification_failed')) | ||
set_minimum_password_length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А что это за метод? Гема девайса? Что он делает?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grozwalker https://github.com/heartcombo/devise/wiki/How-To:-Use-Recaptcha-with-Devise
Девайсовский, прогоняет валидации и в случае ошибок рендерит new
resource.errors.add(:recaptcha, t('recaptcha.errors.verification_failed')) Это я добавил для того, чтобы на уровне формы тоже всплывало флеш-сообщение об ошибке
set_minimum_password_length | ||
|
||
respond_with_navigational(resource) do | ||
flash.discard(:recaptcha_error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
во всем проекте используется хелпер f, здесь нельзя тоже его использовать?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Попробовал адаптировать к хелперу f
48ec069
to
9995839
Compare
@grozwalker посмотри новые изменения |
app/controllers/concerns/flash.rb
Outdated
@@ -14,6 +14,8 @@ def f(key, options = {}) | |||
type = options[:type] || key | |||
if options[:now] | |||
flash.now[type] = msg | |||
elsif key == :recaptcha_error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Как буд-то выглядит не очень, а почему не сделал что-то вроде?
if options[:discard]
flash.discard[type] = msg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Адаптировал для опций, тут еще фишка была в том, что во флеш пихается [:recaptcha_error], а не :alert или :notice @grozwalker Посмотри, пожалуйста. что еще поправить надо
… add check_recaptcha method to registration controller
9995839
to
399f2cc
Compare
Description
Added Google reCaptcha v2 support for registration to cut off spam bots. There's also an update for README.md to setup reCaptcha and reCaptcha errors localization
Motivation and Context
From time to time site gets lots of spam and reCaptcha is required to minimize amount of spam
Types of changes
Demo
https://sleepy-wave-04388.herokuapp.com/users/sign_up
Additional notes
Rubocop Rails/LexicallyScopedActionFilter has to be disabled in order to invoke callback only for [:create] action without rubocop errors and not to override RegistrationController