From cfc1fbfd9f3e80ceae5995abb903d8850fa653ee Mon Sep 17 00:00:00 2001 From: Markus Graf Date: Thu, 30 Mar 2017 21:03:59 +0200 Subject: [PATCH] Added supporter model and send email with the password --- app/assets/stylesheets/application.sass | 6 +++--- app/controllers/supporters_controller.rb | 3 ++- app/mailers/supporter_mailer.rb | 3 ++- app/views/pages/spenden.de.slim | 1 - app/views/shared/_topnavigation.slim | 1 + app/views/supporter_mailer/welcome_email.de.slim | 9 +++++++++ app/views/supporter_mailer/welcome_email.fr.slim | 10 ++++++++-- app/views/supporter_mailer/welcome_email.it.slim | 8 ++++++++ config/environments/development.rb | 1 + config/environments/production.rb | 1 + config/locales/de.yml | 1 + spec/mailers/previews/supporter_mailer_preview.rb | 4 ++-- 12 files changed, 38 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/application.sass b/app/assets/stylesheets/application.sass index 29dfd39..fb31298 100644 --- a/app/assets/stylesheets/application.sass +++ b/app/assets/stylesheets/application.sass @@ -21,9 +21,9 @@ $font-size-base: 14px $navbar-padding-horizontal: none $navbar-default-link-color: #66903F $navbar-default-link-active-bg: #FFF -$font-size-h1: floor($font-size-base * 2) -$font-size-h2: floor($font-size-base * 1.8) -$font-size-h3: floor($font-size-base * 1.5) +$font-size-h1: floor($font-size-base * 1.8) +$font-size-h2: floor($font-size-base * 1.5) +$font-size-h3: floor($font-size-base * 1.2) @import "bootstrap-sprockets" @import "bootstrap" diff --git a/app/controllers/supporters_controller.rb b/app/controllers/supporters_controller.rb index 08fadaf..d88da26 100644 --- a/app/controllers/supporters_controller.rb +++ b/app/controllers/supporters_controller.rb @@ -7,8 +7,9 @@ class SupportersController < ApplicationController def create @supporter = Supporter.new supporter_form_params.merge(language: I18n.locale) + @supporter.password = random_password = SecureRandom.hex(5) if !input_to_fast? && @supporter.save - # SupporterMailer.welcome_email(@supporter).deliver_now + SupporterMailer.welcome_email(@supporter, random_password).deliver_now mailchimp_registration redirect_to thanks_path else diff --git a/app/mailers/supporter_mailer.rb b/app/mailers/supporter_mailer.rb index f763814..03d25ed 100644 --- a/app/mailers/supporter_mailer.rb +++ b/app/mailers/supporter_mailer.rb @@ -1,8 +1,9 @@ class SupporterMailer < ApplicationMailer include Roadie::Rails::Automatic - def welcome_email(supporter) + def welcome_email(supporter, random_password) @supporter = supporter + @password = random_password mail(to: @supporter.email, subject: I18n.t('welcome_email.subject')) end end diff --git a/app/views/pages/spenden.de.slim b/app/views/pages/spenden.de.slim index 2abf9a6..4135cb0 100644 --- a/app/views/pages/spenden.de.slim +++ b/app/views/pages/spenden.de.slim @@ -26,4 +26,3 @@ h3 Weitere Informationen zur Initiative findest du hier: ul li = link_to 'Initiativ-Seite', 'https://www.hanflegal.ch/initiative' li = link_to 'Onlineformular', root_path - li = link_to 'Initiativ-Forum', 'https://forum.hanflegal.ch' diff --git a/app/views/shared/_topnavigation.slim b/app/views/shared/_topnavigation.slim index a861015..f454fd9 100644 --- a/app/views/shared/_topnavigation.slim +++ b/app/views/shared/_topnavigation.slim @@ -4,3 +4,4 @@ = navbar_group id: 'topnav' do = navbar_item "Home", "/#{I18n.locale}" = navbar_item t('.donation'), spenden_path + = navbar_item t('.sign_in'), new_supporter_session_path if current_supporter.blank? diff --git a/app/views/supporter_mailer/welcome_email.de.slim b/app/views/supporter_mailer/welcome_email.de.slim index 211bb57..4786dc7 100644 --- a/app/views/supporter_mailer/welcome_email.de.slim +++ b/app/views/supporter_mailer/welcome_email.de.slim @@ -1,5 +1,14 @@ p Hallo #{@supporter.first_name}, du bist nun ein Teil der Bewegung! +p + | Um deine Angaben anzupassen kannst dich unter #{link_to new_supporter_session_url, new_supporter_session_url} mit folgenden Daten anmelden: + + dl.dl-horizontal + dt E-Mail + dd= @supporter.email + dt Passwort + dd= @password + p Wir informieren dich per E-Mail über die nächsten Schritte und kommen aktiv auf dich zu. Auf https://www.hanflegal.ch/initiative informieren wir über laufende Aktivitäten. p diff --git a/app/views/supporter_mailer/welcome_email.fr.slim b/app/views/supporter_mailer/welcome_email.fr.slim index 6a7b42b..6b9a056 100644 --- a/app/views/supporter_mailer/welcome_email.fr.slim +++ b/app/views/supporter_mailer/welcome_email.fr.slim @@ -1,9 +1,15 @@ p Salut #{@supporter.first_name}, Tu fais maintenant partie du mouvement! - - p Nous allons t’envoyer par e-mail les informations sur les prochaines étapes. Sur https://www.hanflegal.ch/initiative initiative nous informons des activités en cours. +p + | Pour régler vos données peut vous inscrire à #{link_to new_supporter_session_url, new_supporter_session_url} avec les données suivantes: + + dl.dl-horizontal + dt E-Mail + dd= @supporter.email + dt Mot de passe + dd= @password p | Que peux-tu faire? ul diff --git a/app/views/supporter_mailer/welcome_email.it.slim b/app/views/supporter_mailer/welcome_email.it.slim index 3232680..1fcbec1 100644 --- a/app/views/supporter_mailer/welcome_email.it.slim +++ b/app/views/supporter_mailer/welcome_email.it.slim @@ -2,6 +2,14 @@ p Ciao #{@supporter.first_name}, ora sei una parte del movimento! p Vi informeremo via e-mail circa i prossimi passi e diventare attivo. Su https://www.hanflegal.ch/initiative può informarsi sulle attività in corso. +p + | Per regolare i dati possono iscriversi a #{link_to new_supporter_session_url, new_supporter_session_url} i seguenti dati: + + dl.dl-horizontal + dt E-Mail + dd= @supporter.email + dt Password + dd= @password p | Che cosa puoi fare? ul diff --git a/config/environments/development.rb b/config/environments/development.rb index b458e0b..b0ea8ec 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -37,6 +37,7 @@ Rails.application.configure do # config.action_view.raise_on_missing_translations = true config.action_mailer.default_url_options = { host: 'localhost:3000' } + config.action_mailer.asset_host = 'http://localhost:3000' config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: 'localhost', port: 1025 } diff --git a/config/environments/production.rb b/config/environments/production.rb index 54a29b2..c1b465f 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -75,6 +75,7 @@ Rails.application.configure do config.log_formatter = ::Logger::Formatter.new config.action_mailer.default_url_options = { host: 'ch420.herokuapp.com' } + config.action_mailer.asset_host = 'https://ch420.herokuapp.com' config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { diff --git a/config/locales/de.yml b/config/locales/de.yml index fe15967..2c4b4b4 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -5,6 +5,7 @@ de: title_html: Ja, ich will Cannabis in der Schweiz legalisieren topnavigation: donation: Spenden + sign_in: Anmelden counter: supporters: "Unterstützer:" amount_of_supporters: Zurzeit haben wir %{amount} Unterstützer. diff --git a/spec/mailers/previews/supporter_mailer_preview.rb b/spec/mailers/previews/supporter_mailer_preview.rb index 23ffb92..34ef7cc 100644 --- a/spec/mailers/previews/supporter_mailer_preview.rb +++ b/spec/mailers/previews/supporter_mailer_preview.rb @@ -1,7 +1,7 @@ # Preview all emails at http://localhost:3000/rails/mailers/supporter_mailer class SupporterMailerPreview < ActionMailer::Preview def welcome - I18n.locale = :fr - SupporterMailer.welcome_email(Supporter.first) + I18n.locale = :de + SupporterMailer.welcome_email(Supporter.first, SecureRandom.hex(5)) end end