-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsigned-in.html
168 lines (160 loc) · 7.3 KB
/
signed-in.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<html>
<head>
<title>Signed in</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1" />
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<link rel="icon" type="image/png" href="img/favicon96.png" sizes="96x96" />
<link rel="icon" type="image/png" href="img/favicon32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="img/favicon16.png" sizes="16x16" />
<style>
body {
background: aliceblue;
font-family: 'Segoe UI', Helvetica, Arial, Sans-Serif;
}
</style>
<script src="scripts/util.js?v=1.5"></script>
<script src="scripts/model.js?v=1.21"></script>
<script>
/** Return from Azure 3rd-party sign-in.
* Check we have email and other user info.
*/
async function init() {
//alert("test pause - click to continue");
window.project = await Project.get();
text("header", window.project.title);
// checkUser looks up the user in our list.
// If not there, it adds what it can deduce from the x-ms- headers.
// This might include full name or email, depending on the 3rd party.
// We might have to look up the full name separately or ask for the email.
// If contributorRole is set for this project, new users are vetted. Otherwise, new users start off with the contributor role
fetch(window.location.origin + "/api/CheckUser" + (window.project.instantContributor ? "?role=" + "contributor:" + window.project.id.toLowerCase() : ""))
.then(r => r.json())
.then(r => {
let straightOut = true;
let showDoneButton = true;
if (!r.entries || r.entries.length == 0) {
show("nologin");
straightOut = false;
}
else {
let user = User.FromTableRow(r.entries[0]);
text("userName", user.displayName);
if (window.project.contributorRole && !user.isContributor) {
html("adminEmail", `<a href="mailto:${window.project.admin}">${window.project.admin}</a>`);
show("viewerLogin");
straightOut = false;
}
if (!user.email || !user.isValidated) {
show("noemail");
if (user.email) {
g("emailEntry").value = user.email;
text("explanation", "Please confirm your email address. We'll send you a code to check it.");
}
showDoneButton = false;
straightOut = false;
} else if (!user.fullName) {
getFullName();
straightOut = false;
}
}
if(showDoneButton) show("doneButton");
if (straightOut) done();
});
}
/** Get additional user info from the Azure 3rd-party sign-in system.
*/
function getFullName() {
fetch("/.auth/me")
.then(r => r.json())
.then(r => {
if (r.length > 0 && r[0].user_claims) {
for (let i = 0; i < r[0].user_claims.length; i++) {
let c = r[0].user_claims[i];
if (c.typ == "name" || c.typ.indexOf(":name") >= 0) {
if (c.val.indexOf("@") < 0) {
setUserName(c.val);
break;
}
}
}
}
});
}
/** Add the name of the currently signed-in user to our user table.
*/
function setUserName(name) {
fetch(window.location.origin + "/api/CheckUser?name=" + name)
.then(r => {
done();
});
}
function verifyEmail() {
let email = g("emailEntry").value.trim();
if (!email || email.length < 10 || email.indexOf("@") < 0) return;
g("verifyButton").disabled = true;
g("emailEntry").contentEditable = false;
fetch(window.location.origin + "/api/verifyEmail?email=" + email)
.then(r => {
// done();
g("doneButton").disabled = true;
show("emailSent");
setTimeout(() => {
text("doneButton", "Do it later");
g("doneButton").disabled = false;
show("doneButton");
}, 30000);
});
}
function checkToken(token) {
let email = g("emailEntry").value.trim();
fetch(window.location.origin + "/api/verifyEmail?token=" + token + "&email=" + email)
.then(r => {
done();
});
}
function done() {
// alert("done");
try {
window.localStorage.setItem("login", "close " + Date.now());
window.opener.signinDone();
} catch (exx) { }
if (window.location.queryParameters.straightin) {
location.replace(`${window.location.origin}?project='${location.queryParameters.project}'&view=${location.queryParameters.view}`);
} else {
window.close();
}
}
setCookie("assurance", "3");
</script>
</head>
<body onload="init()">
<h1 id="header"></h1>
<h3 id="userName"></h3>
<div id="nologin" style="display:none;">
Not logged in.
<button onclick="done()">OK</button>
</div>
<div id="viewerLogin" style="display:none;">
<p>Thank you for signing in to the Map! We're looking forward to seeing your contributions.
Before that can happen, a map administrator has to add you to the contributors' list.</p>
<p>
If you haven't yet done so, please contact
<span id="adminEmail"><a href="map@foliosuttoncoldfield.org.uk">map@foliosuttoncoldfield.org.uk</a>
to let us know that you've signed in.</span>
</p>
</div>
<div id="noemail" style="display:none;">
<h1>One more thing...</h1>
<p id="explanation">We don't have your email address. Could you please provide it:</p>
<input id="emailEntry" type="email" style="width: 40em;" />
<p>Thanks!</p>
<button id="verifyButton" onclick="verifyEmail()">Send</button>
<div id="emailSent" style="display:none;">
<p>We have sent an email containing a code ... please enter the code here: <input id="tokenInput" type="text"
onchange="checkToken(this.value.trim())" style="width:6em;" /></p>
<p>Can't find it? Look in your Spam or Junk folder.</p>
</div>
</div>
<button onclick="done()" id="doneButton" style="display:none">OK</button>
</body>
</html>