Commit 378f2fe3115cd1e5b4ffd07f5ac8c89ba617341b

Authored by Rafael Manzo
Committed by Rafael Manzo
1 parent 3e766a82

User management with Devise

Gemfile
... ... @@ -33,6 +33,9 @@ gem 'turbolinks'
33 33 # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
34 34 gem 'jbuilder', '~> 1.2'
35 35  
  36 +#For user authentication and everything else
  37 +gem 'devise', '~> 3.0.0.rc'
  38 +
36 39 group :doc do
37 40 # bundle exec rake doc:rails generates the API under doc/api.
38 41 gem 'sdoc', require: false
... ...
Gemfile.lock
... ... @@ -27,6 +27,7 @@ GEM
27 27 tzinfo (~> 0.3.37)
28 28 arel (4.0.0)
29 29 atomic (1.1.9)
  30 + bcrypt-ruby (3.0.1)
30 31 builder (3.1.4)
31 32 capybara (2.1.0)
32 33 mime-types (>= 1.16)
... ... @@ -51,6 +52,11 @@ GEM
51 52 cucumber (>= 1.1.8)
52 53 nokogiri (>= 1.5.0)
53 54 database_cleaner (1.0.1)
  55 + devise (3.0.0.rc)
  56 + bcrypt-ruby (~> 3.0)
  57 + orm_adapter (~> 0.1)
  58 + railties (>= 3.2.6, < 5)
  59 + warden (~> 1.2.1)
54 60 diff-lcs (1.2.4)
55 61 erubis (2.7.0)
56 62 execjs (1.4.0)
... ... @@ -82,6 +88,7 @@ GEM
82 88 multi_json (1.7.7)
83 89 nokogiri (1.6.0)
84 90 mini_portile (~> 0.5.0)
  91 + orm_adapter (0.4.0)
85 92 polyglot (0.3.3)
86 93 rack (1.5.2)
87 94 rack-test (0.6.2)
... ... @@ -154,6 +161,8 @@ GEM
154 161 uglifier (2.1.1)
155 162 execjs (>= 0.3.0)
156 163 multi_json (~> 1.0, >= 1.0.2)
  164 + warden (1.2.1)
  165 + rack (>= 1.0)
157 166 xpath (2.0.0)
158 167 nokogiri (~> 1.3)
159 168  
... ... @@ -164,6 +173,7 @@ DEPENDENCIES
164 173 coffee-rails (~> 4.0.0)
165 174 cucumber-rails
166 175 database_cleaner
  176 + devise (~> 3.0.0.rc)
167 177 factory_girl_rails
168 178 jbuilder (~> 1.2)
169 179 jquery-rails
... ...
app/controllers/application_controller.rb
... ... @@ -2,4 +2,6 @@ class ApplicationController &lt; ActionController::Base
2 2 # Prevent CSRF attacks by raising an exception.
3 3 # For APIs, you may want to use :null_session instead.
4 4 protect_from_forgery with: :exception
  5 +
  6 + add_flash_types :error, :alert
5 7 end
... ...
app/controllers/home_controller.rb 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +class HomeController < ApplicationController
  2 + def index
  3 + end
  4 +end
... ...
app/controllers/registrations_controller.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +class RegistrationsController < Devise::RegistrationsController
  2 + def sign_up_params
  3 + #FIXME: Maybe there should be a better way to do this, but it's still not been documented on Devise.
  4 + params.require(:user).permit(:email, :password, :password_confirmation, :name)
  5 + end
  6 +end
0 7 \ No newline at end of file
... ...
app/models/user.rb
1 1 class User < ActiveRecord::Base
  2 + # Include default devise modules. Others available are:
  3 + # :token_authenticatable, :confirmable,
  4 + # :lockable, :timeoutable and :omniauthable
  5 + devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
  6 +
2 7 validates :name, presence: true
3 8 validates :email, presence: true
4 9 validates :email, uniqueness: true
  10 +
  11 + # Alert: when adding new parameters to this model, they should also be added to registrations_controller
5 12 end
... ...
app/views/devise/confirmations/new.html.erb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +<h2>Resend confirmation instructions</h2>
  2 +
  3 +<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
  4 + <%= devise_error_messages! %>
  5 +
  6 + <div><%= f.label :email %><br />
  7 + <%= f.email_field :email, :autofocus => true %></div>
  8 +
  9 + <div><%= f.submit "Resend confirmation instructions" %></div>
  10 +<% end %>
  11 +
  12 +<%= render "devise/shared/links" %>
... ...
app/views/devise/mailer/confirmation_instructions.html.erb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +<p>Welcome <%= @email %>!</p>
  2 +
  3 +<p>You can confirm your account email through the link below:</p>
  4 +
  5 +<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
... ...
app/views/devise/mailer/reset_password_instructions.html.erb 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +<p>Hello <%= @resource.email %>!</p>
  2 +
  3 +<p>Someone has requested a link to change your password. You can do this through the link below.</p>
  4 +
  5 +<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
  6 +
  7 +<p>If you didn't request this, please ignore this email.</p>
  8 +<p>Your password won't change until you access the link above and create a new one.</p>
... ...
app/views/devise/mailer/unlock_instructions.html.erb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +<p>Hello <%= @resource.email %>!</p>
  2 +
  3 +<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
  4 +
  5 +<p>Click the link below to unlock your account:</p>
  6 +
  7 +<p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>
... ...
app/views/devise/passwords/edit.html.erb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +<h2>Change your password</h2>
  2 +
  3 +<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
  4 + <%= devise_error_messages! %>
  5 + <%= f.hidden_field :reset_password_token %>
  6 +
  7 + <div><%= f.label :password, "New password" %><br />
  8 + <%= f.password_field :password, :autofocus => true %></div>
  9 +
  10 + <div><%= f.label :password_confirmation, "Confirm new password" %><br />
  11 + <%= f.password_field :password_confirmation %></div>
  12 +
  13 + <div><%= f.submit "Change my password" %></div>
  14 +<% end %>
  15 +
  16 +<%= render "devise/shared/links" %>
... ...
app/views/devise/passwords/new.html.erb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +<h2>Forgot your password?</h2>
  2 +
  3 +<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
  4 + <%= devise_error_messages! %>
  5 +
  6 + <div><%= f.label :email %><br />
  7 + <%= f.email_field :email, :autofocus => true %></div>
  8 +
  9 + <div><%= f.submit "Send me reset password instructions" %></div>
  10 +<% end %>
  11 +
  12 +<%= render "devise/shared/links" %>
... ...
app/views/devise/registrations/edit.html.erb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +<h2>Edit <%= resource_name.to_s.humanize %></h2>
  2 +
  3 +<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
  4 + <%= devise_error_messages! %>
  5 +
  6 + <div><%= f.label :name %><br />
  7 + <%= f.text_field :name, :autofocus => true %></div>
  8 +
  9 + <div><%= f.label :email %><br />
  10 + <%= f.email_field :email %></div>
  11 +
  12 + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
  13 + <div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
  14 + <% end %>
  15 +
  16 + <div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
  17 + <%= f.password_field :password, :autocomplete => "off" %></div>
  18 +
  19 + <div><%= f.label :password_confirmation %><br />
  20 + <%= f.password_field :password_confirmation %></div>
  21 +
  22 + <div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
  23 + <%= f.password_field :current_password %></div>
  24 +
  25 + <div><%= f.submit "Update" %></div>
  26 +<% end %>
  27 +
  28 +<h3>Cancel my account</h3>
  29 +
  30 +<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %></p>
  31 +
  32 +<%= link_to "Back", root_path %>
