2014-05-16 19:39:37 +00:00
|
|
|
class ApiInvitedUsersController < ApiController
|
2013-03-21 06:47:35 +00:00
|
|
|
|
|
|
|
|
# have to be signed in currently to see this screen
|
|
|
|
|
before_filter :api_signed_in_user
|
|
|
|
|
|
|
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
@invited_users = InvitedUser.index(current_user)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def show
|
2014-02-10 18:12:03 +00:00
|
|
|
if InvitedUser::FB_MEDIUM == params[:id]
|
2014-01-30 04:49:36 +00:00
|
|
|
@invited_user = current_user.facebook_invite!
|
|
|
|
|
else
|
|
|
|
|
@invited_user = InvitedUser.find(params[:id])
|
|
|
|
|
end
|
2013-03-21 06:47:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
2014-02-25 03:29:03 +00:00
|
|
|
@invited_users = []
|
|
|
|
|
if (emails = params[:emails]).present?
|
2014-03-01 03:07:48 +00:00
|
|
|
emails = emails[0...Rails.application.config.max_email_invites_per_request].uniq
|
2020-04-04 22:51:36 +00:00
|
|
|
if emails.include?(current_user.email)
|
|
|
|
|
@responseobject = { :errors => { :email => ["can't be your own address"]}}
|
|
|
|
|
render :json => @responseobject, :status => :unprocessable_entity, layout: nil
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2020-05-09 14:17:00 +00:00
|
|
|
# remove due to spammers
|
2014-02-25 03:29:03 +00:00
|
|
|
msg = params[:note].blank? ? nil : params[:note].strip
|
2020-05-09 14:17:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-01 03:07:48 +00:00
|
|
|
@invited_users = emails.collect do |ee|
|
2014-02-25 03:29:03 +00:00
|
|
|
iu = InvitedUser.new
|
|
|
|
|
iu.sender = current_user
|
2014-03-01 03:07:48 +00:00
|
|
|
iu.email = ee.strip
|
2014-02-25 03:29:03 +00:00
|
|
|
iu.autofriend = true
|
|
|
|
|
iu.note = msg
|
|
|
|
|
iu.save
|
2020-04-04 22:51:36 +00:00
|
|
|
|
|
|
|
|
if iu.receiver
|
|
|
|
|
# automatically create friend request for an invitation to an existing user
|
|
|
|
|
FriendRequest.save(nil,
|
|
|
|
|
current_user.id,
|
|
|
|
|
iu.receiver.id,
|
|
|
|
|
nil,
|
|
|
|
|
msg)
|
|
|
|
|
end
|
2014-02-25 03:29:03 +00:00
|
|
|
iu
|
|
|
|
|
end
|
2014-03-03 00:51:06 +00:00
|
|
|
else
|
|
|
|
|
iu = InvitedUser.new
|
|
|
|
|
iu.sender = current_user
|
|
|
|
|
iu.save
|
|
|
|
|
@invited_users = [iu]
|
|
|
|
|
end
|
|
|
|
|
if err = @invited_users.detect {|iu| iu.errors.any? }
|
|
|
|
|
response.status = :unprocessable_entity
|
|
|
|
|
respond_with err
|
2013-03-21 06:47:35 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-05-09 14:17:00 +00:00
|
|
|
end
|