Patch #11500 ยป 0021-Add-unknow-user-register-option-support-to-mail-hand.patch
| app/controllers/account_controller.rb | ||
|---|---|---|
| 102 | 102 |
@user.login = params[:user][:login] |
| 103 | 103 |
@user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] |
| 104 | 104 | |
| 105 |
case Setting.self_registration |
|
| 106 |
when '1' |
|
| 107 |
register_by_email_activation(@user) |
|
| 108 |
when '3' |
|
| 109 |
register_automatically(@user) |
|
| 110 |
else |
|
| 111 |
register_manually_by_administrator(@user) |
|
| 112 |
end |
|
| 105 |
process_user_registration(@user) |
|
| 113 | 106 |
end |
| 114 | 107 |
end |
| 115 | 108 |
end |
| ... | ... | |
| 167 | 160 |
user.random_password |
| 168 | 161 |
user.register |
| 169 | 162 | |
| 170 |
case Setting.self_registration |
|
| 171 |
when '1' |
|
| 172 |
register_by_email_activation(user) do |
|
| 173 |
onthefly_creation_failed(user) |
|
| 174 |
end |
|
| 175 |
when '3' |
|
| 176 |
register_automatically(user) do |
|
| 177 |
onthefly_creation_failed(user) |
|
| 178 |
end |
|
| 179 |
else |
|
| 180 |
register_manually_by_administrator(user) do |
|
| 181 |
onthefly_creation_failed(user) |
|
| 182 |
end |
|
| 163 |
process_user_registration(user) do |
|
| 164 |
onthefly_creation_failed(user) |
|
| 183 | 165 |
end |
| 184 | 166 |
else |
| 185 | 167 |
# Existing record |
| ... | ... | |
| 229 | 211 |
flash.now[:error] = l(:notice_account_invalid_creditentials) |
| 230 | 212 |
end |
| 231 | 213 | |
| 232 |
# Register a user for email activation. |
|
| 233 |
# |
|
| 234 |
# Pass a block for behavior when a user fails to save |
|
| 235 |
def register_by_email_activation(user, &block) |
|
| 236 |
token = Token.new(:user => user, :action => "register") |
|
| 237 |
if user.save and token.save |
|
| 238 |
Mailer.deliver_register(token) |
|
| 239 |
flash[:notice] = l(:notice_account_register_done) |
|
| 240 |
redirect_to :action => 'login' |
|
| 241 |
else |
|
| 242 |
yield if block_given? |
|
| 243 |
end |
|
| 244 |
end |
|
| 245 | ||
| 246 |
# Automatically register a user |
|
| 247 |
# |
|
| 248 |
# Pass a block for behavior when a user fails to save |
|
| 249 |
def register_automatically(user, &block) |
|
| 250 |
# Automatic activation |
|
| 251 |
user.activate |
|
| 252 |
user.last_login_on = Time.now |
|
| 253 |
if user.save |
|
| 254 |
self.logged_user = user |
|
| 255 |
flash[:notice] = l(:notice_account_activated) |
|
| 256 |
redirect_to :controller => 'my', :action => 'account' |
|
| 257 |
else |
|
| 258 |
yield if block_given? |
|
| 259 |
end |
|
| 260 |
end |
|
| 261 | ||
| 262 |
# Manual activation by the administrator |
|
| 263 |
# |
|
| 264 |
# Pass a block for behavior when a user fails to save |
|
| 265 |
def register_manually_by_administrator(user, &block) |
|
| 266 |
if user.save |
|
| 267 |
# Sends an email to the administrators |
|
| 268 |
Mailer.deliver_account_activation_request(user) |
|
| 269 |
account_pending |
|
| 214 |
def process_user_registration(user, &block) |
|
| 215 |
if user.process_registration |
|
| 216 |
case Setting.self_registration |
|
| 217 |
when '1' |
|
| 218 |
# mail activation |
|
| 219 |
flash[:notice] = l(:notice_account_register_done) |
|
| 220 |
redirect_to :action => 'login' |
|
| 221 |
when '3' |
|
| 222 |
# auto activation |
|
| 223 |
self.logged_user = user |
|
| 224 |
flash[:notice] = l(:notice_account_activated) |
|
| 225 |
redirect_to :controller => 'my', :action => 'account' |
|
| 226 |
else |
|
| 227 |
# admin approval |
|
| 228 |
account_pending |
|
| 229 |
end |
|
| 270 | 230 |
else |
| 271 | 231 |
yield if block_given? |
| 272 | 232 |
end |
| app/models/mail_handler.rb | ||
|---|---|---|
| 85 | 85 |
case @@handler_options[:unknown_user] |
| 86 | 86 |
when 'accept' |
| 87 | 87 |
@user = User.anonymous |
| 88 |
when 'create' |
|
| 88 |
when 'create', 'register'
|
|
| 89 | 89 |
@user = create_user_from_email |
| 90 | 90 |
if @user |
| 91 | 91 |
logger.info "MailHandler: [#{@user.login}] account created"
|
| ... | ... | |
| 376 | 376 |
# Returns a User from an email address and a full name |
| 377 | 377 |
def self.new_user_from_attributes(email_address, fullname=nil) |
| 378 | 378 |
user = User.new |
| 379 |
user.register if @@handler_options[:unknown_user] == 'register' |
|
| 379 | 380 | |
| 380 | 381 |
# Truncating the email address would result in an invalid format |
| 381 | 382 |
user.mail = email_address |
| ... | ... | |
| 405 | 406 |
addr = email.from_addrs.to_a.first |
| 406 | 407 |
if addr && !addr.spec.blank? |
| 407 | 408 |
user = self.class.new_user_from_attributes(addr.spec, TMail::Unquoter.unquote_and_convert_to(addr.name, 'utf-8')) |
| 408 |
if user.save
|
|
| 409 |
if user.process_registration
|
|
| 409 | 410 |
user |
| 410 | 411 |
else |
| 411 | 412 |
logger.error "MailHandler: failed to create User: #{user.errors.full_messages}"
|
| app/models/user.rb | ||
|---|---|---|
| 381 | 381 |
!logged? |
| 382 | 382 |
end |
| 383 | 383 | |
| 384 |
def process_registration |
|
| 385 |
case Setting.self_registration |
|
| 386 |
when '1' |
|
| 387 |
register_by_email_activation |
|
| 388 |
when '3' |
|
| 389 |
register_automatically |
|
| 390 |
else |
|
| 391 |
register_manually_by_administrator |
|
| 392 |
end |
|
| 393 |
end |
|
| 394 | ||
| 384 | 395 |
# Return user's roles for project |
| 385 | 396 |
def roles_for_project(project) |
| 386 | 397 |
roles = [] |
| ... | ... | |
| 597 | 608 | |
| 598 | 609 |
private |
| 599 | 610 | |
| 611 |
def register_by_email_activation |
|
| 612 |
token = Token.new(:user => self, :action => "register") |
|
| 613 |
Mailer.deliver_register(token) if self.save and token.save |
|
| 614 |
end |
|
| 615 | ||
| 616 |
def register_automatically |
|
| 617 |
self.activate |
|
| 618 |
self.last_login_on = Time.now |
|
| 619 |
self.save |
|
| 620 |
end |
|
| 621 | ||
| 622 |
def register_manually_by_administrator |
|
| 623 |
# Sends an email to the administrators |
|
| 624 |
Mailer.deliver_account_activation_request(self) if self.save |
|
| 625 |
end |
|
| 626 | ||
| 600 | 627 |
# Removes references that are not handled by associations |
| 601 | 628 |
# Things that are not deleted are reassociated with the anonymous user |
| 602 | 629 |
def remove_references_before_destroy |
| extra/mail_handler/rdm-mailhandler.rb | ||
|---|---|---|
| 44 | 44 |
"ACTION can be one of the following values:", |
| 45 | 45 |
"* ignore: email is ignored (default)", |
| 46 | 46 |
"* accept: accept as anonymous user", |
| 47 |
"* create: create a user account") {|v| self.unknown_user = v}
|
|
| 47 |
"* create: create a user account" |
|
| 48 |
"* register: create an inactive user account") {|v| self.unknown_user = v}
|
|
| 48 | 49 |
opts.on("--no-permission-check", "disable permission checking when receiving",
|
| 49 | 50 |
"the email") {self.no_permission_check = '1'}
|
| 50 | 51 |
opts.on("--no-account-notice", "disable new user account notification") {self.no_account_notice = '1'}
|