Browse Source

Merge pull request #21 from spacemunkay/denney-new-user-form

Denney new user form
eperez-timeinput
Jason Denney 12 years ago
parent
commit
c9e94d8e30
  1. 3
      app/assets/javascripts/application.js
  2. 51
      app/assets/javascripts/devise/registrations.js
  3. 0
      app/assets/javascripts/devise/sessions.js
  4. 0
      app/assets/javascripts/site.js
  5. 0
      app/assets/javascripts/twitter/bootstrap.js.coffee
  6. 2
      app/components/app_tab_panel.rb
  7. 1
      app/components/user_stats.rb
  8. 1
      app/components/users.rb
  9. 23
      app/helpers/devise_helper.rb
  10. 6
      app/models/user.rb
  11. 3
      app/models/user_profile.rb
  12. 8
      app/views/devise/registrations/new.html.haml
  13. 8
      app/views/devise/sessions/new.html.erb
  14. 1
      app/views/layouts/application.html.haml
  15. 6
      config/initializers/devise.rb
  16. 6
      db/migrate/20130525143240_add_username_to_user.rb
  17. 6
      db/schema.rb
  18. 4
      spec/factories/users.rb

3
app/assets/javascripts/application.js

@ -12,5 +12,4 @@
// //
//= require jquery //= require jquery
//= require jquery_ujs //= require jquery_ujs
//= require twitter/bootstrap //= require custom_netzke_helpers
//= require_tree .

51
app/assets/javascripts/devise/registrations.js

@ -0,0 +1,51 @@
$(document).ready(function(){
var MIN_LEN = 3;
var MAX_SUBMITS = 3;
var submit_count = 0;
$("input[name=commit]").click( function(e){
console.log("clicked");
submit_count += 1;
//IDs of contact info
var contact_info_ids = [
"user_email",
"user_user_profiles_attributes_0_addrStreet1",
"user_user_profiles_attributes_0_addrCity",
"user_user_profiles_attributes_0_addrState",
"user_user_profiles_attributes_0_addrZip",
"user_user_profiles_attributes_0_phone"
];
var contact_vals = "";
var index = 0;
//see if any contact info exists
for( var index in contact_info_ids){
contact_vals += $("#"+contact_info_ids[index]).val();
}
if( contact_vals.length >= MIN_LEN || submit_count > MAX_SUBMITS){
if( submit_count > MAX_SUBMITS ){
alert("Fine.");
}
return true;
}else{
switch(submit_count){
case 1:
alert("It appears you have not entered any contact information. " +
"Please do.");
break;
case 2:
alert("It is highly recommended that you enter at least one form of" +
" contact information. It is in your best interest.");
break;
case 3:
alert("If something happens to your bicycle, we will not be able to" +
" notify you. Please enter at least one form of contact.");
break;
default:
alert("Please enter at least one form of contact.");
}
return false;
}
});
});

0
app/assets/javascripts/devise/sessions.js

0
app/assets/javascripts/site.js

0
app/assets/javascripts/bootstrap.js.coffee → app/assets/javascripts/twitter/bootstrap.js.coffee

2
app/components/app_tab_panel.rb

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

1
app/components/user_stats.rb

