Commit 65f294e1bb36221c89ab3718addaaed8a26969a1

Authored by André Guedes
Committed by Tallys Martins
1 parent e6f4279a

Changed when user is created on moderation and removed unused user data

from task.

(AI3036)

Signed-off-by: André Bernardes <andrebsguedes@gmail.com>
Signed-off-by: Hebert Douglas <hebertdougl@gmail.com>
app/controllers/public/account_controller.rb
@@ -15,11 +15,27 @@ class AccountController &lt; ApplicationController @@ -15,11 +15,27 @@ class AccountController &lt; ApplicationController
15 15
16 def activate 16 def activate
17 @user = User.find_by_activation_code(params[:activation_code]) if params[:activation_code] 17 @user = User.find_by_activation_code(params[:activation_code]) if params[:activation_code]
18 - if @user and @user.activate  
19 - @message = _("Your account has been activated, now you can log in!")  
20 - check_redirection  
21 - session[:join] = params[:join] unless params[:join].blank?  
22 - render :action => 'login', :userlogin => @user.login 18 + if @user
  19 + unless @user.environment.enabled?('admin_must_approve_new_users')
  20 + if @user.activate
  21 + @message = _("Your account has been activated, now you can log in!")
  22 + check_redirection
  23 + session[:join] = params[:join] unless params[:join].blank?
  24 + render :action => 'login', :userlogin => @user.login
  25 + end
  26 + else
  27 + @task = CreateUser.new
  28 + @task.user_id = @user.id
  29 + @task.name = @user.name
  30 + @task.email =@user.email
  31 + @task.target = @user.environment
  32 + if @task.save
  33 + session[:notice] = _('Thanks for registering. The administrators were notified.')
  34 + @register_pending = true
  35 + @user.activation_code = nil
  36 + @user.save!
  37 + end
  38 + end
23 else 39 else
24 session[:notice] = _("It looks like you're trying to activate an account. Perhaps have already activated this account?") 40 session[:notice] = _("It looks like you're trying to activate an account. Perhaps have already activated this account?")
25 redirect_to :controller => :home 41 redirect_to :controller => :home
@@ -85,45 +101,30 @@ class AccountController &lt; ApplicationController @@ -85,45 +101,30 @@ class AccountController &lt; ApplicationController
85 @user.return_to = session[:return_to] 101 @user.return_to = session[:return_to]
86 @person = Person.new 102 @person = Person.new
87 @person.environment = @user.environment 103 @person.environment = @user.environment
88 - unless @user.environment.enabled?('admin_must_approve_new_users')  
89 - if request.post?  
90 - if may_be_a_bot  
91 - set_signup_start_time_for_now  
92 - @block_bot = true  
93 - session[:may_be_a_bot] = true  
94 - else  
95 - if session[:may_be_a_bot]  
96 - return false unless verify_recaptcha :model=>@user, :message=>_('Captcha (the human test)')  
97 - end  
98 - @user.community_to_join = session[:join]  
99 - @user.signup!  
100 - owner_role = Role.find_by_name('owner')  
101 - @user.person.affiliate(@user.person, [owner_role]) if owner_role  
102 - invitation = Task.find_by_code(@invitation_code)  
103 - if invitation  
104 - invitation.update_attributes!({:friend => @user.person})  
105 - invitation.finish  
106 - end  
107 - if @user.activated?  
108 - self.current_user = @user  
109 - check_join_in_community(@user)  
110 - go_to_signup_initial_page  
111 - else  
112 - @register_pending = true  
113 - end 104 + if request.post?
  105 + @person.attributes = params[:profile_data]
  106 + if may_be_a_bot
  107 + set_signup_start_time_for_now
  108 + @block_bot = true
  109 + session[:may_be_a_bot] = true
  110 + else
  111 + if session[:may_be_a_bot]
  112 + return false unless verify_recaptcha :model=>@user, :message=>_('Captcha (the human test)')
114 end 113 end
115 - end  
116 - else  
117 - @task = CreateUser.new(params[:user])  
118 - @task.person_data = @user.person_data  
119 - if request.post?  
120 - if @user.valid?  
121 - @task.target = @user.environment  
122 - @task.name = @user.name  
123 - if @task.save  
124 - session[:notice] = _('Thanks for registering. The administrators were notified.')  
125 - @register_pending = true  
126 - end 114 + @user.community_to_join = session[:join]
  115 + @user.signup!
  116 + owner_role = Role.find_by_name('owner')
  117 + @user.person.affiliate(@user.person, [owner_role]) if owner_role
  118 + invitation = Task.find_by_code(@invitation_code)
  119 + if invitation
  120 + invitation.update_attributes!({:friend => @user.person})
  121 + invitation.finish
  122 + end
  123 + if @user.activated?
  124 + self.current_user = @user
  125 + go_to_signup_initial_page
  126 + else
  127 + @register_pending = true
127 end 128 end
128 end 129 end
129 end 130 end
app/models/create_user.rb
1 class CreateUser < Task 1 class CreateUser < Task
2 2
3 - settings_items :email, :type => String 3 + settings_items :user_id, :type => String
4 settings_items :name, :type => String 4 settings_items :name, :type => String
5 settings_items :author_name, :type => String 5 settings_items :author_name, :type => String
6 - settings_items :person_data, :type => String 6 + settings_items :email, :type => String
7 7
8 after_create :schedule_spam_checking 8 after_create :schedule_spam_checking
9 9
10 alias :environment :target 10 alias :environment :target
11 alias :environment= :target= 11 alias :environment= :target=
12 12
13 - DATA_FIELDS = Person.fields + ['name', 'email', 'login', 'author_name', 'password', 'password_confirmation']  
14 - DATA_FIELDS.each do |field|  
15 - settings_items field.to_sym  
16 - end  
17 -  
18 def schedule_spam_checking 13 def schedule_spam_checking
19 self.delay.check_for_spam 14 self.delay.check_for_spam
20 end 15 end
@@ -26,13 +21,8 @@ class CreateUser &lt; Task @@ -26,13 +21,8 @@ class CreateUser &lt; Task
26 end 21 end
27 22
28 def perform 23 def perform
29 - user = User.new(user_data)  
30 - user.person = Person.new(person_data)  
31 - user.person.identifier = user.login  
32 - author_name = user.name  
33 - user.environment = self.environment  
34 - user.person.environment = user.environment  
35 - user.signup! 24 + user=User.find_by_id(user_id)
  25 + user.activate
36 end 26 end
37 27
38 def title 28 def title
@@ -66,13 +56,4 @@ class CreateUser &lt; Task @@ -66,13 +56,4 @@ class CreateUser &lt; Task
66 _("User \"%{user}\" just requested to register. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :user => self.name } 56 _("User \"%{user}\" just requested to register. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :user => self.name }
67 end 57 end
68 58
69 - protected  
70 -  
71 - def user_data  
72 - user_data = self.data.reject do |key, value|  
73 - !DATA_FIELDS.include?(key.to_s)  
74 - end  
75 -  
76 - user_data  
77 - end  
78 end 59 end
79 \ No newline at end of file 60 \ No newline at end of file