Skip to content

Commit 4a20f90

Browse files
authored
Initial commit
1 parent fd160a6 commit 4a20f90

File tree

3 files changed

+164
-0
lines changed

3 files changed

+164
-0
lines changed

index.php

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<html>
2+
<head>
3+
<script src="jquery-3.0.0.min.js"></script>
4+
<script src="https://sdk.accountkit.com/en_US/sdk.js"></script>
5+
<style>
6+
body{
7+
font-family: tahoma;
8+
}
9+
.message {
10+
background-color: #222;
11+
border: 1px solid #dcdcdc;
12+
color: #fff;
13+
font-family: tahoma;
14+
margin-top: 84px;
15+
min-height: 250px;
16+
padding: 2px 45px;
17+
text-align: left;
18+
width: 50%;
19+
word-wrap: break-word;
20+
}
21+
</style>
22+
</head>
23+
24+
<body>
25+
<div>
26+
<center>
27+
<input value="+1" id="country_code" />
28+
<input placeholder="phone number" id="phone_number"/>
29+
<button onclick="smsLogin();">Login via SMS</button>
30+
<div>OR</div>
31+
<input placeholder="email" id="email"/>
32+
<button onclick="emailLogin();">Login via Email</button>
33+
34+
<div class="message">
35+
<p><center><b>Message Board</b></center></p>
36+
</div>
37+
</center>
38+
</div>
39+
40+
41+
<script>
42+
//https://developers.facebook.com/docs/accountkit/webjs
43+
$(".message").append("<p>initialized Account Kit.</p>");
44+
45+
// initialize Account Kit with CSRF protection
46+
AccountKit_OnInteractive = function(){
47+
AccountKit.init(
48+
{
49+
appId:"YOUR_FACEBOOK_APP_ID",
50+
state:"CSRF_TOKEN",
51+
version:"v1.0",
52+
fbAppEventsEnabled:true
53+
}
54+
);
55+
};
56+
57+
58+
// login callback
59+
function loginCallback(response) {
60+
if (response.status === "PARTIALLY_AUTHENTICATED") {
61+
var code = response.code;
62+
var csrf = response.state;
63+
$(".message").append("<p>Received auth token from facebook - "+ code +".</p>");
64+
$(".message").append("<p>Triggering AJAX for server-side validation.</p>");
65+
66+
$.post("verify.php", { code : code, csrf : csrf }, function(result){
67+
$(".message").append( "<p>Server response : " + result + "</p>" );
68+
});
69+
70+
}
71+
else if (response.status === "NOT_AUTHENTICATED") {
72+
// handle authentication failure
73+
$(".message").append("<p>( Error ) NOT_AUTHENTICATED status received from facebook, something went wrong.</p>");
74+
}
75+
else if (response.status === "BAD_PARAMS") {
76+
// handle bad parameters
77+
$(".message").append("<p>( Error ) BAD_PARAMS status received from facebook, something went wrong.</p>");
78+
}
79+
}
80+
81+
82+
// phone form submission handler
83+
function smsLogin() {
84+
var countryCode = document.getElementById("country_code").value;
85+
var phoneNumber = document.getElementById("phone_number").value;
86+
$(".message").append("<p>Triggering phone validation.</p>");
87+
AccountKit.login(
88+
'PHONE',
89+
{countryCode: countryCode, phoneNumber: phoneNumber}, // will use default values if not specified
90+
loginCallback
91+
);
92+
}
93+
94+
95+
// email form submission handler
96+
function emailLogin() {
97+
var emailAddress = document.getElementById("email").value;
98+
AccountKit.login(
99+
'EMAIL',
100+
{emailAddress: emailAddress},
101+
loginCallback
102+
);
103+
}
104+
</script>
105+
106+
</body>
107+
</html>

0 commit comments

Comments
 (0)