diff --git a/Gemfile b/Gemfile index 9af038a..dc06bea 100644 --- a/Gemfile +++ b/Gemfile @@ -40,6 +40,8 @@ gem 'interactor-rails' gem 'active_model_serializers' +gem 'mailgun-ruby' + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: %i[mri mingw x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index 084d4f3..0fee2e0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,6 +76,8 @@ GEM rails (>= 4.2.0, < 6) diff-lcs (1.3) docile (1.3.1) + domain_name (0.5.20180417) + unf (>= 0.0.5, < 1.0.0) erubi (1.8.0) factory_bot (5.0.2) activesupport (>= 4.2.0) @@ -88,6 +90,8 @@ GEM globalid (0.4.2) activesupport (>= 4.2.0) htmlentities (4.3.4) + http-cookie (1.0.3) + domain_name (~> 0.5) i18n (1.6.0) concurrent-ruby (~> 1.0) interactor (3.1.1) @@ -107,14 +111,20 @@ GEM nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) + mailgun-ruby (1.1.11) + rest-client (~> 2.0.2) marcel (0.3.3) mimemagic (~> 0.3.2) method_source (0.9.2) + mime-types (3.2.2) + mime-types-data (~> 3.2015) + mime-types-data (3.2019.0331) mimemagic (0.3.3) mini_mime (1.0.1) mini_portile2 (2.4.0) minitest (5.11.3) msgpack (1.2.9) + netrc (0.11.0) nio4r (2.3.1) nokogiri (1.10.2) mini_portile2 (~> 2.4.0) @@ -162,6 +172,10 @@ GEM responders (2.4.1) actionpack (>= 4.2.0, < 6.0) railties (>= 4.2.0, < 6.0) + rest-client (2.0.2) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) reverse_markdown (1.1.0) nokogiri rspec-core (3.8.0) @@ -230,6 +244,9 @@ GEM tins (1.20.2) tzinfo (1.2.5) thread_safe (~> 0.1) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.6) unicode-display_width (1.5.0) warden (1.2.8) rack (>= 2.0.6) @@ -253,6 +270,7 @@ DEPENDENCIES interactor interactor-rails listen (>= 3.0.5, < 3.2) + mailgun-ruby pg puma (~> 3.11) rack-cors diff --git a/app/models/user.rb b/app/models/user.rb index c21ab22..6d2a109 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,7 +3,7 @@ class User < ApplicationRecord extend Devise::Models - devise :database_authenticatable, :registerable, + devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable include DeviseTokenAuth::Concerns::User diff --git a/app/views/devise/mailer/confirmation_instructions.html.erb b/app/views/devise/mailer/confirmation_instructions.html.erb new file mode 100644 index 0000000..dc55f64 --- /dev/null +++ b/app/views/devise/mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @email %>!

+ +

You can confirm your account email through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

diff --git a/app/views/devise/mailer/email_changed.html.erb b/app/views/devise/mailer/email_changed.html.erb new file mode 100644 index 0000000..32f4ba8 --- /dev/null +++ b/app/views/devise/mailer/email_changed.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @email %>!

+ +<% if @resource.try(:unconfirmed_email?) %> +

We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.

+<% else %> +

We're contacting you to notify you that your email has been changed to <%= @resource.email %>.

+<% end %> diff --git a/app/views/devise/mailer/password_change.html.erb b/app/views/devise/mailer/password_change.html.erb new file mode 100644 index 0000000..b41daf4 --- /dev/null +++ b/app/views/devise/mailer/password_change.html.erb @@ -0,0 +1,3 @@ +

Hello <%= @resource.email %>!

+ +

We're contacting you to notify you that your password has been changed.

diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb new file mode 100644 index 0000000..f667dc1 --- /dev/null +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password. You can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/app/views/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/unlock_instructions.html.erb new file mode 100644 index 0000000..41e148b --- /dev/null +++ b/app/views/devise/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