... ...
app/views/devise/registrations/new.html.erb 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +<h2>Sign up</h2>
  2 +
  3 +<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  4 + <%= devise_error_messages! %>
  5 +
  6 + <div><%= f.label :name %><br />
  7 + <%= f.text_field :name, :autofocus => true %></div>
  8 +
  9 + <div><%= f.label :email %><br />
  10 + <%= f.email_field :email %></div>
  11 +
  12 + <div><%= f.label :password %><br />
  13 + <%= f.password_field :password %></div>
  14 +
  15 + <div><%= f.label :password_confirmation %><br />
  16 + <%= f.password_field :password_confirmation %></div>
  17 +
  18 + <div><%= f.submit "Sign up" %></div>
  19 +<% end %>
  20 +
  21 +<%= render "devise/shared/links" %>
... ...
app/views/devise/sessions/new.html.erb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +<h2>Sign in</h2>
  2 +
  3 +<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
  4 + <div><%= f.label :email %><br />
  5 + <%= f.email_field :email, :autofocus => true %></div>
  6 +
  7 + <div><%= f.label :password %><br />
  8 + <%= f.password_field :password %></div>
  9 +
  10 + <% if devise_mapping.rememberable? -%>
  11 + <div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
  12 + <% end -%>
  13 +
  14 + <div><%= f.submit "Sign in" %></div>
  15 +<% end %>
  16 +
  17 +<%= render "devise/shared/links" %>
... ...
app/views/devise/shared/_links.erb 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +<%- if controller_name != 'sessions' %>
  2 + <%= link_to "Sign in", new_session_path(resource_name) %><br />
  3 +<% end -%>
  4 +
  5 +<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
  6 + <%= link_to "Sign up", new_registration_path(resource_name) %><br />
  7 +<% end -%>
  8 +
  9 +<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
  10 + <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
  11 +<% end -%>
  12 +
  13 +<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
  14 + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
  15 +<% end -%>
  16 +
  17 +<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
  18 + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
  19 +<% end -%>
  20 +
  21 +<%- if devise_mapping.omniauthable? %>
  22 + <%- resource_class.omniauth_providers.each do |provider| %>
  23 + <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
  24 + <% end -%>
  25 +<% end -%>
0 26 \ No newline at end of file
... ...
app/views/devise/unlocks/new.html.erb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +<h2>Resend unlock instructions</h2>
  2 +
  3 +<%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
  4 + <%= devise_error_messages! %>
  5 +
  6 + <div><%= f.label :email %><br />
  7 + <%= f.email_field :email, :autofocus => true %></div>
  8 +
  9 + <div><%= f.submit "Resend unlock instructions" %></div>
  10 +<% end %>
  11 +
  12 +<%= render "devise/shared/links" %>
... ...
app/views/home/index.html.erb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +<% if user_signed_in? %>
  2 + <%= link_to('Edit', edit_user_registration_path) %>
  3 + <%= link_to('Logout', destroy_user_session_path, :method => :delete) %>
  4 +<% else %>
  5 + <%= link_to('Login', new_user_session_path) %>
  6 + <%= link_to('Sign Up', user_registration_path) %>
  7 +<% end %>
0 8 \ No newline at end of file
... ...
app/views/layouts/application.html.erb
... ... @@ -20,6 +20,9 @@
20 20 </head>
21 21  
22 22 <body>
  23 + <p class="notice"><%= notice %></p>
  24 + <p class="alert"><%= alert %></p>
  25 +
23 26  
24 27 <%= yield %>
25 28  
... ...
config/environments/development.rb
... ... @@ -26,4 +26,7 @@ Mezuro::Application.configure do
26 26 # This option may cause significant delays in view rendering with a large
27 27 # number of complex assets.
28 28 config.assets.debug = true
  29 +
  30 + #Root URL for ActionMailer
  31 + config.action_mailer.default_url_options = { :host => 'localhost:3000' }
29 32 end
... ...
config/environments/production.rb
... ... @@ -77,4 +77,8 @@ Mezuro::Application.configure do
77 77  
78 78 # Use default logging formatter so that PID and timestamp are not suppressed.
79 79 config.log_formatter = ::Logger::Formatter.new
  80 +
  81 + # Root URL for ActionMailer
  82 + # FIXME: Before sending to production review this
  83 + config.action_mailer.default_url_options = { :host => 'mezuro.org' }
