Skip to content

Commit c38dc9d

Browse files
author
Keith Thompson
authored
Merge pull request #5 from coderjourney/user-sign-up-and-authentication
Install and configure clearance
2 parents 483e796 + 82bb06b commit c38dc9d

File tree

11 files changed

+67
-2
lines changed

11 files changed

+67
-2
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ gem 'puma', '~> 3.0'
66
gem 'sass-rails', '~> 5.0'
77
gem 'uglifier', '>= 1.3.0'
88
gem 'jquery-rails'
9+
gem 'clearance', '~> 1.15.1'
910

1011
gem 'nokogiri', '1.6.8.1'
1112

Gemfile.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,17 @@ GEM
3939
minitest (~> 5.1)
4040
tzinfo (~> 1.1)
4141
arel (7.1.4)
42+
bcrypt (3.1.11)
4243
builder (3.2.2)
4344
byebug (9.0.6)
45+
clearance (1.15.1)
46+
bcrypt
47+
email_validator (~> 1.4)
48+
rails (>= 3.1)
4449
concurrent-ruby (1.0.2)
4550
debug_inspector (0.0.2)
51+
email_validator (1.6.0)
52+
activemodel
4653
erubis (2.7.0)
4754
execjs (2.7.0)
4855
ffi (1.9.14)
@@ -136,6 +143,7 @@ PLATFORMS
136143

137144
DEPENDENCIES
138145
byebug
146+
clearance (~> 1.15.1)
139147
jquery-rails
140148
listen (~> 3.0.5)
141149
nokogiri (= 1.6.8.1)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
class ApplicationController < ActionController::Base
2+
include Clearance::Controller
23
protect_from_forgery with: :exception
34
end

app/controllers/welcome_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class WelcomeController < ApplicationController
2+
def show
3+
end
4+
end

app/models/user.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class User < ApplicationRecord
2+
include Clearance::User
3+
end

app/views/layouts/application.html.erb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@
99
</head>
1010

1111
<body>
12-
<%= yield %>
12+
13+
<header>
14+
<% if signed_in? %>
15+
Signed in as: <%= current_user.email %>
16+
<%= button_to 'Sign out', sign_out_path, method: :delete %>
17+
<% else %>
18+
<%= link_to 'Sign in', sign_in_path %>
19+
<% end %>
20+
</header>
21+
22+
23+
<section>
24+
<div id="flash">
25+
<% flash.each do |key, value| %>
26+
<div class="flash <%= key %>"><%= value %></div>
27+
<% end %>
28+
</div>
29+
<%= yield %>
30+
</section>
1331
</body>
1432
</html>

app/views/welcome/show.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Welcome</h1>

config/initializers/clearance.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Clearance.configure do |config|
2+
config.mailer_sender = "reply@example.com"
3+
end

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Rails.application.routes.draw do
22
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
3+
root to: "welcome#show"
34
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class CreateUsers < ActiveRecord::Migration[5.0]
2+
def change
3+
create_table :users do |t|
4+
t.timestamps null: false
5+
t.string :email, null: false
6+
t.string :encrypted_password, limit: 128, null: false
7+
t.string :confirmation_token, limit: 128
8+
t.string :remember_token, limit: 128, null: false
9+
end
10+
11+
add_index :users, :email
12+
add_index :users, :remember_token
13+
end
14+
end

db/schema.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,20 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 0) do
13+
ActiveRecord::Schema.define(version: 20161117122331) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
1717

18+
create_table "users", force: :cascade do |t|
19+
t.datetime "created_at", null: false
20+
t.datetime "updated_at", null: false
21+
t.string "email", null: false
22+
t.string "encrypted_password", limit: 128, null: false
23+
t.string "confirmation_token", limit: 128
24+
t.string "remember_token", limit: 128, null: false
25+
t.index ["email"], name: "index_users_on_email", using: :btree
26+
t.index ["remember_token"], name: "index_users_on_remember_token", using: :btree
27+
end
28+
1829
end

0 commit comments

Comments
 (0)