users can now select their level when signing up (for testing only)

This commit is contained in:
albert
2011-10-21 17:29:41 -04:00
parent e8808987d5
commit e8ac9cfcc1
4 changed files with 27 additions and 7 deletions

View File

@@ -16,7 +16,7 @@ div#c-users {
} }
div#a-new { div#a-new {
max-width: 60em; max-width: 50em;
p { p {
margin-bottom: 1em; margin-bottom: 1em;
@@ -28,8 +28,11 @@ div#c-users {
} }
div#account-comparison { div#account-comparison {
padding: 0 1em;
margin: 1em 0;
h1 { h1 {
font-size: $h2_size; font-size: $h3_size;
} }
li { li {
@@ -38,9 +41,9 @@ div#c-users {
} }
section { section {
width: 18em; width: 15em;
float: left; float: left;
padding: 1em; padding-right: 1em;
} }
} }

View File

@@ -27,7 +27,7 @@ class UsersController < ApplicationController
end end
def create def create
@user = User.create(params[:user]) @user = User.create(params[:user], :as => :admin)
if @user.errors.empty? if @user.errors.empty?
session[:user_id] = @user.id session[:user_id] = @user.id
end end
@@ -38,7 +38,7 @@ class UsersController < ApplicationController
def update def update
@user = User.find(params[:id]) @user = User.find(params[:id])
check_privilege(@user) check_privilege(@user)
@user.update_attributes(params[:user]) @user.update_attributes(params[:user], :as => :admin)
respond_with(@user) respond_with(@user)
end end

View File

@@ -15,7 +15,8 @@ class User < ActiveRecord::Base
attr_accessor :password, :old_password attr_accessor :password, :old_password
attr_accessible :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size attr_accessible :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size
validates_length_of :name, :within => 2..1000, :on => :create attr_accessible :level, :as => :admin
validates_length_of :name, :within => 2..100, :on => :create
validates_format_of :name, :with => /\A[^\s:]+\Z/, :on => :create, :message => "cannot have whitespace or colons" validates_format_of :name, :with => /\A[^\s:]+\Z/, :on => :create, :message => "cannot have whitespace or colons"
validates_uniqueness_of :name, :case_sensitive => false, :on => :create validates_uniqueness_of :name, :case_sensitive => false, :on => :create
validates_uniqueness_of :email, :case_sensitive => false, :on => :create, :if => lambda {|rec| !rec.email.blank?} validates_uniqueness_of :email, :case_sensitive => false, :on => :create, :if => lambda {|rec| !rec.email.blank?}
@@ -191,6 +192,21 @@ class User < ActiveRecord::Base
end end
module LevelMethods module LevelMethods
extend ActiveSupport::Concern
module ClassMethods
def level_hash
return {
"Member" => Levels::MEMBER,
"Privileged" => Levels::PRIVILEGED,
"Contributor" => Levels::CONTRIBUTOR,
"Janitor" => Levels::JANITOR,
"Moderator" => Levels::MODERATOR,
"Admin" => Levels::ADMIN
}
end
end
def promote_to_admin_if_first_user def promote_to_admin_if_first_user
return if Rails.env.test? return if Rails.env.test?

View File

@@ -69,6 +69,7 @@
<%= f.input :password %> <%= f.input :password %>
<%= f.input :password_confirmation %> <%= f.input :password_confirmation %>
<%= f.input :email, :required => false %> <%= f.input :email, :required => false %>
<%= f.input :level, :collection => User.level_hash.to_a, :include_blank => false %>
<%= f.button :submit %> <%= f.button :submit %>
<% end %> <% end %>
</div> </div>