Skip to content

Commit

Permalink
Merge pull request #48 from CH1006/222
Browse files Browse the repository at this point in the history
222: reset-password
  • Loading branch information
N-Viet-ruby-dev authored Aug 28, 2019
2 parents e07686c + 01a3bfd commit 3e98169
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@
config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml

# Ignore application configuration
/config/application.yml
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/devise/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
.custom-btn-login{
margin-top: 10px;
}

#error_explanation {
color: red;
}
2 changes: 2 additions & 0 deletions app/assets/stylesheets/manager/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
}
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/manager/admins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions app/controllers/manager/passwords_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module Manager
class PasswordsController < Devise::PasswordsController
layout "sessions"
end
end
1 change: 0 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions app/views/manager/passwords/edit.html.slim
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions app/views/manager/passwords/new.html.slim
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions config/application.yml.example
Original file line number Diff line number Diff line change
@@ -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
13 changes: 12 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 3e98169

Please sign in to comment.