Skip to content
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

Merged
merged 1 commit into from Sep 2, 2022
Merged

Conversation

Amanetes
Copy link
Contributor

@Amanetes Amanetes commented Aug 18, 2022

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update

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

@ssssank ssssank requested a review from fey August 19, 2022 06:12
@fey fey requested review from ralder and removed request for fey August 20, 2022 12:19
@fey
Copy link
Collaborator

fey commented Aug 20, 2022

@ralder просьба поревьювить

@ashikov
Copy link
Contributor

ashikov commented Aug 23, 2022

@ralder тыц

@ashikov ashikov added the enhancement New feature or request label Aug 23, 2022
@ashikov
Copy link
Contributor

ashikov commented Aug 25, 2022

@amshkv призываю гуру рекапчи :D

@ashikov ashikov requested a review from amshkv August 25, 2022 16:38
self.resource = resource_class.new sign_up_params
resource.validate
resource.errors.add(:recaptcha, t('recaptcha.errors.verification_failed'))
set_minimum_password_length
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А что это за метод? Гема девайса? Что он делает?

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

во всем проекте используется хелпер f, здесь нельзя тоже его использовать?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Попробовал адаптировать к хелперу f

@Amanetes Amanetes requested review from grozwalker and removed request for ralder and amshkv August 26, 2022 14:36
@acidmaksim
Copy link
Contributor

@grozwalker посмотри новые изменения

@@ -14,6 +14,8 @@ def f(key, options = {})
type = options[:type] || key
if options[:now]
flash.now[type] = msg
elsif key == :recaptcha_error
Copy link
Contributor

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

Copy link
Contributor Author

@Amanetes Amanetes Aug 31, 2022

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants