Site Builder
Editing:
choose-slug.php
writable 0666
<?php /***************************************************************** * Google‑OAuth “finish signup” page (styled + phone masking) *****************************************************************/ require_once __DIR__.'/../lib/db.php'; require_once __DIR__.'/../lib/auth.php'; session_start(); /* 0. Pending Google data (set by google‑callback.php) */ $data = $_SESSION['g_pending'] ?? null; if (!$data) { header('Location: /members/login.php'); exit; } /* 1. Handle POST ------------------------------------------------ */ $err=''; if ($_SERVER['REQUEST_METHOD']==='POST') { $type = $_POST['acct_type'] ?? ''; $raw = trim($_POST['slug_raw'] ?? ''); // ← raw, un‑masked /* validate + normalise */ if ($type==='business') { $slug = preg_replace('/\D/','',$raw); // keep digits if (strlen($slug)!==10) $err='Enter a 10‑digit US phone'; } elseif ($type==='social') { $slug = strtolower($raw); if(!preg_match('/^[A-Za-z0-9_-]{3,32}$/',$slug)) $err='3‑32 letters, numbers, _ or -'; } else $err='Choose account type'; /* slug unique among usernames *or* site_slugs */ if(!$err){ $dup=$db->prepare('SELECT 1 FROM users WHERE username=? OR site_slug=? LIMIT 1'); $dup->execute([$slug,$slug]); if($dup->fetch()) $err='That slug is already taken'; } /* 2. persist */ if(!$err){ $db->beginTransaction(); $db->prepare('INSERT INTO users (username,email,password_hash,acct_type,site_slug,signup_ip, google_sub,google_name,referred_by) VALUES (?,?,?,?,?,inet6_aton(?),?,?,?)') ->execute([ $slug, // username = slug $data['email'], // email '', // no local pwd $type, $slug, $_SERVER['REMOTE_ADDR'], $data['sub'], $data['name'], (preg_match('/^[A-Za-z0-9_-]{3,32}$/',$_COOKIE['bdo_ref']??'') ? $_COOKIE['bdo_ref'] : null) ]); $uid=$db->lastInsertId(); // assume $type is either 'business' or something else $extra = $type === 'business' ? 'edit-business' : 'edit-social'; // build a single slug list $slugs = array_merge( [$extra], ['boundary','coupon','links','prompts'] ); // run one INSERT … SELECT $db->exec(" INSERT INTO user_pages (user_id, page_id) SELECT $uid, id FROM pages WHERE slug IN ('" . implode("','", $slugs) . "') "); $db->commit(); unset($_SESSION['g_pending']); $_SESSION['uid']=$uid; header('Location: /members/dashboard.php'); exit; } } ?> <!doctype html> <title>Finish sign‑up – BestDealOn</title> <meta name=viewport content="width=device-width,initial-scale=1"> <style> :root{ --bg:#f6f7fb;--card:#fff;--brand:#0366d6;--brand-d:#0254b3; --text:#202124;--radius:10px; } *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI', Roboto,Helvetica,Arial,sans-serif;margin:0;padding:0} body{background:var(--bg);color:var(--text);display:flex;min-height:100vh; align-items:center;justify-content:center} main{width:clamp(320px,92vw,450px);background:var(--card);border-radius:var(--radius); box-shadow:0 8px 24px rgba(0,0,0,.08);padding:2.2rem 1.8rem} h2{font-size:1.8rem;font-weight:700;margin-bottom:.8rem;text-align:center} label{display:block;font-size:.9rem;margin:.8rem 0 .35rem;font-weight:600} input,select,button{width:100%;padding:.63rem .75rem;font-size:1rem; border:1px solid #c7cace;border-radius:6px} input:invalid{border-color:#d33} input:focus,select:focus{outline:2px solid var(--brand);border-color:var(--brand)} button{margin-top:1.4rem;background:var(--brand);color:#fff;border:0;font-weight:600;cursor:pointer} button:hover{background:var(--brand-d)} .error{background:#ffe1e1;color:#c00;padding:.8rem 1rem;border-radius:6px; margin-bottom:1rem;text-align:center} small.help{display:block;font-size:.8rem;color:#666;margin-top:.25rem} </style> <main> <h2>Hello, <?= htmlspecialchars($data['name']) ?>!</h2> <p style="text-align:center">Please finish setting up your account.</p> <?php if($err): ?> <p class=error><?= htmlspecialchars($err) ?></p> <?php endif; ?> <form method=post novalidate> <label for=acctType>Account type</label> <select name=acct_type id=acctType required> <option value="">Choose…</option> <option value=business <?=($_POST['acct_type']??'')==='business'?'selected':''?>>Business</option> <option value=social <?=($_POST['acct_type']??'')==='social' ?'selected':''?>>Social / Influencer</option> </select> <label for=slugInput id=slugLabel>Business phone (10 digits)</label> <!-- visible input (masked for phone) --> <input id=slugInput placeholder="727‑610‑1188" autocomplete="off" value="<?= htmlspecialchars($_POST['slug_raw']??'') ?>"> <small id=helpTxt class=help>Digits only – no dashes</small> <!-- hidden, real value will be copied here on submit --> <input type=hidden name=slug_raw id=slugRaw> <button>Create my site</button> </form> </main> <script> const sel = document.getElementById('acctType'); const vis = document.getElementById('slugInput'); const raw = document.getElementById('slugRaw'); const lbl = document.getElementById('slugLabel'); const help = document.getElementById('helpTxt'); /* on‑type phone masker */ function maskPhone(v){ const digits=v.replace(/\D/g,'').slice(0,10); if(digits.length<=3) return digits; if(digits.length<=6) return digits.slice(0,3)+'-'+digits.slice(3); return digits.slice(0,3)+'-'+digits.slice(3,6)+'-'+digits.slice(6); } /* swap UI between business / social */ function updateUI(){ if(sel.value==='social'){ lbl.textContent='Public handle (3–32 letters, numbers, _ or -)'; vis.placeholder='mybrand'; help.textContent='3–32 characters • letters, numbers, _ or -'; vis.value=vis.value.replace(/\s+/g,''); }else{ lbl.textContent='Business phone (10 digits)'; vis.placeholder='727‑610‑1188'; help.textContent='Digits only – no dashes'; vis.value=maskPhone(vis.value); } } /* enforce masking while typing (business) */ vis.addEventListener('input',()=>{ if(sel.value==='business'){ const pos=vis.selectionStart; vis.value=maskPhone(vis.value); vis.setSelectionRange(pos,pos); } }); /* copy clean value to hidden field before submit */ document.querySelector('form').addEventListener('submit',e=>{ if(sel.value==='business'){ raw.value=vis.value.replace(/\D/g,''); // 10 digits }else{ raw.value=vis.value.trim(); } }); sel.addEventListener('change',updateUI); updateUI(); /* initial */ </script>
Save changes
Create folder
writable 0777
Create
Cancel