Devise Taking care of your users Andreas Bjärlestam 2011-02-22
<ul><ul><li>Andreas Bjärlestam </li></ul></ul><ul><ul><li>mailto:andreas@bjarlestam.com </li></ul></ul><ul><ul><li>http://...
So you are building a site with rails?
Hopefully you will have some users lining up...
They will probably f#&k things up USER USER
This could require quite some coding Signup page Login page Account confirmation mails Password reset mails Password reset...
What to do?
DEVISE can do it!
DEVISE <ul><li>User authentication </li></ul><ul><li>User signup </li></ul><ul><li>Account confirmaiton </li></ul><ul><li>...
Lets code…
Create a rails project <ul><li>$>rails new devise_test </li></ul><ul><li>$>cd devise_test </li></ul><ul><li>$>gem install ...
Create a User model <ul><li>$>rails generate devise User </li></ul><ul><li>$>rake db:migrate </li></ul>
Test it <ul><li>$>rails server </li></ul><ul><li>$>open http://localhost:3000/users/sign_up </li></ul><ul><li>$>open http:...
 
What happened?
configuration <ul><li>Configured routes  </li></ul><ul><li>config/routes.rb </li></ul><ul><li>devise_for :users </li></ul>...
User model <ul><li>class User < ActiveRecord::Base </li></ul><ul><li># Include default devise modules. Others available ar...
helpers available <ul><li>before_filter :authenticate_user! </li></ul><ul><li>user_signed_in? </li></ul><ul><li>current_us...
customize views <ul><li>$>rails generate devise:views </li></ul><ul><li>create  app/views/devise </li></ul><ul><li>create ...
 
Attributions <ul><li>http://www.flickr.com/photos/weelakeo/3815108314/ </li></ul><ul><li>http://www.flickr.com/photos/niki...
Devise
Upcoming SlideShare
Loading in...5
×

Devise

2,731

Published on

A short introduction to user authentication in Rails using Devise

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,731
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
18
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Devise

  1. 1. Devise Taking care of your users Andreas Bjärlestam 2011-02-22
  2. 2. <ul><ul><li>Andreas Bjärlestam </li></ul></ul><ul><ul><li>mailto:andreas@bjarlestam.com </li></ul></ul><ul><ul><li>http://twitter.com/bjarlestam </li></ul></ul>
  3. 3. So you are building a site with rails?
  4. 4. Hopefully you will have some users lining up...
  5. 5. They will probably f#&k things up USER USER
  6. 6. This could require quite some coding Signup page Login page Account confirmation mails Password reset mails Password reset page Checks and redirects
  7. 7. What to do?
  8. 8. DEVISE can do it!
  9. 9. DEVISE <ul><li>User authentication </li></ul><ul><li>User signup </li></ul><ul><li>Account confirmaiton </li></ul><ul><li>Password recovery </li></ul><ul><li>Remembering via cookie </li></ul><ul><li>Session expiration </li></ul><ul><li>Account locking </li></ul>http://github.com/plataformatec/devise
  10. 10. Lets code…
  11. 11. Create a rails project <ul><li>$>rails new devise_test </li></ul><ul><li>$>cd devise_test </li></ul><ul><li>$>gem install devise </li></ul><ul><li>$>echo &quot;gem 'devise'&quot; >> Gemfile </li></ul><ul><li>$>rails generate devise:install </li></ul><ul><li>$>cat config/routes.rb | sed s/'# root :to'/'root :to'/ >> config/routes.rb </li></ul>
  12. 12. Create a User model <ul><li>$>rails generate devise User </li></ul><ul><li>$>rake db:migrate </li></ul>
  13. 13. Test it <ul><li>$>rails server </li></ul><ul><li>$>open http://localhost:3000/users/sign_up </li></ul><ul><li>$>open http://localhost:3000/users/sign_in </li></ul><ul><li>$>open http://localhost:3000/users/sign_out </li></ul>
  14. 15. What happened?
  15. 16. configuration <ul><li>Configured routes </li></ul><ul><li>config/routes.rb </li></ul><ul><li>devise_for :users </li></ul><ul><li>Configuration file and localization </li></ul><ul><li>config/initializers/devise.rb </li></ul><ul><li>config/initializers/locales/devise.en.yml </li></ul>
  16. 17. User model <ul><li>class User < ActiveRecord::Base </li></ul><ul><li># Include default devise modules. Others available are: </li></ul><ul><li># :token_authenticatable, :confirmable, :lockable and :timeoutable </li></ul><ul><li>devise :database_authenticatable, :registerable, </li></ul><ul><li>:recoverable, :rememberable, :trackable, :validatable </li></ul><ul><li># Setup accessible (or protected) attributes for your model </li></ul><ul><li>attr_accessible :email, :password, :password_confirmation, :remember_me </li></ul><ul><li>end </li></ul>
  17. 18. helpers available <ul><li>before_filter :authenticate_user! </li></ul><ul><li>user_signed_in? </li></ul><ul><li>current_user </li></ul>
  18. 19. customize views <ul><li>$>rails generate devise:views </li></ul><ul><li>create app/views/devise </li></ul><ul><li>create app/views/devise/confirmations/new.html.erb </li></ul><ul><li>create app/views/devise/mailer/confirmation_instructions.html.erb </li></ul><ul><li>create app/views/devise/mailer/reset_password_instructions.html.erb </li></ul><ul><li>create app/views/devise/mailer/unlock_instructions.html.erb </li></ul><ul><li>create app/views/devise/passwords/edit.html.erb </li></ul><ul><li>create app/views/devise/passwords/new.html.erb </li></ul><ul><li>create app/views/devise/registrations/edit.html.erb </li></ul><ul><li>create app/views/devise/registrations/new.html.erb </li></ul><ul><li>create app/views/devise/sessions/new.html.erb </li></ul><ul><li>create app/views/devise/shared/_links.erb </li></ul><ul><li>create app/views/devise/unlocks/new.html.erb </li></ul>
  19. 21. Attributions <ul><li>http://www.flickr.com/photos/weelakeo/3815108314/ </li></ul><ul><li>http://www.flickr.com/photos/nikio/3899114449/ </li></ul><ul><li>http://www.flickr.com/photos/zigazou76/3636704536/ </li></ul><ul><li>http://www.flickr.com/photos/myklroventine-events/3832058915/ </li></ul><ul><li>http://www.flickr.com/photos/cokaigne/1401246909/ </li></ul><ul><li>http://www.flickr.com/photos/alpha/5433405433 </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×