Browse Source

Auth by username instead of email

Added username to User table/model
eperez-timeinput
Jason Denney 11 years ago
parent
commit
9021294c4b
  1. 2
      app/components/app_tab_panel.rb
  2. 1
      app/components/user_stats.rb
  3. 1
      app/components/users.rb
  4. 4
      app/views/devise/registrations/new.html.haml
  5. 8
      app/views/devise/sessions/new.html.erb
  6. 2
      config/initializers/devise.rb
  7. 6
      db/migrate/20130525143240_add_username_to_user.rb
  8. 4
      db/schema.rb
  9. 4
      spec/factories/users.rb

2
app/components/app_tab_panel.rb

@ -3,7 +3,7 @@ class AppTabPanel < Netzke::Basepack::TabPanel
action :sign_out do |c|
c.icon = :door_out
c.text = "Sign out #{controller.current_user.email}" if controller.current_user
c.text = "Exit" if controller.current_user
end
def configure(c)

1
app/components/user_stats.rb

@ -4,6 +4,7 @@ class UserStats < Netzke::Base
bike = user.bike
%Q(
<div id="user_stats_page">
<p>Username: #{user.username}</p>
<p>Total Hours Worked: #{user.total_hours}</p>
<p>Hours worked in #{Time.now.strftime('%B')}: #{user.current_month_hours}</p>
<p>Current bike Shop ID: #{bike.shop_id if bike}</p>

1
app/components/users.rb

@ -5,6 +5,7 @@ class Users < Netzke::Basepack::Grid
c.model = "User"
c.columns = [
:username,
:first_name,
:last_name,
:nickname,

4
app/views/devise/registrations/new.html.haml

@ -2,6 +2,10 @@
%h2 Sign up
= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
= devise_error_messages!
%div
= f.label :username
%br/
= f.text_field :username
%div
= f.label :first_name
%br/

8
app/views/devise/sessions/new.html.erb

@ -3,8 +3,8 @@
<h2>Sign in</h2>
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.label :username%><br />
<%= f.text_field :username%></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
@ -21,9 +21,9 @@
<% if Rails.env.development? %>
<% User.all.each do |user| %>
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<%= f.hidden_field :email, :value => user.email %></div>
<%= f.hidden_field :username, :value => user.username%></div>
<%= f.hidden_field :password, :value => 'password' %></div>
<div><%= f.submit "Sign in as #{user.email}" %></div>
<div><%= f.submit "Sign in as #{user.username}" %></div>
<% end %>
<% end %>
<% end %>

2
config/initializers/devise.rb

@ -26,7 +26,7 @@ Devise.setup do |config|
# session. If you need permissions, you should implement that in a before filter.
# You can also supply a hash where the value is a boolean determining whether
# or not authentication should be aborted when the value is not present.
# config.authentication_keys = [ :email ]
config.authentication_keys = [ :username ]
# Configure parameters from the request object used for authentication. Each entry
# given should be a request method and it will automatically be passed to the

6
db/migrate/20130525143240_add_username_to_user.rb

@ -0,0 +1,6 @@
class AddUsernameToUser < ActiveRecord::Migration
def change
add_column :users, :username, :string
add_index :users, :username, :unique => true
end
end

4
db/schema.rb

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130419010051) do
ActiveRecord::Schema.define(:version => 20130525143240) do
create_table "bike_actions", :force => true do |t|
t.string "action", :limit => 128, :null => false
@ -177,10 +177,12 @@ ActiveRecord::Schema.define(:version => 20130419010051) do
t.string "first_name", :default => "", :null => false
t.string "last_name", :default => "", :null => false
t.string "nickname"
t.string "username"
end
add_index "users", ["bike_id"], :name => "index_users_on_bike_id", :unique => true
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
add_index "users", ["username"], :name => "index_users_on_username", :unique => true
end

4
spec/factories/users.rb

@ -1,5 +1,6 @@
FactoryGirl.define do
factory :user do
sequence(:username) { |n| "user_#{n}" }
sequence(:email) { |n| "user_#{n}@example.com" }
password 'password'
password_confirmation { password }
@ -9,16 +10,19 @@ FactoryGirl.define do
association :user_role, factory: :role_user
factory :staff do
username "staff"
first_name 'Staff'
association :user_role, factory: :role_staff
end
factory :admin do
username "admin"
first_name 'Admin'
association :user_role, factory: :role_admin
end
factory :bike_admin do
username "bike_admin"
first_name 'BikeAdmin'
association :user_role, factory: :role_bike_admin
end

Loading…
Cancel
Save