-
Notifications
You must be signed in to change notification settings - Fork 191
/
invite_controller.rb
135 lines (115 loc) · 3.49 KB
/
invite_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
require 'spaceship'
class InviteController < ApplicationController
before_action :set_app_details
before_action :check_disabled_text
before_action :check_imprint_url
skip_before_filter :verify_authenticity_token
def index
if boarding_service.user and boarding_service.password
# default
@email = params[:email]
else
render 'environment_error'
end
rescue => ex
update_spaceship_message
raise ex
end
def update_spaceship_message
Rails.logger.fatal("--------------------------------------------------------------------------------")
Rails.logger.fatal("Error rendering the page, make sure to update to the latest version of spaceship")
Rails.logger.fatal("More information about how to do so can be found on the project README")
Rails.logger.fatal("--------------------------------------------------------------------------------")
end
def submit
if @message # from a `before_action`
render :index
return
end
email = params[:email]
first_name = params[:first_name]
last_name = params[:last_name]
if ENV["RESTRICTED_DOMAIN"]
domains = ENV["RESTRICTED_DOMAIN"].split(",")
unless domains.include?(email.split("@").last)
if domains.count == 1
@message = "Sorry! Early access is currently restricted to people within the #{domains.first} domain."
else
@message = "Sorry! Early access is currently restricted to people within the following domains: (#{domains.join(", ")})"
end
@type = "warning"
render :index
return
end
end
if boarding_service.itc_token
if boarding_service.itc_token != params[:token]
@message = t(:message_invalid_password)
@type = "danger"
render :index
return
end
end
if email.length == 0
render :index
return
end
if boarding_service.is_demo
@message = t(:message_demo_page)
@type = "success"
render :index
return
end
logger.info "Creating a new tester: #{email} - #{first_name} #{last_name}"
begin
create_and_add_tester(email, first_name, last_name)
rescue => ex
Rails.logger.fatal ex.inspect
Rails.logger.fatal ex.backtrace.join("\n")
@message = [t(:message_error), ex.to_s].join(": ")
@type = "danger"
end
render :index
rescue => ex
update_spaceship_message
raise ex
end
private
def create_and_add_tester(email, first_name, last_name)
add_tester_response = boarding_service.add_tester(email, first_name, last_name)
@message = add_tester_response.message
@type = add_tester_response.type
end
def boarding_service
BOARDING_SERVICE
end
def app_metadata
Rails.cache.fetch('appMetadata', expires_in: 10.minutes) do
{
icon_url: boarding_service.app.app_icon_preview_url,
title: boarding_service.app.name
}
end
end
def set_app_details
@metadata = app_metadata
@title = @metadata[:title]
tabIcon = ENV["TAB_ICON"].to_s
if tabIcon.to_s.length == 0
@tabIcon = "/BoardingIcon.ico"
else
@tabIcon = tabIcon
end
end
def check_disabled_text
if boarding_service.itc_closed_text
@message = boarding_service.itc_closed_text
@type = "warning"
end
end
def check_imprint_url
if boarding_service.imprint_url
@imprint_url = boarding_service.imprint_url
end
end
end