diff --git a/config/application.rb b/config/application.rb index 1c92888..879cffc 100644 --- a/config/application.rb +++ b/config/application.rb @@ -40,5 +40,11 @@ module TurniereBackend resource '*', headers: :any, methods: :any, expose: ['access-token', 'client', 'expiry', 'uid'] end end + + # Mail + config.action_mailer.default_url_options = { host: 'turnie.re' } + config.action_mailer.default_options = { + from: 'noreply@turnie.re' + } end end diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index 8616a64..8b96059 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1 +1 @@ -dCVJGOYsmgcPz9jtSayZvIPAReIg2LIeScmbZ66S3PHhRj32F3vhQJLpARU26RISOCc8cFxvVcZb1H/Lhmj9iq+5/+5471OB04U74F7vbXIpgwlC+4CYD99hDOw/i9GokwfT/E/nqW1tBBMIm17QC8EwrJgIZlZCxE6C/3DUx+sAcupQafb9NAFqRffoL9KQj7X7CyJ3d7GCQUX1cS+x6/sLtfqxvEN5vWn702yMg5Ff5TdGUfHlaLCfA9POk1UEf36kwcqhK78XLfGgq+W1cTJCvgOjdxk2sOdo1gRVElpFH4DJ1l/VG1/C7AO33QPZNWH0TlWwje9FewHhr3Vq3xhfqmraChfPcRiHoFOS4rPFddeMtWq2oWZMj+DfhjJVW9WccTOJO7wWUH9HOdNHFEfQ6P1vKVq3oyXcWOVi248Me1YXEqfb1X1Lt/QuTbF0tEwfUThKmlCvqi/C0To4gf8WmZaU0OrJZzdozA9uL+99aZd6VduCkVzE9/OSZ5RLlPrDThitoCDTSFfeTMIwLlF3siGsVm9oc1GFex8zIx0FsLO5AIBSEa0kx20/2jUXNw==--HHZlzHqK+9w+/284--yCLnfdWp8Wvgf3buUq4RYg== \ No newline at end of file +lZTlGrYwVpMhsFEPbuQuWM50gk6t6SIFng3hUJ+X5JBbhEKv0fBrbwIw7//jGY/S00XTYPMf4H7nm7z2WyoLWWTUDIGoEZUKFPefkfytmTv6Com236i7z7/w6PkiLb9+16ixrTCKxcBeQ7esPctzPjKAeCPrCes8RQCePrOx+gwa1LmEb9JE31U631vVB+BQD1u2mTtlzfiImBC/u3kNJvTdtza9Quld1TUGTiamPQUo+GuHKdPDW6hHL/LdJ5vUcYkU1x+uqd0UeQYYEKBzy+5N7autn4qEVZTuOvxtDGCEq0QKKIDdXHJDThPjtPeO7yY97fPx9oijUMbLrdk+ZkQcS3f0s8iHGbV32AFzcldXasfJEzqQv61nXsaGfPHa944xkt0dG/0Jq25Y+GuZzsgitJ+A3lsAL6xfZ6wsZV1QfnwO6ironECskznRwSgneq83RILRdPy03ye6XQI6ykemmAr5JcOj6t5gRiovF0q+buuMkjDyxIO5YfRTZLGuePFRqR+Zp7kxaG8pGKwSISauPanGqV+27z8GH68hidlqk4NCZ5D9FE2idxF0WXon5BQN3cQmHSUlUsV9ovFt9A2ysmP3wAOH/SX5omOcc7h0fieVp95L34P+m+VPrG/ICTW5PWNmX0SiJwCx4nqtVtCaA9G0HkMkNLuKpg2xBjWzGGQIavXhw9/psFvNmDB/dQ==--HuHh1Wokx17kNpuw--gZGihS+vuQyynRk9ZchTuw== \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 5e8fcca..3255142 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -54,7 +54,10 @@ Rails.application.configure do config.file_watcher = ActiveSupport::EventedFileUpdateChecker # Mail - config.action_mailer.default_url_options = { host: 'localhost' } + config.action_mailer.default_url_options = { host: 'localhost:3000' } config.action_mailer.delivery_method = :smtp - config.action_mailer.smtp_settings = { address: 'localhost', port: 1025 } + config.action_mailer.smtp_settings = { + address: 'localhost', + port: 1025 + } end diff --git a/config/environments/production.rb b/config/environments/production.rb index d9fc517..99d3cb3 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -53,10 +53,6 @@ Rails.application.configure do config.action_mailer.perform_caching = false - # Ignore bad email addresses and do not raise email delivery errors. - # Set this to true and configure the email server for immediate delivery to raise delivery errors. - # config.action_mailer.raise_delivery_errors = false - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true @@ -79,4 +75,13 @@ Rails.application.configure do # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + + # Mail + config.action_mailer.raise_delivery_errors = true + config.action_mailer.default_url_options = { host: 'api01.turnie.re' } + config.action_mailer.delivery_method = :mailgun + config.action_mailer.mailgun_settings = { + api_key: Rails.application.credentials.dig(:mailgun, :api_key), + domain: Rails.application.credentials.dig(:mailgun, :domain) + } end diff --git a/config/initializers/devise_token_auth.rb b/config/initializers/devise_token_auth.rb index dec712e..4d3e626 100644 --- a/config/initializers/devise_token_auth.rb +++ b/config/initializers/devise_token_auth.rb @@ -47,4 +47,6 @@ DeviseTokenAuth.setup do |config| # If, however, you wish to integrate with legacy Devise authentication, you can # do so by enabling this flag. NOTE: This feature is highly experimental! # config.enable_standard_devise_support = false + + config.default_confirm_success_url = 'https://frontend01.turnie.re' end