forked from gabrielsroka/gabrielsroka.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_account.html
66 lines (63 loc) · 2.13 KB
/
update_account.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
<!doctype html>
<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>Update Okta Account</title>
</head>
<body>
<div id=app></div>
<br>
<div id=error></div>
<script>
onload = async function () {
// For this to work, enable CORS in Okta: Security > API > Trusted Origins > Add Origin > CORS.
const baseUrl = 'https://gsroka-neto.oktapreview.com';
const init = {
credentials: 'include',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
};
try {
var response = await fetch(baseUrl + '/api/v1/users/me', init);
} catch (e) {
error.innerHTML = "Not logged in";
// TODO: send the user to login and come back to this page?
return;
}
const user = await response.json();
app.innerHTML = '<form><table><tr><td>Login<td>' + user.profile.login +
'<tr><td>Email<td>' + user.profile.email +
'<tr><td>Second Email *<td><input id=secondEmail value="' + user.profile.secondEmail + '">' +
'<tr><td>Mobile Phone *<td><input id=mobilePhone value="' + user.profile.mobilePhone + '">' +
'</table><button id=updateUser type=submit>Update</button></form>';
secondEmail.focus();
updateUser.onclick = async (event) => {
event.preventDefault();
if (!secondEmail.value || !mobilePhone.value) {
error.innerHTML = 'Please fill in all required fields.';
return;
}
error.innerHTML = '';
const body = {
profile: {
secondEmail: secondEmail.value,
mobilePhone: mobilePhone.value
}
};
init.body = JSON.stringify(body);
init.method = 'POST';
const response = await fetch(baseUrl + '/api/v1/users/me', init);
if (response.ok) {
const user = await response.json();
app.innerHTML = 'Your Okta account has been updated. You may close this window.';
} else {
const e = await response.json();
error.innerHTML = e.errorCauses[0].errorSummary;
}
}
};
</script>
</body>
</html>