Class: InvitationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/invitations_controller.rb

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Instance Method Summary collapse

Instance Method Details

#createObject


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/invitations_controller.rb', line 24

def create
  emails = inviter_params[:emails].split(",").map(&:strip).uniq

  valid_emails, invalid_emails = emails.partition {|email| valid_email?(email) }

  session[:valid_email_invites] = valid_emails
  session[:invalid_email_invites] = invalid_emails

  unless valid_emails.empty?
    Workers::Mail::InviteEmail.perform_async(valid_emails.join(","), current_user.id, inviter_params)
  end

  if emails.empty?
    flash[:error] = t("invitations.create.empty")
  elsif invalid_emails.empty?
    flash[:notice] = t("invitations.create.sent", emails: valid_emails.join(", "))
  elsif valid_emails.empty?
    flash[:error] = t("invitations.create.rejected", emails: invalid_emails.join(", "))
  else
    flash[:error] = t("invitations.create.sent", emails: valid_emails.join(", ")) + ". " +
      t("invitations.create.rejected", emails: invalid_emails.join(", "))
  end

  redirect_back fallback_location: stream_path
end

#newObject


11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/invitations_controller.rb', line 11

def new
  @invite_code = current_user.invitation_code

  @invalid_emails = html_safe_string_from_session_array(:invalid_email_invites)
  @valid_emails   = html_safe_string_from_session_array(:valid_email_invites)

  respond_to do |format|
    format.html do
      render "invitations/new", layout: false
    end
  end
end