80 84 end
... ...
config/environments/test.rb
... ... @@ -33,4 +33,7 @@ Mezuro::Application.configure do
33 33  
34 34 # Print deprecation notices to the stderr
35 35 config.active_support.deprecation = :stderr
  36 +
  37 + #Root URL for ActionMailer
  38 + config.action_mailer.default_url_options = { :host => 'localhost:3000' }
36 39 end
... ...
config/initializers/devise.rb 0 → 100644
... ... @@ -0,0 +1,246 @@
  1 +# Use this hook to configure devise mailer, warden hooks and so forth.
  2 +# Many of these configuration options can be set straight in your model.
  3 +Devise.setup do |config|
  4 + # ==> Mailer Configuration
  5 + # Configure the e-mail address which will be shown in Devise::Mailer,
  6 + # note that it will be overwritten if you use your own mailer class with default "from" parameter.
  7 + config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
  8 +
  9 + # Configure the class responsible to send e-mails.
  10 + # config.mailer = "Devise::Mailer"
  11 +
  12 + # ==> ORM configuration
  13 + # Load and configure the ORM. Supports :active_record (default) and
  14 + # :mongoid (bson_ext recommended) by default. Other ORMs may be
  15 + # available as additional gems.
  16 + require 'devise/orm/active_record'
  17 +
  18 + # ==> Configuration for any authentication mechanism
  19 + # Configure which keys are used when authenticating a user. The default is
  20 + # just :email. You can configure it to use [:username, :subdomain], so for
  21 + # authenticating a user, both parameters are required. Remember that those
  22 + # parameters are used only when authenticating and not when retrieving from
  23 + # session. If you need permissions, you should implement that in a before filter.
  24 + # You can also supply a hash where the value is a boolean determining whether
  25 + # or not authentication should be aborted when the value is not present.
  26 + # config.authentication_keys = [ :email ]
  27 +
  28 + # Configure parameters from the request object used for authentication. Each entry
  29 + # given should be a request method and it will automatically be passed to the
  30 + # find_for_authentication method and considered in your model lookup. For instance,
  31 + # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
  32 + # The same considerations mentioned for authentication_keys also apply to request_keys.
  33 + # config.request_keys = []
  34 +
  35 + # Configure which authentication keys should be case-insensitive.
  36 + # These keys will be downcased upon creating or modifying a user and when used
  37 + # to authenticate or find a user. Default is :email.
  38 + config.case_insensitive_keys = [ :email ]
  39 +
  40 + # Configure which authentication keys should have whitespace stripped.
  41 + # These keys will have whitespace before and after removed upon creating or
  42 + # modifying a user and when used to authenticate or find a user. Default is :email.
  43 + config.strip_whitespace_keys = [ :email ]
  44 +
  45 + # Tell if authentication through request.params is enabled. True by default.
  46 + # It can be set to an array that will enable params authentication only for the
  47 + # given strategies, for example, `config.params_authenticatable = [:database]` will
  48 + # enable it only for database (email + password) authentication.
  49 + # config.params_authenticatable = true
  50 +
  51 + # Tell if authentication through HTTP Auth is enabled. False by default.
  52 + # It can be set to an array that will enable http authentication only for the
  53 + # given strategies, for example, `config.http_authenticatable = [:token]` will
  54 + # enable it only for token authentication. The supported strategies are:
  55 + # :database = Support basic authentication with authentication key + password
  56 + # :token = Support basic authentication with token authentication key
  57 + # :token_options = Support token authentication with options as defined in
  58 + # http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Token.html
  59 + # config.http_authenticatable = false
  60 +
  61 + # If http headers should be returned for AJAX requests. True by default.
  62 + # config.http_authenticatable_on_xhr = true
  63 +
  64 + # The realm used in Http Basic Authentication. "Application" by default.
  65 + # config.http_authentication_realm = "Application"
  66 +
  67 + # It will change confirmation, password recovery and other workflows
  68 + # to behave the same regardless if the e-mail provided was right or wrong.
  69 + # Does not affect registerable.
  70 + # config.paranoid = true
  71 +
  72 + # By default Devise will store the user in session. You can skip storage for
  73 + # :http_auth and :token_auth by adding those symbols to the array below.
  74 + # Notice that if you are skipping storage for all authentication paths, you
  75 + # may want to disable generating routes to Devise's sessions controller by
  76 + # passing :skip => :sessions to `devise_for` in your config/routes.rb
  77 + config.skip_session_storage = [:http_auth]
  78 +
  79 + # ==> Configuration for :database_authenticatable
  80 + # For bcrypt, this is the cost for hashing the password and defaults to 10. If
  81 + # using other encryptors, it sets how many times you want the password re-encrypted.
  82 + #
  83 + # Limiting the stretches to just one in testing will increase the performance of
  84 + # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
  85 + # a value less than 10 in other environments.
  86 + config.stretches = Rails.env.test? ? 1 : 10
  87 +
  88 + # Setup a pepper to generate the encrypted password.
  89 + # config.pepper = "72de9806eb45d3895a8b01bac6f84cee19723313257405cd6cc3a3947fe531d06708322069b6c9c63a7ef0105d67c0608ed27bfb7de0796110733327f685fe2f"
  90 +
  91 + # ==> Configuration for :confirmable
  92 + # A period that the user is allowed to access the website even without
  93 + # confirming his account. For instance, if set to 2.days, the user will be
  94 + # able to access the website for two days without confirming his account,
  95 + # access will be blocked just in the third day. Default is 0.days, meaning
  96 + # the user cannot access the website without confirming his account.
  97 + # config.allow_unconfirmed_access_for = 2.days
  98 +
  99 + # A period that the user is allowed to confirm their account before their
  100 + # token becomes invalid. For example, if set to 3.days, the user can confirm
  101 + # their account within 3 days after the mail was sent, but on the fourth day
  102 + # their account can't be confirmed with the token any more.
  103 + # Default is nil, meaning there is no restriction on how long a user can take
  104 + # before confirming their account.
  105 + # config.confirm_within = 3.days
  106 +
  107 + # If true, requires any email changes to be confirmed (exactly the same way as
  108 + # initial account confirmation) to be applied. Requires additional unconfirmed_email
  109 + # db field (see migrations). Until confirmed new email is stored in
  110 + # unconfirmed email column, and copied to email column on successful confirmation.
  111 + config.reconfirmable = true
  112 +
  113 + # Defines which key will be used when confirming an account
  114 + # config.confirmation_keys = [ :email ]
  115 +
  116 + # ==> Configuration for :rememberable
  117 + # The time the user will be remembered without asking for credentials again.
  118 + # config.remember_for = 2.weeks
  119 +
  120 + # If true, extends the user's remember period when remembered via cookie.
  121 + # config.extend_remember_period = false
  122 +
  123 + # Options to be passed to the created cookie. For instance, you can set
  124 + # :secure => true in order to force SSL only cookies.
  125 + # config.rememberable_options = {}
  126 +
  127 + # ==> Configuration for :validatable
  128 + # Range for password length. Default is 8..128.
  129 + config.password_length = 8..128
  130 +
  131 + # Email regex used to validate email formats. It simply asserts that
  132 + # one (and only one) @ exists in the given string. This is mainly
  133 + # to give user feedback and not to assert the e-mail validity.
  134 + # config.email_regexp = /\A[^@]+@[^@]+\z/
  135 +
  136 + # ==> Configuration for :timeoutable
  137 + # The time you want to timeout the user session without activity. After this
  138 + # time the user will be asked for credentials again. Default is 30 minutes.
  139 + # config.timeout_in = 30.minutes
  140 +
  141 + # If true, expires auth token on session timeout.
  142 + # config.expire_auth_token_on_timeout = false
  143 +
  144 + # ==> Configuration for :lockable
  145 + # Defines which strategy will be used to lock an account.
  146 + # :failed_attempts = Locks an account after a number of failed attempts to sign in.
  147 + # :none = No lock strategy. You should handle locking by yourself.
  148 + # config.lock_strategy = :failed_attempts
  149 +
  150 + # Defines which key will be used when locking and unlocking an account
  151 + # config.unlock_keys = [ :email ]
  152 +
  153 + # Defines which strategy will be used to unlock an account.
  154 + # :email = Sends an unlock link to the user email
  155 + # :time = Re-enables login after a certain amount of time (see :unlock_in below)
  156 + # :both = Enables both strategies
  157 + # :none = No unlock strategy. You should handle unlocking by yourself.
  158 + # config.unlock_strategy = :both
  159 +
  160 + # Number of authentication tries before locking an account if lock_strategy
  161 + # is failed attempts.
  162 + # config.maximum_attempts = 20
  163 +
  164 + # Time interval to unlock the account if :time is enabled as unlock_strategy.
  165 + # config.unlock_in = 1.hour
  166 +
  167 + # ==> Configuration for :recoverable
  168 + #
  169 + # Defines which key will be used when recovering the password for an account
  170 + # config.reset_password_keys = [ :email ]
  171 +
  172 + # Time interval you can reset your password with a reset password key.
  173 + # Don't put a too small interval or your users won't have the time to
  174 + # change their passwords.
  175 + config.reset_password_within = 6.hours
  176 +
  177 + # ==> Configuration for :encryptable
  178 + # Allow you to use another encryption algorithm besides bcrypt (default). You can use
  179 + # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
  180 + # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
  181 + # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
  182 + # REST_AUTH_SITE_KEY to pepper).
  183 + #
  184 + # Require the `devise-encryptable` gem when using anything other than bcrypt
  185 + # config.encryptor = :sha512
  186 +
  187 + # ==> Configuration for :token_authenticatable
  188 + # Defines name of the authentication token params key
  189 + # config.token_authentication_key = :auth_token
  190 +
  191 + # ==> Scopes configuration
  192 + # Turn scoped views on. Before rendering "sessions/new", it will first check for
  193 + # "users/sessions/new". It's turned off by default because it's slower if you
  194 + # are using only default views.
  195 + # config.scoped_views = false
  196 +
  197 + # Configure the default scope given to Warden. By default it's the first
  198 + # devise role declared in your routes (usually :user).
  199 + # config.default_scope = :user
  200 +
  201 + # Set this configuration to false if you want /users/sign_out to sign out
  202 + # only the current scope. By default, Devise signs out all scopes.
  203 + # config.sign_out_all_scopes = true
  204 +
  205 + # ==> Navigation configuration
  206 + # Lists the formats that should be treated as navigational. Formats like
  207 + # :html, should redirect to the sign in page when the user does not have
  208 + # access, but formats like :xml or :json, should return 401.
  209 + #
  210 + # If you have any extra navigational formats, like :iphone or :mobile, you
  211 + # should add them to the navigational formats lists.
  212 + #
  213 + # The "*/*" below is required to match Internet Explorer requests.
  214 + # config.navigational_formats = ["*/*", :html]
  215 +
  216 + # The default HTTP method used to sign out a resource. Default is :delete.
  217 + config.sign_out_via = :delete
  218 +
  219 + # ==> OmniAuth
  220 + # Add a new OmniAuth provider. Check the wiki for more information on setting
  221 + # up on your models and hooks.
  222 + # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
  223 +
  224 + # ==> Warden configuration
  225 + # If you want to use other strategies, that are not supported by Devise, or
  226 + # change the failure app, you can configure them inside the config.warden block.
  227 + #
  228 + # config.warden do |manager|
  229 + # manager.intercept_401 = false
  230 + # manager.default_strategies(:scope => :user).unshift :some_external_strategy
  231 + # end
  232 +
  233 + # ==> Mountable engine configurations
  234 + # When using Devise inside an engine, let's call it `MyEngine`, and this engine
  235 + # is mountable, there are some extra configurations to be taken into account.
  236 + # The following options are available, assuming the engine is mounted as:
  237 + #
  238 + # mount MyEngine, at: "/my_engine"
  239 + #
  240 + # The router that invoked `devise_for`, in the example above, would be:
  241 + # config.router_name = :my_engine
  242 + #
  243 + # When using omniauth, Devise cannot automatically set Omniauth path,
  244 + # so you need to do it manually. For the users scope, it would be:
  245 + # config.omniauth_path_prefix = "/my_engine/users/auth"
  246 +end
