mirror of
https://github.com/HeyPuter/puter.git
synced 2026-01-05 20:50:22 -06:00
Add requestEmailConfirmation to puter.ui
This commit is contained in:
@@ -53,6 +53,14 @@ async function init_workers() {
|
||||
}
|
||||
|
||||
$(document).on('click', '.create-a-worker-btn', async function (e) {
|
||||
// if user doesn't have an email, request it
|
||||
if(!window.user?.email || !window.user?.email_confirmed){
|
||||
const email_confirm_resp = await puter.ui.requestEmailConfirmation();
|
||||
if(!email_confirm_resp)
|
||||
UIAlert('Email confirmation required to create a worker.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 1: Show file picker limited to .js files
|
||||
let selectedFile;
|
||||
try {
|
||||
|
||||
@@ -32,6 +32,8 @@ import update_mouse_position from './helpers/update_mouse_position.js';
|
||||
import item_icon from './helpers/item_icon.js';
|
||||
import UIPopover from './UI/UIPopover.js';
|
||||
import socialLink from './helpers/socialLink.js';
|
||||
import UIWindowEmailConfirmationRequired from './UI/UIWindowEmailConfirmationRequired.js';
|
||||
import UIWindowSaveAccount from './UI/UIWindowSaveAccount.js';
|
||||
|
||||
import { PROCESS_IPC_ATTACHED } from './definitions.js';
|
||||
|
||||
@@ -157,6 +159,55 @@ const ipc_listener = async (event, handled) => {
|
||||
// TODO: Respond to this
|
||||
}
|
||||
//--------------------------------------------------------
|
||||
// requestEmailConfirmation
|
||||
//--------------------------------------------------------
|
||||
else if(event.data.msg === 'requestEmailConfirmation'){
|
||||
// If the user has an email and it is confirmed, respond with success
|
||||
if(window.user.email && window.user.email_confirmed){
|
||||
target_iframe.contentWindow.postMessage({
|
||||
original_msg_id: msg_id,
|
||||
msg: 'requestEmailConfirmationResponded',
|
||||
response: true,
|
||||
}, '*');
|
||||
}
|
||||
|
||||
// If the user is a temporary user, show the save account window
|
||||
if(window.user.is_temp &&
|
||||
!await UIWindowSaveAccount({
|
||||
send_confirmation_code: true,
|
||||
message: 'Please create an account to proceed.',
|
||||
window_options: {
|
||||
backdrop: true,
|
||||
close_on_backdrop_click: false,
|
||||
}
|
||||
})){
|
||||
target_iframe.contentWindow.postMessage({
|
||||
original_msg_id: msg_id,
|
||||
msg: 'requestEmailConfirmationResponded',
|
||||
response: false,
|
||||
}, '*');
|
||||
return;
|
||||
}
|
||||
else if(!window.user.email_confirmed && !await UIWindowEmailConfirmationRequired()){
|
||||
target_iframe.contentWindow.postMessage({
|
||||
original_msg_id: msg_id,
|
||||
msg: 'requestEmailConfirmationResponded',
|
||||
response: false,
|
||||
}, '*');
|
||||
return;
|
||||
}
|
||||
|
||||
const email_confirm_resp = await UIWindowEmailConfirmationRequired({
|
||||
email: window.user.email,
|
||||
});
|
||||
|
||||
target_iframe.contentWindow.postMessage({
|
||||
original_msg_id: msg_id,
|
||||
msg: 'requestEmailConfirmationResponded',
|
||||
response: email_confirm_resp,
|
||||
}, '*');
|
||||
}
|
||||
//--------------------------------------------------------
|
||||
// ALERT
|
||||
//--------------------------------------------------------
|
||||
else if(event.data.msg === 'ALERT' && event.data.message !== undefined){
|
||||
|
||||
@@ -629,6 +629,12 @@ class UI extends EventListener {
|
||||
this.#onLaunchedWithItems = callback;
|
||||
}
|
||||
|
||||
requestEmailConfirmation = function() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.#postMessageWithCallback('requestEmailConfirmation', resolve, { });
|
||||
});
|
||||
}
|
||||
|
||||
alert = function(message, buttons, options, callback) {
|
||||
return new Promise((resolve) => {
|
||||
this.#postMessageWithCallback('ALERT', resolve, { message, buttons, options });
|
||||
|
||||
Reference in New Issue
Block a user