-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.html
129 lines (117 loc) · 4.43 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Slack Inviter</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript">
// ------------------------------------------------
// FIXME THESE VALUES SHOULD BE CUSTOMISED
var SLACK_TEAM_URL = "";
var AWS_LAMDBA_URL = "";
var SLACK_CHANNEL_IDS = "";
//
// ------------------------------------------------
</script>
<style type="text/css">
form {
max-width: 330px;
padding: 15px;
margin: 0 auto;
}
</style>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="container">
<form id="inputForm" action="fail.html">
<h1>Join our Slack</h1>
<p>Submit your email address below and we'll send you an invitation!</p>
<p>
<label for="inputEmail" class="sr-only">Email address</label>
<input class="form-control" type="email" id="inputEmail" placeholder="Email address" required autofocus>
</p>
<p>
<input class="btn btn-md btn-primary btn-block" type="submit" value="Join Slack">
</p>
<p id="slackDomain"></p>
<p id="errorMessage" style="color: #f00"></p>
</form>
</div>
<!-- scripts -->
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script type="text/javascript">
function validEmail(email) {
var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,})+$/;
return regex.test(email);
}
$( document ).ready(function() {
$.ajaxSetup({
url: AWS_LAMDBA_URL,
type: "POST",
crossDomain: true,
dataType: "json",
contentType: "application/json",
xhrFields: {
withCredentials: true
},
success: function (response) {
var resp = JSON.parse(response)
if (resp.ok) {
$( "#errorMessage" ).text('Now check your email!');
}
else if (resp.error == 'already_in_team') {
$( "#errorMessage" ).html("You've already joined this team! Please log in at <a href=\"" + SLACK_TEAM_URL + "\">" + SLACK_TEAM_URL + "</a>");
}
else if (resp.error == 'already_invited') {
$( "#errorMessage" ).html("You're already invited! Please check your email.");
}
else {
$( "#errorMessage" ).text("Error submitting '" + resp.error + "'");
}
}
});
$( "#slackDomain" ).html( '<a href=\"\"></a>' );
// email input form handler
$( "#inputEmail" ).on( "focus", function() {
$( "#inputEmail" ).attr( "style", "" )
$( "#errorMessage" ).text( "" )
});
$( "#inputForm" ).submit(function( event ) {
// prevent default action
event.preventDefault();
// get value from field
var email = $( "#inputEmail" ).val()
// check value is not empty
if (email == '' || !validEmail(email) ) {
$( "#inputEmail" ).attr( "style", "border: 1px solid #f00" );
$( "#errorMessage" ).text( "This '" + email + "' doesn't look like a valid email, please try again...");
}
/*
* TODO check value looks like an email address
*/
else {
// CORS REST call to to lambda service
var json = {
email : email
}
if (SLACK_CHANNEL_IDS != '') {
json.channel = SLACK_CHANNEL_IDS
}
$( "#errorMessage" ).text('Sending...');
$.ajax({
data: JSON.stringify(json),
error: function (xhr, errStatus) {
console.log('ERROR:' + JSON.stringify(xhr));
$( "#inputEmail" ).attr( "style", "border: 1px solid #f00" )
$( "#errorMessage" ).text( "Error! '" + xhr.error + "'")
}
});
}
});
});
</script>
</body>
</html>