Skip to content
Browse files

adding admin.

  • Loading branch information...
1 parent bd1ab77 commit 5afb06685fea5fb3207601fd72a4e17fd7f75e07 @chaserx chaserx committed Jul 6, 2012
View
11 app/models/user.rb
@@ -5,6 +5,15 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
- attr_accessible :email, :password, :password_confirmation, :remember_me
+ attr_accessible :username, :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
+
+ attr_accessor :login
+ attr_accessible :login
+
+ def self.find_first_by_auth_conditions(warden_conditions)
+ conditions = warden_conditions.dup
+ login = conditions.delete(:login).downcase
+ where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first
+ end
end
View
3 app/views/devise/registrations/edit.html.erb
@@ -4,7 +4,8 @@
<%= f.error_notification %>
<div class="inputs">
- <%= f.input :email, :required => true, :autofocus => true %>
+ <%= f.input :username, :required => true, :autofocus => true %>
+ <%= f.input :email, :required => true %>
<%= f.input :password, :autocomplete => "off", :hint => "leave it blank if you don't want to change it", :required => false %>
<%= f.input :password_confirmation, :required => false %>
<%= f.input :current_password, :hint => "we need your current password to confirm your changes", :required => true %>
View
3 app/views/devise/registrations/new.html.erb
@@ -4,7 +4,8 @@
<%= f.error_notification %>
<div class="inputs">
- <%= f.input :email, :required => true, :autofocus => true %>
+ <%= f.input :username, :required => true, :autofocus => true %>
+ <%= f.input :email, :required => true %>
<%= f.input :password, :required => true %>
<%= f.input :password_confirmation, :required => true %>
</div>
View
5 db/migrate/20120707031028_add_username_to_users.rb
@@ -0,0 +1,5 @@
+class AddUsernameToUsers < ActiveRecord::Migration
+ def change
+ add_column :users, :username, :string
+ end
+end
View
5 db/migrate/20120707032805_add_admin_to_users.rb
@@ -0,0 +1,5 @@
+class AddAdminToUsers < ActiveRecord::Migration
+ def change
+ add_column :users, :admin, :boolean, default: false
+ end
+end

0 comments on commit 5afb066

Please sign in to comment.
Something went wrong with that request. Please try again.