mirror of
https://github.com/redmine/redmine.git
synced 2025-11-18 03:00:52 +01:00
Anonymous users can now be allowed to create, edit, comment issues, comment news and post messages in the forums.
These permissions need to be explicitly given to the Anonymous role (Admin -> Roles & Permissions -> Anonymous). git-svn-id: http://redmine.rubyforge.org/svn/trunk@919 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -19,6 +19,7 @@ require "digest/sha1"
|
||||
|
||||
class User < ActiveRecord::Base
|
||||
# Account statuses
|
||||
STATUS_ANONYMOUS = 0
|
||||
STATUS_ACTIVE = 1
|
||||
STATUS_REGISTERED = 2
|
||||
STATUS_LOCKED = 3
|
||||
@@ -36,15 +37,15 @@ class User < ActiveRecord::Base
|
||||
# Prevents unauthorized assignments
|
||||
attr_protected :login, :admin, :password, :password_confirmation, :hashed_password
|
||||
|
||||
validates_presence_of :login, :firstname, :lastname, :mail
|
||||
validates_presence_of :login, :firstname, :lastname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }
|
||||
validates_uniqueness_of :login, :mail
|
||||
# Login must contain lettres, numbers, underscores only
|
||||
validates_format_of :login, :with => /^[a-z0-9_\-@\.]+$/i
|
||||
validates_format_of :login, :with => /^[a-z0-9_\-@\.]*$/i
|
||||
validates_length_of :login, :maximum => 30
|
||||
validates_format_of :firstname, :lastname, :with => /^[\w\s\'\-]*$/i
|
||||
validates_length_of :firstname, :lastname, :maximum => 30
|
||||
validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
|
||||
validates_length_of :mail, :maximum => 60
|
||||
validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_nil => true
|
||||
validates_length_of :mail, :maximum => 60, :allow_nil => true
|
||||
# Password length between 4 and 12
|
||||
validates_length_of :password, :in => 4..12, :allow_nil => true
|
||||
validates_confirmation_of :password, :allow_nil => true
|
||||
@@ -216,11 +217,17 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.current
|
||||
@current_user ||= AnonymousUser.new
|
||||
@current_user ||= User.anonymous
|
||||
end
|
||||
|
||||
def self.anonymous
|
||||
AnonymousUser.new
|
||||
return @anonymous_user if @anonymous_user
|
||||
anonymous_user = AnonymousUser.find(:first)
|
||||
if anonymous_user.nil?
|
||||
anonymous_user = AnonymousUser.create(:lastname => 'Anonymous', :firstname => '', :mail => '', :login => '', :status => 0)
|
||||
raise 'Unable to create the anonymous user.' if anonymous_user.new_record?
|
||||
end
|
||||
@anonymous_user = anonymous_user
|
||||
end
|
||||
|
||||
private
|
||||
@@ -231,16 +238,17 @@ private
|
||||
end
|
||||
|
||||
class AnonymousUser < User
|
||||
def logged?
|
||||
false
|
||||
|
||||
def validate_on_create
|
||||
# There should be only one AnonymousUser in the database
|
||||
errors.add_to_base 'An anonymous user already exists.' if AnonymousUser.find(:first)
|
||||
end
|
||||
|
||||
def time_zone
|
||||
nil
|
||||
end
|
||||
|
||||
# Anonymous user has no RSS key
|
||||
def rss_key
|
||||
nil
|
||||
end
|
||||
# Overrides a few properties
|
||||
def logged?; false end
|
||||
def admin; false end
|
||||
def name; 'Anonymous' end
|
||||
def mail; nil end
|
||||
def time_zone; nil end
|
||||
def rss_key; nil end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user