Diff -- /var/www/vhosts/3dshawn.com/repricer.3dshawn.com/_attic/buyer_signup.cgi
Diff

/var/www/vhosts/3dshawn.com/repricer.3dshawn.com/_attic/buyer_signup.cgi

added on local at 2026-07-01 21:47:31

Added
+143
lines
Removed
-0
lines
Context
0
unchanged
Blobs
from
to 4ff34267eed7
Restore this content →
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.
1#!/usr/bin/perl
2#======================================================================
3# RePricer -- buyer signup.
4#
5# GET /buyer_signup.cgi?id=<storefront_id> → render form
6# POST /buyer_signup.cgi → create account + login
7#
8# On success: 302 to /my_orders.cgi?id=<storefront_id> with the
9# session cookie set. On failure: re-renders the form with an error.
10#======================================================================
11use strict;
12use warnings;
13
14use lib '/var/www/vhosts/3dshawn.com/repricer.3dshawn.com';
15use CGI;
16use MODS::Template;
17use MODS::DBConnect;
18use MODS::RePricer::Config;
19use MODS::RePricer::BuyerAuth;
20use MODS::RePricer::Themes;
21
22my $q = CGI->new;
23my $form = $q->Vars;
24my $tfile = MODS::Template->new;
25my $db = MODS::DBConnect->new;
26my $cfg = MODS::RePricer::Config->new;
27my $auth = MODS::RePricer::BuyerAuth->new;
28my $themes = MODS::RePricer::Themes->new;
29my $DB = $cfg->settings('database_name');
30
31$| = 1;
32
33my $sid = $form->{id} || $form->{storefront_id} || 0;
34$sid =~ s/[^0-9]//g;
35
36my $dbh = $db->db_connect();
37
38# Resolve the storefront so we can theme the page + redirect back.
39my $store;
40if ($sid) {
41 $store = $db->db_readwrite($dbh,
42 qq~SELECT id, name, subdomain, theme_id FROM `${DB}`.storefronts WHERE id='$sid' LIMIT 1~,
43 $ENV{SCRIPT_NAME}, __LINE__);
44}
45unless ($store && $store->{id}) {
46 $db->db_disconnect($dbh);
47 print "Status: 302 Found\nLocation: /\n\n";
48 exit;
49}
50
51my $err = '';
52my $email_in = '';
53my $name_in = '';
54
55if (($ENV{REQUEST_METHOD} || '') eq 'POST') {
56 $email_in = $form->{email} || '';
57 $name_in = $form->{display_name} || '';
58 my $pw = $form->{password} || '';
59
60 my $result = $auth->signup($db, $dbh, $DB, $store->{id}, $email_in, $pw, $name_in);
61 if (ref($result) eq 'HASH' && $result->{error}) {
62 $err = $result->{error};
63 } else {
64 # Auto-login the new account.
65 my ($buyer, $cookie) = $auth->login($db, $dbh, $DB, $store->{id}, $email_in, $pw);
66
67 # Link the visitor's existing tracking session to the new
68 # buyer_account so admin sees them flip from Guest -> Lead.
69 if ($buyer && $buyer->{id}) {
70 my $track_token = '';
71 my $raw_cookie = $ENV{HTTP_COOKIE} || '';
72 if ($raw_cookie =~ /(?:^|;\s*)repricer_track=([a-f0-9-]{36})/) {
73 $track_token = $1;
74 }
75 if ($track_token) {
76 require MODS::RePricer::Tracking;
77 my $tr = MODS::RePricer::Tracking->new;
78 $tr->link_session_to_buyer($db, $dbh, $DB, $track_token, $buyer->{id});
79 }
80
81 # Backfill any historic buyer_credit_ledger rows that were
82 # issued to this email while it was unregistered, so the new
83 # account inherits the credit balance instantly. Self-guards
84 # against the table being absent.
85 eval {
86 require MODS::RePricer::BuyerCredits;
87 my $bc = MODS::RePricer::BuyerCredits->new;
88 $bc->link_email_to_account($db, $dbh, $DB,
89 $store->{id}, $buyer->{id}, $email_in);
90 };
91 }
92
93 $db->db_disconnect($dbh);
94 print "Status: 302 Found\n";
95 print "Set-Cookie: $cookie\n" if $cookie;
96 print "Location: /my_orders.cgi?id=$store->{id}\n\n";
97 exit;
98 }
99}
100
101my $theme = $themes->by_id($store->{theme_id});
102my $css_vars = $themes->css_vars($theme);
103
104$db->db_disconnect($dbh);
105
106require MODS::RePricer::StoreChrome;
107my $chrome_dbh = $db->db_connect();
108my $chrome_html = MODS::RePricer::StoreChrome->header_html({
109 store_id => $store->{id},
110 store_name => $store->{name} || $store->{subdomain},
111 is_buyer_in => 0,
112 cart_count => 0,
113 db => $db,
114 dbh => $chrome_dbh,
115 DB => $DB,
116});
117$db->db_disconnect($chrome_dbh);
118
119my $tvars = {
120 theme_css_vars => $css_vars,
121 store_id => $store->{id},
122 store_name => _h($store->{name} || $store->{subdomain}),
123 store_chrome_html => $chrome_html,
124 email_value => _h($email_in),
125 name_value => _h($name_in),
126 has_error => $err ? 1 : 0,
127 error_message => _h($err),
128 login_href => "/buyer_login.cgi?id=$store->{id}",
129 back_href => "/store.cgi?id=$store->{id}",
130};
131
132print "Content-Type: text/html; charset=utf-8\nCache-Control: no-cache\n\n";
133print join('', $tfile->template('repricer_buyer_signup.html', $tvars, undef));
134
135sub _h {
136 my $s = shift;
137 $s //= '';
138 $s =~ s/&/&amp;/g;
139 $s =~ s/</&lt;/g;
140 $s =~ s/>/&gt;/g;
141 $s =~ s/"/&quot;/g;
142 return $s;
143}
Keyboard: j next diff k previous diff g top G bottom r restore c compile-check ? help