diff options
Diffstat (limited to 'app/controllers/invitations_controller.rb')
-rw-r--r-- | app/controllers/invitations_controller.rb | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb index d063ef839..be2993777 100644 --- a/app/controllers/invitations_controller.rb +++ b/app/controllers/invitations_controller.rb @@ -16,35 +16,35 @@ class InvitationsController < Devise::InvitationsController end def create - if !AppConfig[:open_invitations] && current_user.invites == 0 - flash[:error] = I18n.t 'invitations.create.no_more' - redirect_to :back - return - end - aspect = params[:user].delete(:aspects) - message = params[:user].delete(:invite_messages) - emails = params[:user][:email].to_s.gsub(/\s/, '').split(/, */) + unless AppConfig[:open_invitations] + flash[:error] = I18n.t 'invitations.create.no_more' + redirect_to :back + return + end + aspect = params[:user].delete(:aspects) + message = params[:user].delete(:invite_messages) + emails = params[:user][:email].to_s.gsub(/\s/, '').split(/, */) - good_emails, bad_emails = emails.partition{|e| e.try(:match, Devise.email_regexp)} + good_emails, bad_emails = emails.partition{|e| e.try(:match, Devise.email_regexp)} - if good_emails.include?(current_user.email) - if good_emails.length == 1 - flash[:error] = I18n.t 'invitations.create.own_address' - redirect_to :back - return - else - bad_emails.push(current_user.email) - good_emails.delete(current_user.email) - end + if good_emails.include?(current_user.email) + if good_emails.length == 1 + flash[:error] = I18n.t 'invitations.create.own_address' + redirect_to :back + return + else + bad_emails.push(current_user.email) + good_emails.delete(current_user.email) end + end - good_emails.each{|e| Resque.enqueue(Job::Mail::InviteUserByEmail, current_user.id, e, aspect, message)} + good_emails.each{|e| Resque.enqueue(Job::Mail::InviteUserByEmail, current_user.id, e, aspect, message)} - if bad_emails.any? - flash[:error] = I18n.t('invitations.create.sent') + good_emails.join(', ') + " "+ I18n.t('invitations.create.rejected') + bad_emails.join(', ') - else - flash[:notice] = I18n.t('invitations.create.sent') + good_emails.join(', ') - end + if bad_emails.any? + flash[:error] = I18n.t('invitations.create.sent') + good_emails.join(', ') + " "+ I18n.t('invitations.create.rejected') + bad_emails.join(', ') + else + flash[:notice] = I18n.t('invitations.create.sent') + good_emails.join(', ') + end redirect_to :back end |