Skip to content

Commit

Permalink
Merge pull request #54 from CH1006/295
Browse files Browse the repository at this point in the history
295: confirmation mail
  • Loading branch information
Lương Việt Dũng authored Sep 3, 2019
2 parents 1cb612c + 428fc59 commit 3c75904
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 13 deletions.
5 changes: 5 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
//= require bootstrap
//= require custom
//= require toastr

/*global toastr*/
toastr.options = {
"timeOut": "1500",
}
2 changes: 1 addition & 1 deletion app/assets/javascripts/manager/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $(document).ready(function(){
"pageLength": 25,
"aaSorting": [],
"columnDefs": [
{ "orderable": false, "targets": [5] },
{ "orderable": false, "targets": [6] },
]
});

Expand Down
8 changes: 8 additions & 0 deletions app/assets/stylesheets/manager/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,11 @@ td.action{
.control-label{
font-weight: 700;
}

#member_table td{
word-break: break-word;
}

#admin_table td{
word-break: break-word;
}
3 changes: 3 additions & 0 deletions app/controllers/confirmations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ConfirmationsController < Devise::ConfirmationsController
layout "application"
end
1 change: 1 addition & 0 deletions app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

class Member < User
scope :newest, -> { order updated_at: :desc }
devise :confirmable
end
3 changes: 2 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
class User < ApplicationRecord
attr_accessor :not_update_password

devise :registerable, :database_authenticatable, :recoverable, :rememberable, :validatable, :timeoutable
devise :registerable, :database_authenticatable, :recoverable, :rememberable,
:validatable, :timeoutable
has_many :rooms

validates :name, presence: true, length: { maximum: 45 }
Expand Down
17 changes: 17 additions & 0 deletions app/views/confirmations/_new_form.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.account
.text-center
h1.h4.text-gray-900.mb-2
= t ".title"
p.mb-4
= t ".description"
= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f|
= render "shared/manager/error_messages", object: resource
.form-group
= f.label :email, class: "control-label"
= f.email_field :email, class: "form-control form-control-user", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email)
.actions
= f.submit t(".resend_btn"), class: "btn btn-primary btn-user btn-block"
.text-center
= link_to t(".login_link"), new_member_session_path, class: "small"
br
= link_to t(".signup_link"), new_member_registration_path, class: "small"
1 change: 1 addition & 0 deletions app/views/confirmations/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= render partial: "shared/view_content", locals: { yield_content: render(partial: "new_form") }
2 changes: 2 additions & 0 deletions app/views/manager/members/_member.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ tr.data-user
= t(".updated", time: time_ago_in_words(member.updated_at))
- else
= t(".created", time: time_ago_in_words(member.created_at))
td
= member.confirmed_at? ? t(".true") : t(".false")
td
= link_to t(".edit"), edit_manager_member_path(member), remote: true, class: "btn info align-btn"
= link_to t(".delete"), manager_member_path(member), method: :delete, \
Expand Down
1 change: 1 addition & 0 deletions app/views/manager/members/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ table#member_table.table.table-striped.table-bordered style=("width: 100%")
th = t(".email")
th = t(".address")
th = t(".access")
th = t(".active")
th = t(".action")
tbody.data-member
= render @members
Expand Down
3 changes: 3 additions & 0 deletions app/views/registrations/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
= f.label :email, class: "control-label col-lg-3 label-profile"
.col-lg-9
= f.email_field :email, class: "form-control form-profile"
- if devise_mapping.confirmable? && resource.pending_reconfirmation?
i
= t ".wait_confirm", unconfirm: "#{resource.unconfirmed_email}"
.form-group
.row.align-attr
= f.label :address, class: "control-label col-lg-3 label-profile"
Expand Down
2 changes: 2 additions & 0 deletions app/views/sessions/_new_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
= link_to t(".forgot_link"), new_password_path(resource_name), class: "small"
br
= link_to t(".signup_link"), new_member_registration_path, class: "small"
br
= link_to t(".resend_mail"), new_member_confirmation_path, class: "small"
9 changes: 9 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ en:
login_btn: "Log in"
forgot_link: "Forgot your password?"
signup_link: "Sign Up"
resend_mail: "Resend confirmation mail?"
registrations:
new_form:
title: "Sign Up"
Expand All @@ -96,6 +97,7 @@ en:
more: "More"
update: "Update"
back: "Back"
wait_confirm: "Currently waiting confirmation for: %{unconfirm}"
passwords:
new_form:
title: "Forgot Your Password?"
Expand All @@ -108,6 +110,13 @@ en:
valid_pass: "(%{num} characters minimum)"
change_btn: "Change my password"
login_link: "Already have an account? Login!"
confirmations:
new_form:
title: "Resend confirmation instructions"
description: "Enter your email to confirmation!"
resend_btn: "Resend confirmation"
login_link: "Log in"
signup_link: "Sign up"
activerecord:
errors:
models:
Expand Down
3 changes: 3 additions & 0 deletions config/locales/manager/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ en:
delete: "Delete"
updated: "Edited %{time}"
created: "Created %{time}"
true: "True"
false: "False"
index:
create: "Create"
all_member: "All members"
Expand All @@ -144,6 +146,7 @@ en:
address: "Address"
access: "Access"
action: "Action"
active: "Active"
new:
create: "Create"
new_member: "New Member"
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

Rails.application.routes.draw do
devise_for :admins, controllers: { sessions: "manager/sessions", passwords: "manager/passwords" }
devise_for :members, controllers: { registrations: "registrations", sessions: "sessions", passwords: "passwords" }
devise_for :members, controllers: { registrations: "registrations",
sessions: "sessions", passwords: "passwords", confirmations: "confirmations" }

namespace :manager do
root "members#index"
Expand Down
7 changes: 0 additions & 7 deletions db/migrate/20190815081049_devise_create_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,13 @@ def change
t.string :type
t.string :avatar


## Trackable
# t.integer :sign_in_count, default: 0, null: false
# t.datetime :current_sign_in_at
# t.datetime :last_sign_in_at
# t.string :current_sign_in_ip
# t.string :last_sign_in_ip

## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable

## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20190903072038_add_confirmable_to_devise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddConfirmableToDevise < ActiveRecord::Migration[5.2]
def change
add_column :users, :confirmation_token, :string
add_column :users, :confirmed_at, :datetime
add_column :users, :confirmation_sent_at, :datetime
add_column :users, :unconfirmed_email, :string
add_index :users, :confirmation_token, unique: true
end
end
7 changes: 6 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_08_28_005029) do
ActiveRecord::Schema.define(version: 2019_09_03_072038) do

create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name", null: false
Expand Down Expand Up @@ -116,6 +116,11 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "flag", default: false
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
Expand Down
6 changes: 4 additions & 2 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
Member.create!(email: "member@gmail.com",
name: "MemberBot",
password: "123123",
address: "Member page!")
address: "Member page!",
confirmed_at: Time.now)

50.times do |n|
name = Faker::Name.name
Expand All @@ -31,5 +32,6 @@
email: email,
password: password,
password_confirmation: password,
address: address)
address: address,
confirmed_at: Time.now)
end

0 comments on commit 3c75904

Please sign in to comment.