diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 0db33128..3adc60f7 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -3,6 +3,17 @@ class RegistrationsController < Devise::RegistrationsController prepend_before_action :check_captcha, only: [:create] + def create + existing_user = User.find_by(email: sign_up_params[:email]) + if existing_user + flash[:notice] = 'An account with this email already exists. Please reset your password to sign in.' + redirect_to new_user_password_path(user: { email: sign_up_params[:email] }) + return + end + + super + end + protected def after_update_path_for(resource) diff --git a/app/views/devise/passwords/new.html.haml b/app/views/devise/passwords/new.html.haml index 49765d77..31aef5c8 100644 --- a/app/views/devise/passwords/new.html.haml +++ b/app/views/devise/passwords/new.html.haml @@ -10,7 +10,7 @@ .form-group = f.label :email, "Email" %abbr{title: 'This field is required'} * - = f.email_field :email, autofocus: true, required: true, class: 'form-control', placeholder: 'Email' + = f.email_field :email, autofocus: true, required: true, class: 'form-control', placeholder: 'Email', value: params.dig(:user, :email) %p.text-right %button{type: 'submit', class: 'btn btn-success'} Send me reset password instructions