@ -4,6 +4,7 @@ class UserStats < Netzke::Base
bike = user.bike bike = user.bike
%Q( %Q(
<div id="user_stats_page"> <div id="user_stats_page">
<p>Username: #{user.username}</p>
<p>Total Hours Worked: #{user.total_hours}</p> <p>Total Hours Worked: #{user.total_hours}</p>
<p>Hours worked in #{Time.now.strftime('%B')}: #{user.current_month_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> <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.model = "User"
c.columns = [ c.columns = [
:username,
:first_name, :first_name,
:last_name, :last_name,
:nickname, :nickname,

23
app/helpers/devise_helper.rb

@ -0,0 +1,23 @@
module DeviseHelper
# A simple way to show error messages for the current devise resource. If you need
# to customize this method, you can either overwrite it in your application helpers or
# copy the views to your application.
#
# This method is intended to stay simple and it is unlikely that we are going to change
# it to add more behavior or options.
def devise_error_messages!
return "" if resource.errors.empty?
messages = resource.errors.full_messages.map { |msg| content_tag(:p, msg, :class => "alert") }.join
sentence = I18n.t("errors.messages.not_saved",
:count => resource.errors.count,
:resource => resource.class.model_name.human.downcase)
html = <<-HTML
<p>#{sentence}</p>
#{messages}
HTML
html.html_safe
end
end

6
app/models/user.rb

@ -8,7 +8,7 @@ class User < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model # Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, attr_accessible :email, :password, :password_confirmation, :remember_me,
:first_name, :last_name, :nickname, :bike_id, :first_name, :last_name, :nickname, :bike_id,
:user_profiles_attributes :user_profiles_attributes, :username
has_many :transactions has_many :transactions
has_many :user_profiles has_many :user_profiles
@ -26,6 +26,10 @@ class User < ActiveRecord::Base
"#{first_name} #{last_name}" "#{first_name} #{last_name}"
end end
def email_required?
false
end
def full_name def full_name
to_s to_s
end end

3
app/models/user_profile.rb

@ -1,5 +1,4 @@
class UserProfile < ActiveRecord::Base class UserProfile < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model
attr_accessible :user_id, :addrStreet1, :addrStreet2, :addrCity, attr_accessible :user_id, :addrStreet1, :addrStreet2, :addrCity,
:addrState, :addrZip, :phone :addrState, :addrZip, :phone
@ -10,7 +9,7 @@ class UserProfile < ActiveRecord::Base
#validates :addrCity , :presence => true #validates :addrCity , :presence => true
#validates :addrState , :presence => true #validates :addrState , :presence => true
#validates :addrZip , :presence => true #validates :addrZip , :presence => true
validates :phone, :presence => true #validates :phone, :presence => true
def to_s def to_s
[addrStreet1, addrStreet2, addrCity, addrState, addrZip, phone].join(" - ") [addrStreet1, addrStreet2, addrCity, addrState, addrZip, phone].join(" - ")

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

@ -1,6 +1,11 @@
= stylesheet_link_tag "bootstrap_and_overrides", :media => "all"
%h2 Sign up %h2 Sign up
= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| = form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
= devise_error_messages! = devise_error_messages!
%div
= f.label :username
%br/
= f.text_field :username
%div %div
= f.label :first_name = f.label :first_name
%br/ %br/
@ -18,7 +23,8 @@
%br/ %br/
= f.email_field :email = f.email_field :email
%div %div
= f.fields_for :user_profiles, UserProfile.new do |builder| - profile_builder = resource.user_profiles.empty? ? resource.user_profiles.build : resource.user_profiles
= f.fields_for :user_profiles, profile_builder do |builder|
= render 'user_profile_fields', f: builder = render 'user_profile_fields', f: builder
%div %div
= f.label :password = f.label :password

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

@ -3,8 +3,8 @@
<h2>Velocipede</h2> <h2>Velocipede</h2>
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %> <%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<div><%= f.label :email %><br /> <div><%= f.label :username%><br />
<%= f.email_field :email %></div> <%= f.text_field :username%></div>
<div><%= f.label :password %><br /> <div><%= f.label :password %><br />
<%= f.password_field :password %></div> <%= f.password_field :password %></div>
@ -28,9 +28,9 @@
<% if Rails.env.development? %> <% if Rails.env.development? %>
<% User.all.each do |user| %> <% User.all.each do |user| %>
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %> <%= 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> <%= 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 %> <% end %>
<% end %> <% end %>

1
app/views/layouts/application.html.haml

@ -28,3 +28,4 @@
%p &copy; Velocipede 2013 %p &copy; Velocipede 2013
= javascript_include_tag "application" = javascript_include_tag "application"
= javascript_include_tag params[:controller]

6
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. # 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 # 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. # 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 # 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 # given should be a request method and it will automatically be passed to the
@ -38,12 +38,12 @@ Devise.setup do |config|
# Configure which authentication keys should be case-insensitive. # Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used # These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email. # to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [ :email ] config.case_insensitive_keys = [ :username ]
# Configure which authentication keys should have whitespace stripped. # Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or # These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email. # modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [ :email ] config.strip_whitespace_keys = [ :username ]
# Tell if authentication through request.params is enabled. True by default. # Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the # It can be set to an array that will enable params authentication only for 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

6
db/schema.rb

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130424005701) do ActiveRecord::Schema.define(:version => 20130525143240) do
create_table "bike_actions", :force => true do |t| create_table "bike_actions", :force => true do |t|
t.string "action", :limit => 128, :null => false t.string "action", :limit => 128, :null => false
@ -155,7 +155,7 @@ ActiveRecord::Schema.define(:version => 20130424005701) do
end end
create_table "user_role_joins", :force => true do |t| create_table "user_role_joins", :force => true do |t|
t.integer "role_id" t.integer "role_id", :limit => 255
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.datetime "ends" t.datetime "ends"
@ -182,10 +182,12 @@ ActiveRecord::Schema.define(:version => 20130424005701) do
t.string "first_name", :default => "", :null => false t.string "first_name", :default => "", :null => false
t.string "last_name", :default => "", :null => false t.string "last_name", :default => "", :null => false
t.string "nickname" t.string "nickname"
t.string "username"
end end
add_index "users", ["bike_id"], :name => "index_users_on_bike_id", :unique => true 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", ["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", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
add_index "users", ["username"], :name => "index_users_on_username", :unique => true
end end

4
spec/factories/users.rb

@ -1,5 +1,6 @@
FactoryGirl.define do FactoryGirl.define do
factory :user do factory :user do
sequence(:username) { |n| "user_#{n}" }
sequence(:email) { |n| "user_#{n}@example.com" } sequence(:email) { |n| "user_#{n}@example.com" }
password 'password' password 'password'
password_confirmation { password } password_confirmation { password }
@ -11,6 +12,7 @@ FactoryGirl.define do
end end
factory :staff do factory :staff do
username "staff"
first_name 'Staff' first_name 'Staff'
after_build do |r| after_build do |r|
r.roles << (Role.find_by_role("staff") || FactoryGirl.create(:role_staff)) r.roles << (Role.find_by_role("staff") || FactoryGirl.create(:role_staff))
@ -18,6 +20,7 @@ FactoryGirl.define do
end end
factory :admin do factory :admin do
username "admin"
first_name 'Admin' first_name 'Admin'
after_build do |r| after_build do |r|
r.roles << (Role.find_by_role("admin") || FactoryGirl.create(:role_admin)) r.roles << (Role.find_by_role("admin") || FactoryGirl.create(:role_admin))
@ -25,6 +28,7 @@ FactoryGirl.define do
end end
factory :bike_admin do factory :bike_admin do
username "bike_admin"
first_name 'BikeAdmin' first_name 'BikeAdmin'
after_build do |r| after_build do |r|
r.roles << (Role.find_by_role("bike_admin") || FactoryGirl.create(:role_bike_admin)) r.roles << (Role.find_by_role("bike_admin") || FactoryGirl.create(:role_bike_admin))

Loading…
Cancel
Save