@user.admin = params[:user][:admin] if params[:user][:admin]
@user.login = params[:user][:login] if params[:user][:login]
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
- if @user.update_attributes(params[:user])
+ @user.attributes = params[:user]
+ # Was the account actived ? (do it before User#save clears the change)
+ was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
+ if @user.save
+ Mailer.deliver_account_activated(@user) if was_activated
flash[:notice] = l(:notice_successful_update)
# Give a string to redirect_to otherwise it would use status param as the response code
redirect_to(url_for(:action => 'list', :status => params[:status], :page => params[:page]))
:url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
end
+ # A registered user's account was activated by an administrator
+ def account_activated(user)
+ set_language_if_valid user.language
+ recipients user.mail
+ subject l(:mail_subject_register, Setting.app_title)
+ body :user => user,
+ :login_url => url_for(:controller => 'account', :action => 'login')
+ end
+
def lost_password(token)
set_language_if_valid(token.user.language)
recipients token.user.mail
--- /dev/null
+<p><%= l(:notice_account_activated) %></p>
+<p><%= l(:label_login) %>: <%= link_to @login_url, @login_url %></p>
--- /dev/null
+<%= l(:notice_account_activated) %>
+<%= l(:label_login) %>: <%= @login_url %>
assert_equal 2, Member.find(1).role_id
end
+ def test_edit_with_activation_should_send_a_notification
+ u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr')
+ u.login = 'foo'
+ u.status = User::STATUS_REGISTERED
+ u.save!
+ ActionMailer::Base.deliveries.clear
+ Setting.bcc_recipients = '1'
+
+ post :edit, :id => u.id, :user => {:status => User::STATUS_ACTIVE}
+ assert u.reload.active?
+ mail = ActionMailer::Base.deliveries.last
+ assert_not_nil mail
+ assert_equal ['foo.bar@somenet.foo'], mail.bcc
+ assert mail.body.include?(ll('fr', :notice_account_activated))
+ end
+
def test_destroy_membership
assert_routing(
#TODO: use DELETE method on user_membership_path, modify form