Authentication Crash Course with Devise

#45 Authentication Crash Course with Devise
9/5/2016

Summary

Devise is a flexible authentication solution for Rails based on Warden. Learn how to add a stable authentication solution like Devise to your application.
9
rails security authentication 8:04 min

Summary

Gemfilegem 'devise'

If you want to use the bootstrap views, add the following to your gem file. Run bundle and and the generator.

Bootstrap Viewsgem 'devise-bootstrapped', github: 'king601/devise-bootstrapped'

bundle
rails generate devise:views:bootstrapped
Bashrails generate devise:install
rails generate devise User # MODEL
rake db:migrate
_navigation_links.html.erb

<li><%= link_to 'Protected', protected_path %></li> <% if user_signed_in? %>   <li><%= link_to current_user.email, edit_user_registration_path %></li>   <li><%= link_to 'Logout', destroy_user_session_path, method: :delete %></li> <% else %>   <li><%= link_to 'Login', new_user_session_path %></li> <% end %>

development.rbconfig.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
routes.rbRails.application.routes.draw do
  devise_for :users
  get :protected, to: 'visitors#protected'
  root 'visitors#index'
end

user.rbclass User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
end



1741179?v=3&s=64
king601 said about 1 year ago:

Thanks for using my Gem! I'm glad you liked it enough and featured it in the video! 

I'm open to suggestions for improvements, I'm sure there are improvements that can be made :)

635114?v=3&s=64
kobaltz said about 1 year ago:

One thought would be making a CLI utility so that you can generate the files without having to add/remove the gem. This way, it would be a globally accessible thing that could easily be used on other projects.

Photo
Rocela Durazo Verdugo said 2 months ago:

Ey nice video, can you add the facebook login ? that would be very cool.

Login to Comment