diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index 4b04572..6d0cb94 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -25,11 +25,13 @@ class AccountController < ApplicationController # action to perform login to the application def login - @user = User.new - @person = @user.build_person store_location(request.referer) unless session[:return_to] return unless request.post? - self.current_user = User.authenticate(params[:user][:login], params[:user][:password], environment) if params[:user] + + self.current_user = plugins_alternative_authentication + + self.current_user ||= User.authenticate(params[:user][:login], params[:user][:password], environment) if params[:user] + if logged_in? if params[:remember_me] == "1" self.current_user.remember_me @@ -41,7 +43,6 @@ class AccountController < ApplicationController end else session[:notice] = _('Incorrect username or password') if redirect? - redirect_to :back if redirect? end end @@ -56,6 +57,10 @@ class AccountController < ApplicationController # action to register an user to the application def signup + if @plugins.dispatch(:allow_user_registration).include?(false) + redirect_back_or_default(:controller => 'home') + end + @invitation_code = params[:invitation_code] begin if params[:user] @@ -125,6 +130,9 @@ class AccountController < ApplicationController # # Posts back. def forgot_password + if @plugins.dispatch(:allow_password_recovery).include?(false) + redirect_back_or_default(:controller => 'home') + end @change_password = ChangePassword.new(params[:change_password]) if request.post? @@ -316,4 +324,13 @@ class AccountController < ApplicationController end end + def plugins_alternative_authentication + user = nil + @plugins.each do |plugin| + user = plugin.alternative_authentication + break unless user.nil? + end + user + end + end diff --git a/app/models/person.rb b/app/models/person.rb index 378ad3a..37c5f27 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -71,10 +71,7 @@ class Person < Profile Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } end - after_destroy :destroy_user - def destroy_user - self.user.destroy if self.user - end + belongs_to :user, :dependent => :delete def can_control_scrap?(scrap) begin diff --git a/app/models/user.rb b/app/models/user.rb index 307b69d..da9b5f0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -30,7 +30,7 @@ class User < ActiveRecord::Base after_create do |user| user.person ||= Person.new - user.person.attributes = user.person_data.merge(:identifier => user.login, :user_id => user.id, :environment_id => user.environment_id) + user.person.attributes = user.person_data.merge(:identifier => user.login, :user => user, :environment_id => user.environment_id) user.person.name ||= user.login user.person.visible = false unless user.activated? user.person.save! @@ -88,13 +88,13 @@ class User < ActiveRecord::Base attr_protected :activated_at # Virtual attribute for the unencrypted password - attr_accessor :password + attr_accessor :password, :name validates_presence_of :login, :email validates_format_of :login, :with => Profile::IDENTIFIER_FORMAT, :if => (lambda {|user| !user.login.blank?}) validates_presence_of :password, :if => :password_required? - validates_presence_of :password_confirmation, :if => :password_required?, :if => (lambda {|user| !user.password.blank?}) - validates_length_of :password, :within => 4..40, :if => :password_required?, :if => (lambda {|user| !user.password.blank?}) + validates_presence_of :password_confirmation, :if => :password_required? + validates_length_of :password, :within => 4..40, :if => :password_required? validates_confirmation_of :password, :if => :password_required? validates_length_of :login, :within => 2..40, :if => (lambda {|user| !user.login.blank?}) validates_length_of :email, :within => 3..100, :if => (lambda {|user| !user.email.blank?}) @@ -228,7 +228,12 @@ class User < ActiveRecord::Base end def name - person ? person.name : login + name = (self[:name] || login) + person.nil? ? name : (person.name || name) + end + + def name= name + self[:name] = name end def enable_email! @@ -274,6 +279,11 @@ class User < ActiveRecord::Base 15 # in minutes end + + def not_require_password! + @is_password_required = false + end + protected # before filter def encrypt_password @@ -282,9 +292,13 @@ class User < ActiveRecord::Base self.password_type ||= User.system_encryption_method.to_s self.crypted_password = encrypt(password) end - + def password_required? - crypted_password.blank? || !password.blank? + (crypted_password.blank? || !password.blank?) && is_password_required? + end + + def is_password_required? + @is_password_required.nil? ? true : @is_password_required end def make_activation_code diff --git a/app/views/account/login.rhtml b/app/views/account/login.rhtml index 69ec0fc..5ab7e8c 100644 --- a/app/views/account/login.rhtml +++ b/app/views/account/login.rhtml @@ -13,6 +13,8 @@ <%= f.password_field :password %> + <%= @plugins.dispatch(:login_extra_contents).collect { |content| instance_eval(&content) }.join("") %> + <% button_bar do %> <%= submit_button( 'login', _('Log in') )%> <% if is_thickbox %> @@ -23,8 +25,13 @@ <% end %> <% button_bar do %> - <%= button :add, _("New user"), :controller => 'account', :action => 'signup' %> - <%= button :help, _("I forgot my password!"), :controller => 'account', :action => 'forgot_password' %> + <% unless @plugins.dispatch(:allow_user_registration).include?(false) %> + <%= button :add, _("New user"), :controller => 'account', :action => 'signup' %> + <% end %> + + <% unless @plugins.dispatch(:allow_password_recovery).include?(false) %> + <%= button :help, _("I forgot my password!"), :controller => 'account', :action => 'forgot_password' %> + <% end %> <% end %> diff --git a/app/views/layouts/application-ng.rhtml b/app/views/layouts/application-ng.rhtml index 838fb19..480e3f9 100644 --- a/app/views/layouts/application-ng.rhtml +++ b/app/views/layouts/application-ng.rhtml @@ -56,10 +56,18 @@ <%= usermenu_logged_in %>