From 01a3bfd6d5454701cc72bda1c2e19382d8df0c00 Mon Sep 17 00:00:00 2001 From: huylc Date: Wed, 28 Aug 2019 10:27:33 +0700 Subject: [PATCH] 222: reset-password --- .gitignore | 3 ++ Gemfile | 1 + Gemfile.lock | 3 ++ .../stylesheets/devise/application.scss | 4 +++ app/assets/stylesheets/manager/custom.scss | 2 ++ app/controllers/manager/admins_controller.rb | 6 ++-- .../manager/passwords_controller.rb | 7 +++++ app/models/user.rb | 1 - app/views/manager/passwords/edit.html.slim | 30 +++++++++++++++++++ app/views/manager/passwords/new.html.slim | 22 ++++++++++++++ config/application.yml.example | 18 +++++++++++ config/environments/development.rb | 13 +++++++- config/environments/production.rb | 14 +++++++++ config/initializers/devise.rb | 6 ++-- config/routes.rb | 2 +- 15 files changed, 122 insertions(+), 10 deletions(-) create mode 100644 app/controllers/manager/passwords_controller.rb create mode 100644 app/views/manager/passwords/edit.html.slim create mode 100644 app/views/manager/passwords/new.html.slim create mode 100644 config/application.yml.example diff --git a/.gitignore b/.gitignore index 7596f28..b4bae68 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ config/settings.local.yml config/settings/*.local.yml config/environments/*.local.yml + +# Ignore application configuration +/config/application.yml diff --git a/Gemfile b/Gemfile index 41d7e99..5548d08 100644 --- a/Gemfile +++ b/Gemfile @@ -23,6 +23,7 @@ gem "kaminari", "~> 1.1", ">= 1.1.1" gem "bootstrap4-kaminari-views" gem "config", "~> 2.0" gem "cocoon" +gem "figaro" group :development, :test do gem "byebug", platforms: %i[mri mingw x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index b270d5f..5cd758a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -125,6 +125,8 @@ GEM faker (2.1.2) i18n (>= 0.8) ffi (1.11.1) + figaro (1.1.1) + thor (~> 0.14) font-awesome-rails (4.7.0.5) railties (>= 3.2, < 6.1) globalid (0.4.2) @@ -325,6 +327,7 @@ DEPENDENCIES database_cleaner (~> 1.5) devise faker + figaro font-awesome-rails (~> 4.7, >= 4.7.0.5) jbuilder (~> 2.5) jquery-rails diff --git a/app/assets/stylesheets/devise/application.scss b/app/assets/stylesheets/devise/application.scss index 010af5f..e3a98d4 100644 --- a/app/assets/stylesheets/devise/application.scss +++ b/app/assets/stylesheets/devise/application.scss @@ -6,3 +6,7 @@ .custom-btn-login{ margin-top: 10px; } + +#error_explanation { + color: red; +} diff --git a/app/assets/stylesheets/manager/custom.scss b/app/assets/stylesheets/manager/custom.scss index 502f8a2..22dacc6 100644 --- a/app/assets/stylesheets/manager/custom.scss +++ b/app/assets/stylesheets/manager/custom.scss @@ -165,9 +165,11 @@ i.fa.fa-caret-down { -webkit-box-flex: 1; flex: 1 0 auto; } + .sticky-footer.bg-white { border-top: 1px solid #858796; } + .wrapper { width: 100%; } diff --git a/app/controllers/manager/admins_controller.rb b/app/controllers/manager/admins_controller.rb index 0feb619..54438db 100644 --- a/app/controllers/manager/admins_controller.rb +++ b/app/controllers/manager/admins_controller.rb @@ -50,11 +50,9 @@ def admin_params def update_admin(admin) if admin.save && admin.update_avatar(params[:admin][:avatar]) - flash.now[:success] = - t("messages.success.admins.update", id: admin.id) + flash.now[:success] = t("messages.success.admins.update", id: admin.id) else - flash.now[:danger] = - t("messages.failed.admins.update", id: admin.id) + flash.now[:danger] = t("messages.failed.admins.update", id: admin.id) end end diff --git a/app/controllers/manager/passwords_controller.rb b/app/controllers/manager/passwords_controller.rb new file mode 100644 index 0000000..5d91b0b --- /dev/null +++ b/app/controllers/manager/passwords_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Manager + class PasswordsController < Devise::PasswordsController + layout "sessions" + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 3b9cb7d..16c152f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,7 +10,6 @@ class User < ApplicationRecord validates :address, presence: true, length: { maximum: 255 } validates :type, presence: true validate :avatar_validate, if: -> { avatar.attached? } - has_one_attached :avatar def timeout_in diff --git a/app/views/manager/passwords/edit.html.slim b/app/views/manager/passwords/edit.html.slim new file mode 100644 index 0000000..3bfdc2a --- /dev/null +++ b/app/views/manager/passwords/edit.html.slim @@ -0,0 +1,30 @@ +.row.justify-content-center + .col-xl-10.col-lg-12.col-md-9 + .card.o-hidden.border-0.shadow-lg.my-5 + .card-body.p-0 + .row + .col-lg-6.d-none.d-lg-block.bg-register-image + .col-lg-6 + .p-5 + .text-center + h1.h4.text-gray-900.mb-2 + | Change your password + p.mb-4 + | Now, You can enter a new password for your account! + = form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| + = render "shared/manager/error_messages", object: resource + = f.hidden_field :reset_password_token + .form-group + = f.label :password, "New password" + - if @minimum_password_length + em + | (#{@minimum_password_length} characters minimum) + br/ + = f.password_field :password, autofocus: true, autocomplete: "new-password", class: "form-control" + .form-group + = f.label :password_confirmation, "Confirm new password" + = f.password_field :password_confirmation, autocomplete: "off", class: "form-control" + .actions + = f.submit "Change my password", class: "btn btn-primary btn-block" + .text-center + = link_to "Already have an account? Login!", new_admin_session_path diff --git a/app/views/manager/passwords/new.html.slim b/app/views/manager/passwords/new.html.slim new file mode 100644 index 0000000..c725898 --- /dev/null +++ b/app/views/manager/passwords/new.html.slim @@ -0,0 +1,22 @@ +.row.justify-content-center + .col-xl-10.col-lg-12.col-md-9 + .card.o-hidden.border-0.shadow-lg.my-5 + .card-body.p-0 + .row + .col-lg-6.d-none.d-lg-block.bg-password-image + .col-lg-6 + .p-5 + .text-center + h1.h4.text-gray-900.mb-2 + | Forgot Your Password? + p.mb-4 + | We get it, stuff happens. Just enter your email address below and we'll send you a link to reset your password! + = form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }, class: "user") do |f| + = render "shared/manager/error_messages", object: resource + .form-group + = f.label :email + = f.email_field :email, autofocus: true, autocomplete: "email", class: "form-control" + .actions + = f.submit "Reset Password", class: "btn btn-primary btn-block" + .text-center + = link_to "Already have an account? Login!", new_admin_session_path diff --git a/config/application.yml.example b/config/application.yml.example new file mode 100644 index 0000000..e474751 --- /dev/null +++ b/config/application.yml.example @@ -0,0 +1,18 @@ +# Add configuration values here, as shown below. +# +# pusher_app_id: "2954" +# pusher_key: 7381a978f7dd7f9a1117 +# pusher_secret: abdc3b896a0ffb85d373 +# stripe_api_key: sk_test_2J0l093xOyW72XUYJHE4Dv2r +# stripe_publishable_key: pk_test_ro9jV5SNwGb1yYlQfzG17LHK +# +# production: +# stripe_api_key: sk_live_EeHnL644i6zo4Iyq4v1KdV9H +# stripe_publishable_key: pk_live_9lcthxpSIHbGwmdO941O1XVU +GMAIL_USERNAME: example@gmail.com +GMAIL_PASSWORD: password +ADDRESS: smtp.gmail.com +production: + GMAIL_USERNAME: example@gmail.com + GMAIL_PASSWORD: password + DOMAIN: domain diff --git a/config/environments/development.rb b/config/environments/development.rb index 4a57a81..ecc38ed 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -33,7 +33,7 @@ config.active_storage.service = :local # Don't care if the mailer can't send. - config.action_mailer.raise_delivery_errors = false + config.action_mailer.raise_delivery_errors = true config.action_mailer.default_url_options = { host: "localhost", port: 3000 } @@ -47,6 +47,17 @@ # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true + config.action_mailer.delivery_method = :smtp + # SMTP settings for gmail + config.action_mailer.smtp_settings = { + :address => ENV["ADDRESS"], + :port => 587, + :user_name => ENV["GMAIL_USERNAME"], + :password => ENV["GMAIL_PASSWORD"], + :authentication => "plain", + :enable_starttls_auto => true + } + # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large diff --git a/config/environments/production.rb b/config/environments/production.rb index d0142c3..3f205bf 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -67,6 +67,20 @@ config.action_mailer.perform_caching = false + config.action_mailer.default_url_options = { :host => "example.host.com" } + + config.action_mailer.perform_caching = false + config.action_mailer.delivery_method = :smtp + # SMTP settings for gmail + config.action_mailer.smtp_settings = { + :address => ENV["ADDRESS"], + :port => 587, + :domain => ENV["DOMAIN"], + :user_name => ENV["GMAIL_USERNAME"], + :password => ENV["GMAIL_PASSWORD"], + :authentication => "plain", + :enable_starttls_auto => true + } # 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 diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index ba0fffd..a8f404f 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -17,7 +17,7 @@ # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class # with default "from" parameter. - config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com" + config.mailer_sender = "bookinghomestay@example.com" # Configure the class responsible to send e-mails. # config.mailer = 'Devise::Mailer' @@ -115,10 +115,10 @@ # Set up a pepper to generate the hashed password. # Send a notification to the original email when the user's email is changed. - # config.send_email_changed_notification = false + config.send_email_changed_notification = true # Send a notification email when the user's password is changed. - # config.send_password_change_notification = false + config.send_password_change_notification = true # ==> Configuration for :confirmable # A period that the user is allowed to access the website even without diff --git a/config/routes.rb b/config/routes.rb index 87cc9ee..b2d902c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true Rails.application.routes.draw do - devise_for :admins, controllers: { sessions: "manager/sessions" } + devise_for :admins, controllers: { sessions: "manager/sessions", passwords: "manager/passwords" } namespace :manager do root "members#index"