Last active
April 24, 2020 05:21
-
-
Save jebai0521/5208e9bbef68a6ad48c2cc5895d17329 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getUrlParams() | |
{ | |
var url = window.location.toString(); | |
var qs = url.split("?")[1]; | |
if (!qs) return {}; | |
var params = {}; | |
qs.split('&').forEach(function(pair){ | |
var kv = pair.split('='); | |
params[kv[0]] = kv[1]; | |
}) | |
return params; | |
} | |
function autoUnlock() { | |
var params = getUrlParams(window.location.href) | |
console.log('getQueryString', params); | |
var password = params["storePassword"]; | |
var redirect = '/account/login' | |
if (!password) { | |
return; | |
} | |
var request = { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ password: password}) | |
} | |
var date = new Date() | |
date.setTime(date.getTime() + (1*24*60*60*1000)) | |
fetch('/password', request).then(function(res){ | |
window.location = redirect + '?email=' + params["email"] + "&password=" + params["password"] | |
// fire event indicate login result | |
}) | |
} | |
function autoLogin() { | |
let params1 = getUrlParams(window.location.href) | |
params2 = getUrlParams(decodeURIComponent(params1["return_url"])) | |
console.log('getQueryString', params2); | |
var email = params2["email"]; //; | |
var password = params2["password"];//; | |
var redirect = '/' | |
if (!email || !password) { | |
return; | |
} | |
var request = { | |
method: 'POST', | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json' | |
}, | |
redirect: 'manual', | |
body: JSON.stringify({ customer: { email: email, password: password }}) | |
} | |
var date = new Date() | |
date.setTime(date.getTime() + (1*24*60*60*1000)) | |
console.log(request); | |
document.cookie = 'passwordless_login=1; expires='+date.toUTCString()+'; path=/' | |
console.log('try to request', request); | |
fetch('/account/login', request).then(function(res){ | |
window.ReactNativeWebView.postMessage({'event':'sso', data:res}); | |
// window.location = redirect | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment