Merge pull request #25 from unraid/refactor/regwiz-sign-in

refactor: regwiz sign in postmessage handler
This commit is contained in:
Eric Schultz
2020-11-02 22:27:30 -07:00
committed by GitHub
+21 -28
View File
@@ -1199,35 +1199,28 @@ function handleMessage(e) {
break;
case "REG_WIZARD":
if (data.apikey) {
$.post('https://keys.lime-technology.com/ips/details', {'apikey': data.apikey}, function(details) {
var postargs = {
'#file': 'dynamix/dynamix.cfg',
'#section': 'remote',
apikey: data.apikey,
regWizTime: Date.now(), // set when signing in the first time and never unset for the sake of displaying Sign In/Up in the UPC without needing to validate guid every time
};
if (data.email) {
postargs['email'] = data.email; // this is also never unset but only "reset" if with instance of sign in
}
if (details.username) {
postargs['username'] = details.username;
}
if (details.avatar) {
postargs['avatar'] = details.avatar;
}
$.post('/update.php', postargs, function() {
console.log('dynamix/dynamix.cfg: Updated apikey under [remote] section');
// send a ping back to the regwiz
const payload = { event: 'ACCOUNT_PINGBACK', success: true, type: 'signIn', webGuiPathname: window.location.pathname };
e.source.postMessage(JSON.stringify(payload), e.origin);
}).fail(function() {
console.error('Failed to update apikey under [remote] section');
// send a ping back to the regwiz
const payload = { event: 'ACCOUNT_PINGBACK', success: false, type: 'signIn', webGuiPathname: window.location.pathname };
e.source.postMessage(JSON.stringify(payload), e.origin);
});
var postargs = {
'#file': 'dynamix/dynamix.cfg',
'#section': 'remote',
apikey: data.apikey,
regWizTime: Date.now(), // set when signing in the first time and never unset for the sake of displaying Sign In/Up in the UPC without needing to validate guid every time
};
if (data.email) {
postargs['email'] = data.email;
}
if (data.username) {
postargs['username'] = data.username;
}
if (data.avatar) {
postargs['avatar'] = data.avatar;
}
$.post('/update.php', postargs, function() {
console.log('dynamix/dynamix.cfg: Updated apikey under [remote] section');
// send a ping back to the regwiz
const payload = { event: 'ACCOUNT_PINGBACK', success: true, type: 'signIn', webGuiPathname: window.location.pathname };
e.source.postMessage(JSON.stringify(payload), e.origin);
}).fail(function() {
console.error('Failed to retrieve details from key server');
console.error('Failed to update apikey under [remote] section');
// send a ping back to the regwiz
const payload = { event: 'ACCOUNT_PINGBACK', success: false, type: 'signIn', webGuiPathname: window.location.pathname };
e.source.postMessage(JSON.stringify(payload), e.origin);