Skip to content

Instantly share code, notes, and snippets.

@taranjeet
Created February 1, 2020 11:25
Show Gist options
  • Save taranjeet/b91684a1e07e377b877bc3bbf028d55a to your computer and use it in GitHub Desktop.
Save taranjeet/b91684a1e07e377b877bc3bbf028d55a to your computer and use it in GitHub Desktop.
# logindemo/index.html
{% extends "__base.html" %}
{% block container %}
<div class="card" style="height:400px; width:400px;">
<div class="card-body">
<h5 class="card-title">
Account Kit Login Demo
</h5>
<div class="row mt-5">
<div class="col-12">
<button type="button" class="btn btn-primary btn-block" onClick="loginWithSMS()">Login With SMS</button>
</div>
</div>
<form id="loginForm" name="loginForm" action="/sendcode" method="POST" style="display: none;">
<input type="text" id="code" name="code">
{% csrf_token %}
<input type="submit" value="Submit">
</form>
</div>
</div>
{% endblock %}
{% block js %}
<script src="https://sdk.accountkit.com/en_US/sdk.js"></script>
<script type="text/javascript">
AccountKit_OnInteractive = function(){
AccountKit.init(
{
appId:'{{ app_id }}',
state:"{{csrf_token}}",
version:"{{ api_version }}",
debug: true,
redirect:"/sendcode"
}
);
};
function loginCallback(response) {
if (response.status === "PARTIALLY_AUTHENTICATED") {
document.getElementById("code").value = response.code;
document.getElementsByName("csrfmiddlewaretoken")[0].value = response.state;
document.getElementById("loginForm").submit();
// here send a ajax call.
}
else if (response.status === "NOT_AUTHENTICATED") {
// handle authentication failure
}
else if (response.status === "BAD_PARAMS") {
// handle bad parameters
}
}
function loginWithSMS(){
AccountKit.login("PHONE",{}, loginCallback);
}
</script>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment