]> gitweb.mndrdr.org Git - arelpe.git/commitdiff
Added hCaptcha, sadly, because of spam
authorAidan Cornelius-Bell <[email protected]>
Mon, 7 Oct 2024 22:01:19 +0000 (08:31 +1030)
committerAidan Cornelius-Bell <[email protected]>
Mon, 7 Oct 2024 22:01:19 +0000 (08:31 +1030)
Gemfile
Gemfile.lock
app/controllers/users/registrations_controller.rb [new file with mode: 0644]
app/models/user.rb
app/views/devise/registrations/new.html.erb
config/routes.rb

diff --git a/Gemfile b/Gemfile
index 65bc37562750281690c99a3775b3d2c96fbe0dce..59be3ae371519a4a9a80d7f3c645889ee204473a 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -20,6 +20,8 @@ gem "rouge"
 gem "httparty"
 #environment stuff
 gem "dotenv"
+#humanity verification
+gem "hcaptcha"
 # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
 # gem "kredis"
 #api stuff
index 23fc602e14a5c749aab511b40e7e5ad4c5d7aa5c..fae35dc17fc0f57c17cd0f4513ba4b9315558884 100644 (file)
@@ -113,6 +113,8 @@ GEM
     erubi (1.13.0)
     globalid (1.2.1)
       activesupport (>= 6.1)
+    hcaptcha (7.1.0)
+      json
     httparty (0.22.0)
       csv
       mini_mime (>= 1.0.0)
@@ -326,6 +328,7 @@ DEPENDENCIES
   debug
   devise
   dotenv
+  hcaptcha
   httparty
   jsonapi-serializer
   kaminari
diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb
new file mode 100644 (file)
index 0000000..837c1c3
--- /dev/null
@@ -0,0 +1,19 @@
+class Users::RegistrationsController < Devise::RegistrationsController
+  prepend_before_action :check_captcha, only: [:create]
+
+  private
+
+  def check_captcha
+       unless verify_hcaptcha
+         self.resource = resource_class.new sign_up_params
+         resource.validate
+         set_minimum_password_length
+         resource.errors.add(:base, 'Please verify that you are not a robot')
+         respond_with_navigational(resource) { render :new }
+       end
+  end
+  
+  def sign_up_params
+         params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation)
+       end
+end
\ No newline at end of file
index 163501f345dd3e429ab15d9a69180136b32ed388..9c650ff0689b00451161b452a16be83a25c3b082 100644 (file)
@@ -1,7 +1,7 @@
 class User < ApplicationRecord
   # Include default devise modules. Others available are:
   # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
-  devise :database_authenticatable, :registerable,
+  devise :database_authenticatable, :registerable,
          :recoverable, :rememberable, :validatable,
          :confirmable
          
index a466cde930e3a00974158ca11cd01c22b34bb187..c9efc47b862d513ae4a4485cddb2773746e155eb 100644 (file)
       <%= f.label :password_confirmation %>
       <%= f.password_field :password_confirmation, autocomplete: "new-password" %>
     </div>
+    
+    <div class="field">
+      <%= hcaptcha_tags %>
+    </div>
 
     <div class="actions">
       <%= f.submit "Sign up" %>
index 9e62840d6fb2a90e3752ca4a64d1f6be5e9e6a30..ff3554dd092c0475f3bfb469be94c0c0441e8af6 100644 (file)
@@ -16,7 +16,7 @@ Rails.application.routes.draw do
   get 'export', to: 'posts#export'
   post 'import', to: 'posts#import'
   resources :api_keys
-  devise_for :users
+  devise_for :users, controllers: { registrations: 'users/registrations' }
   resources :posts
   get '/feed', to: 'pubview#rss', as: 'rss', defaults: { format: 'rss' }
   get '/feed/dispatches', to: 'pubview#dispatches_rss', as: 'dispatches_rss', defaults: { format: 'rss' }