... ...
config/locales/devise.en.yml 0 → 100644
... ... @@ -0,0 +1,59 @@
  1 +# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
  2 +
  3 +en:
  4 + devise:
  5 + confirmations:
  6 + confirmed: "Your account was successfully confirmed. You are now signed in."
  7 + send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes."
  8 + send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
  9 + failure:
  10 + already_authenticated: "You are already signed in."
  11 + inactive: "Your account was not activated yet."
  12 + invalid: "Invalid email or password."
  13 + invalid_token: "Invalid authentication token."
  14 + locked: "Your account is locked."
  15 + not_found_in_database: "Invalid email or password."
  16 + timeout: "Your session expired, please sign in again to continue."
  17 + unauthenticated: "You need to sign in or sign up before continuing."
  18 + unconfirmed: "You have to confirm your account before continuing."
  19 + mailer:
  20 + confirmation_instructions:
  21 + subject: "Confirmation instructions"
  22 + reset_password_instructions:
  23 + subject: "Reset password instructions"
  24 + unlock_instructions:
  25 + subject: "Unlock Instructions"
  26 + omniauth_callbacks:
  27 + failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
  28 + success: "Successfully authenticated from %{kind} account."
  29 + passwords:
  30 + no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
  31 + send_instructions: "You will receive an email with instructions about how to reset your password in a few minutes."
  32 + send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
  33 + updated: "Your password was changed successfully. You are now signed in."
  34 + updated_not_active: "Your password was changed successfully."
  35 + registrations:
  36 + destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon."
  37 + signed_up: "Welcome! You have signed up successfully."
  38 + signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
  39 + signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
  40 + signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account."
  41 + update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
  42 + updated: "You updated your account successfully."
  43 + sessions:
  44 + signed_in: "Signed in successfully."
  45 + signed_out: "Signed out successfully."
  46 + unlocks:
  47 + send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes."
  48 + send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."
  49 + unlocked: "Your account has been unlocked successfully. Please sign in to continue."
  50 + errors:
  51 + messages:
  52 + already_confirmed: "was already confirmed, please try signing in"
  53 + confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
  54 + expired: "has expired, please request a new one"
  55 + not_found: "not found"
  56 + not_locked: "was not locked"
  57 + not_saved:
  58 + one: "1 error prohibited this %{resource} from being saved:"
  59 + other: "%{count} errors prohibited this %{resource} from being saved:"
... ...
config/routes.rb
1 1 Mezuro::Application.routes.draw do
  2 + devise_for :users, :controllers => { :registrations => "registrations" }
  3 +
  4 + root "home#index"
  5 +
2 6 # The priority is based upon order of creation: first created -> highest priority.
3 7 # See how all your routes lay out with "rake routes".
4 8  
... ...
db/migrate/20130627170417_create_users.rb
1 1 class CreateUsers < ActiveRecord::Migration
2 2 def change
3 3 create_table :users do |t|
4   - t.string :name
5   - t.string :email
  4 + t.string :name, :null => false, :default => ""
  5 + t.string :email, :null => false, :default => ""
6 6  
7 7 t.timestamps
8 8 end
... ...
db/migrate/20130627183652_add_devise_to_users.rb 0 → 100644
... ... @@ -0,0 +1,52 @@
  1 +class AddDeviseToUsers < ActiveRecord::Migration
  2 + def self.up
  3 + change_table(:users) do |t|
  4 + ## Database authenticatable
  5 + t.string :encrypted_password, :null => false, :default => ""
  6 +
  7 + ## Recoverable
  8 + t.string :reset_password_token
  9 + t.datetime :reset_password_sent_at
  10 +
  11 + ## Rememberable
  12 + t.datetime :remember_created_at
  13 +
  14 + ## Trackable
  15 + t.integer :sign_in_count, :default => 0
  16 + t.datetime :current_sign_in_at
  17 + t.datetime :last_sign_in_at
  18 + t.string :current_sign_in_ip
  19 + t.string :last_sign_in_ip
  20 +
  21 + ## Confirmable
  22 + # t.string :confirmation_token
  23 + # t.datetime :confirmed_at
  24 + # t.datetime :confirmation_sent_at
  25 + # t.string :unconfirmed_email # Only if using reconfirmable
  26 +
  27 + ## Lockable
  28 + # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
  29 + # t.string :unlock_token # Only if unlock strategy is :email or :both
  30 + # t.datetime :locked_at
  31 +
  32 + ## Token authenticatable
  33 + # t.string :authentication_token
  34 +
  35 +
  36 + # Uncomment below if timestamps were not included in your original model.
  37 + # t.timestamps
  38 + end
  39 +
  40 + add_index :users, :email, :unique => true
  41 + add_index :users, :reset_password_token, :unique => true
  42 + # add_index :users, :confirmation_token, :unique => true
  43 + # add_index :users, :unlock_token, :unique => true
  44 + # add_index :users, :authentication_token, :unique => true
  45 + end
  46 +
  47 + def self.down
  48 + # By default, we don't want to make any assumption about how to roll back a migration when your
  49 + # model already existed. Please edit below which fields you would like to remove in this migration.
  50 + raise ActiveRecord::IrreversibleMigration
  51 + end
  52 +end
