From aaa838dd77c9792f04b1dd948edd248c31a1fd98 Mon Sep 17 00:00:00 2001 From: ismail Akbudak Date: Tue, 21 Jun 2016 16:33:17 +0300 Subject: [PATCH] add user and admin mailer --- lib/cybele/app_builder.rb | 11 ++++++++++- templates/app/mailers/admin_mailer.rb | 4 ++-- templates/app/mailers/user_mailer.rb | 4 ++-- templates/app/models/admin.rb | 6 +++--- templates/app/models/user.rb | 2 +- .../app/views/admin_mailer/login_info.html.haml | 13 +++++++++++++ .../app/views/user_mailer/login_info.html.haml | 13 +++++++++++++ templates/config/locales/email.tr.yml | 4 ++-- 8 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 templates/app/views/admin_mailer/login_info.html.haml create mode 100644 templates/app/views/user_mailer/login_info.html.haml diff --git a/lib/cybele/app_builder.rb b/lib/cybele/app_builder.rb index e78d573..845a1cf 100644 --- a/lib/cybele/app_builder.rb +++ b/lib/cybele/app_builder.rb @@ -380,7 +380,11 @@ def copy_files say 'Coping files..' remove_file 'config/locales/en.yml' remove_file 'config/locales/simple_form.en.yml' - directory 'config/locales', 'config/locales' + copy_file 'config/locales/models.tr.yml', 'config/locales/models.tr.yml' + copy_file 'config/locales/show_for.tr.yml', 'config/locales/show_for.tr.yml' + copy_file 'config/locales/simple_form.tr.yml', 'config/locales/simple_form.tr.yml' + copy_file 'config/locales/view.tr.yml', 'config/locales/view.tr.yml' + copy_file 'config/locales/email.tr.yml', 'config/locales/email.tr.yml' # Model files remove_file 'app/models/admin.rb' @@ -428,6 +432,11 @@ def copy_files copy_file 'config/initializers/devise_async.rb', 'config/initializers/devise_async.rb' copy_file 'config/schedule.yml', 'config/schedule.yml' copy_file 'config/sidekiq.yml', 'config/sidekiq.yml' + + # Mailer files + directory 'app/mailers', 'app/mailers' + directory 'app/views/admin_mailer', 'app/views/admin_mailer' + directory 'app/views/user_mailer', 'app/views/user_mailer' end private diff --git a/templates/app/mailers/admin_mailer.rb b/templates/app/mailers/admin_mailer.rb index 07f329a..d6e9e8e 100644 --- a/templates/app/mailers/admin_mailer.rb +++ b/templates/app/mailers/admin_mailer.rb @@ -1,9 +1,9 @@ class AdminMailer < BaseMailer - def send_login_information(admin_id, password) + def login_info(admin_id, password) @admin = Admin.find admin_id @password = password - @subject = t('email.admin.send_login_information.title') + @subject = t('email.admin.login_info.title') mail(to: @admin.email, subject: @subject) end diff --git a/templates/app/mailers/user_mailer.rb b/templates/app/mailers/user_mailer.rb index 35509e8..286457b 100644 --- a/templates/app/mailers/user_mailer.rb +++ b/templates/app/mailers/user_mailer.rb @@ -1,9 +1,9 @@ class UserMailer < BaseMailer - def send_login_information(user_id, password) + def login_info(user_id, password) @user = User.find user_id @password = password - @subject = t('email.user.send_login_information.title') + @subject = t('email.user.login_info.title') mail(to: @user.email, subject: @subject) end diff --git a/templates/app/models/admin.rb b/templates/app/models/admin.rb index 04a6c59..269aae0 100644 --- a/templates/app/models/admin.rb +++ b/templates/app/models/admin.rb @@ -12,7 +12,7 @@ class Admin < ActiveRecord::Base :validatable # Validations - validates_presence_of :name, :email + validates_presence_of :name, :email, :surname validates :email, uniqueness: true # Callbacks @@ -31,7 +31,7 @@ def inactive_message end def full_name - "#{self.name}" + "#{self.name} #{self.surname}" end private @@ -46,7 +46,7 @@ def create_password end def send_login_info - AdminMailer.send_login_information(self.id, self.password).deliver_later! if self.is_generated_password + AdminMailer.login_info(self.id, self.password).deliver_later! if self.is_generated_password end end diff --git a/templates/app/models/user.rb b/templates/app/models/user.rb index 3c9ef47..c4ee0ef 100644 --- a/templates/app/models/user.rb +++ b/templates/app/models/user.rb @@ -49,6 +49,6 @@ def create_password end def send_login_info - UserMailer.send_login_information(self.id, self.password).deliver_later! if self.is_generated_password + UserMailer.login_info(self.id, self.password).deliver_later! if self.is_generated_password end end diff --git a/templates/app/views/admin_mailer/login_info.html.haml b/templates/app/views/admin_mailer/login_info.html.haml new file mode 100644 index 0000000..dff5eba --- /dev/null +++ b/templates/app/views/admin_mailer/login_info.html.haml @@ -0,0 +1,13 @@ +%h2= t('email.only_hello') + +%p= t('email.admin.login_info.first_info') +%p= "#{t('email.admin.login_info.second_info')} :" +%p + %strong= "#{t('activerecord.attributes.admin.email')} :" + = @admin.email +%p + %strong= "#{t('activerecord.attributes.admin.password')} :" + = @password +%p= link_to t('email.admin.login_info.btn_login'), new_admin_session_url + +%p= t('email.admin.login_info.last_info', link: new_admin_session_url ).html_safe \ No newline at end of file diff --git a/templates/app/views/user_mailer/login_info.html.haml b/templates/app/views/user_mailer/login_info.html.haml new file mode 100644 index 0000000..1b27830 --- /dev/null +++ b/templates/app/views/user_mailer/login_info.html.haml @@ -0,0 +1,13 @@ +%h2= t('email.only_hello') + +%p= t('email.user.login_info.first_info') +%p= t('email.user.login_info.second_info') +%p + %strong= "#{t('activerecord.attributes.user.email')} :" + = @user.email +%p + %strong= "#{t('activerecord.attributes.user.password')} :" + = @password +%p= link_to t('email.user.login_info.btn_login'), new_user_session_url + +%p= t('email.user.login_info.last_info', link: new_user_session_url ).html_safe \ No newline at end of file diff --git a/templates/config/locales/email.tr.yml b/templates/config/locales/email.tr.yml index 90c3e02..4f6700d 100644 --- a/templates/config/locales/email.tr.yml +++ b/templates/config/locales/email.tr.yml @@ -13,14 +13,14 @@ tr: desc2: Eğer bu isteği siz yapmadıysanız bu e-posta'yı yok sayınız. desc3: Parolanız yukarıdaki link'e erişip yeni bir parola oluşturmadığınız sürece değişmeyecektir. admin: - send_login_information: + login_info: title: Yönetici Giriş Bilgileriniz first_info: Portal üzerinden yönetici hesabınız oluşturuldu. Artık yönetici portalına giriş yapabilirsiniz. second_info: Giriş bilgileriniz şu şekildedir btn_login: Giriş yapmak için tıklayınız last_info: "Eğer 'Giriş Yap' butonunu kullanamıyorsanız giriş linkiniz şu şekildedir
Link : %{link}
Bu linki kopyalayıp tarayıcınıza yapıştırınız.." user: - send_login_information: + login_info: title: Kullanıcı Giriş Bilgileriniz first_info: Portal üzerinden kullanıcı hesabınız oluşturuldu. Artık kullanıcı portalına giriş yapabilirsiniz. second_info: Giriş bilgileriniz şu şekildedir