-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemailValidation.html
More file actions
60 lines (55 loc) · 1.88 KB
/
Copy pathemailValidation.html
File metadata and controls
60 lines (55 loc) · 1.88 KB
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
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Email validation</title>
<link rel="icon" type="image/png" href="assets/images/favicon.png">
<script type="text/javascript" src="https://tonyzub.github.io/FinanceAPI/libs/code.js"></script>
</head>
<body>
</body>
<script>
const CHECK_EMAIL_FUNCTION_PARAMETER = "func";
const VALIDATION_TOKEN_PARAMETER = "param";
function TryValidateEmail(){
let url = new URL(window.location.href);
let checkEmailFunctionName = url.searchParams.get(CHECK_EMAIL_FUNCTION_PARAMETER);
let validationToken = url.searchParams.get(VALIDATION_TOKEN_PARAMETER);
CheckEmail(checkEmailFunctionName, validationToken);
}
function CheckEmail(functionName, validationToken){
let request = MakeRequest("POST", functionName, validationToken);
request.onload = function() {
if (request.status != 200) {
console.log(request.status);
switch(request.status){
case 404:
OpenURL(NOT_FOUND_URL, PAGE_TARGETS.self);
break;
default:
alert("Server error occured, try later");
break;
}
}
else {
let responseJSON = JSON.parse(request.response);
console.log(responseJSON);
if(responseJSON.isValidated){
SetCookie("Token", responseJSON.token);
SetCookie("Username", responseJSON.username);
OpenURL(MAIN_PAGE_URL, PAGE_TARGETS.self);
}
else{
alert("Your email is not validated, the link is too old");
}
};
};
request.onerror = function(request) {
alert("Connection error");
};
}
window.onload = function() {
TryValidateEmail();
};
</script>
</html>