... ...
db/schema.rb
... ... @@ -11,13 +11,25 @@
11 11 #
12 12 # It's strongly recommended that you check this file into your version control system.
13 13  
14   -ActiveRecord::Schema.define(version: 20130627170417) do
  14 +ActiveRecord::Schema.define(version: 20130627183652) do
15 15  
16 16 create_table "users", force: true do |t|
17   - t.string "name"
18   - t.string "email"
  17 + t.string "name", default: "", null: false
  18 + t.string "email", default: "", null: false
19 19 t.datetime "created_at"
20 20 t.datetime "updated_at"
  21 + t.string "encrypted_password", default: "", null: false
  22 + t.string "reset_password_token"
  23 + t.datetime "reset_password_sent_at"
  24 + t.datetime "remember_created_at"
  25 + t.integer "sign_in_count", default: 0
  26 + t.datetime "current_sign_in_at"
  27 + t.datetime "last_sign_in_at"
  28 + t.string "current_sign_in_ip"
  29 + t.string "last_sign_in_ip"
21 30 end
22 31  
  32 + add_index "users", ["email"], name: "index_users_on_email", unique: true
  33 + add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
  34 +
23 35 end
... ...
spec/controllers/home_controller_spec.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +require 'spec_helper'
  2 +
  3 +describe HomeController do
  4 + context 'Method' do
  5 + context '#index' do
  6 + before :each do
  7 + get :index
  8 + end
  9 +
  10 + it {should render_template(:index)}
  11 + end
  12 + end
  13 +end
... ...
spec/helpers/.keep 0 → 100644
spec/routing/home_routing_spec.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +require "spec_helper"
  2 +
  3 +describe HomeController do
  4 + describe "routing" do
  5 + it 'should route to #index' do
  6 + get('/').should route_to('home#index')
  7 + end
  8 + end
  9 +end
0 10 \ No newline at end of file
... ...