Skip to content

Commit

Permalink
redirect to frontend after confirming email adress
Browse files Browse the repository at this point in the history
  • Loading branch information
simonfranzen committed Sep 18, 2020
1 parent 79c83cf commit 831af15
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 29 deletions.
56 changes: 29 additions & 27 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
require:
- rubocop-performance
- rubocop-rails
- rubocop-rspec
- rubocop-performance
- rubocop-rails
- rubocop-rspec
AllCops:
TargetRubyVersion: 2.6
NewCops: enable
Exclude:
- "db/**/*"
- "script/**/*"
- "bin/**/*"
- "vendor/**/*"
- "app/helpers/ui_helper*"
- "spec/spec_helper*"
- "spec/rails_helper*"
- Gemfile*
TargetRubyVersion: 2.6
NewCops: enable
Exclude:
- "db/**/*"
- "script/**/*"
- "bin/**/*"
- "vendor/**/*"
- "app/helpers/ui_helper*"
- "spec/spec_helper*"
- "spec/rails_helper*"
- Gemfile*
Metrics/MethodLength:
Max: 15
Max: 15
Metrics/AbcSize:
Max: 25
Style/MethodCallWithoutArgsParentheses:
Enabled: false
Enabled: false
Metrics/BlockLength:
Exclude:
- "config/**/*"
- "spec/**/*"
- "lib/tasks/**/*"
Exclude:
- "config/**/*"
- "spec/**/*"
- "lib/tasks/**/*"
Layout/LineLength:
Exclude:
- "config/**/*"
Exclude:
- "config/**/*"
RSpec/MultipleExpectations:
Enabled: false
Enabled: false
RSpec/InstanceVariable:
Enabled: false
Enabled: false
RSpec/UnspecifiedException:
Enabled: false
Enabled: false
RSpec/ExampleLength:
Max: 10
Max: 10
RSpec/MultipleMemoizedHelpers:
Max: 10
Max: 10
23 changes: 23 additions & 0 deletions app/controllers/confirmations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

# Custom confirmations controller
class ConfirmationsController < Devise::ConfirmationsController
# GET /resource/confirmation?confirmation_token=abcdef
def show
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
yield resource if block_given?

if resource.errors.empty?
respond_with_navigational(resource) { redirect_to after_confirmation_path_for(resource_name, resource) }
else
redirect_to "http://#{ENV['CLIENT_URL']}?error=#{I18n.t('errors.messages.already_confirmed')}"
end
end

private

# redirect user to front end app after confirming the email adress.
def after_confirmation_path_for(_resource_name, _resource)
"http://#{ENV['CLIENT_URL']}?notice=#{I18n.t('devise.confirmations.confirmed')}"
end
end
1 change: 1 addition & 0 deletions app/graphql/types/user_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class UserType < BaseModel
field :first_name, String, null: false
field :last_name, String, null: false
field :email, String, null: true
field :role, String, null: false
field :company, Types::Companies::CompanyType, null: false
end
end
3 changes: 2 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@
#
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :timeoutable, :trackable and :omniauthable
# :timeoutable, :trackable and :omniauthable
devise :database_authenticatable,
:registerable,
:recoverable,
:confirmable,
:devise,
:validatable,
:lockable,
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
post '/graphql', to: 'graphql#execute'
devise_for :users, skip: :registrations # skip registration route
devise_for :users, controllers: { confirmations: 'confirmations' }, skip: :registrations # skip registration route

# Just a blank root path
root 'pages#blank'
Expand Down

0 comments on commit 831af15

Please sign in to comment.