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

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

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

Added
+122
lines
Removed
-0
lines
Context
0
unchanged
Blobs
from
to ef50c46b993d
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 login.
4#
5# GET /buyer_login.cgi?id=<storefront_id> → render form
6# POST /buyer_login.cgi → authenticate + set cookie
7#======================================================================
8use strict;
9use warnings;
10
11use lib '/var/www/vhosts/3dshawn.com/repricer.3dshawn.com';
12use CGI;
13use MODS::Template;
14use MODS::DBConnect;
15use MODS::RePricer::Config;
16use MODS::RePricer::BuyerAuth;
17use MODS::RePricer::Themes;
18
19my $q = CGI->new;
20my $form = $q->Vars;
21my $tfile = MODS::Template->new;
22my $db = MODS::DBConnect->new;
23my $cfg = MODS::RePricer::Config->new;
24my $auth = MODS::RePricer::BuyerAuth->new;
25my $themes = MODS::RePricer::Themes->new;
26my $DB = $cfg->settings('database_name');
27
28$| = 1;
29
30my $sid = $form->{id} || $form->{storefront_id} || 0;
31$sid =~ s/[^0-9]//g;
32
33my $dbh = $db->db_connect();
34my $store;
35if ($sid) {
36 $store = $db->db_readwrite($dbh,
37 qq~SELECT id, name, subdomain, theme_id FROM `${DB}`.storefronts WHERE id='$sid' LIMIT 1~,
38 $ENV{SCRIPT_NAME}, __LINE__);
39}
40unless ($store && $store->{id}) {
41 $db->db_disconnect($dbh);
42 print "Status: 302 Found\nLocation: /\n\n";
43 exit;
44}
45
46my $err = '';
47my $email_in = '';
48
49if (($ENV{REQUEST_METHOD} || '') eq 'POST') {
50 $email_in = $form->{email} || '';
51 my $pw = $form->{password} || '';
52
53 my ($buyer, $cookie) = $auth->login($db, $dbh, $DB, $store->{id}, $email_in, $pw);
54 if (ref($buyer) eq 'HASH' && $buyer->{error}) {
55 $err = $buyer->{error};
56 } elsif ($buyer && $buyer->{id}) {
57 # Link this visitor's tracking session to the buyer account so
58 # the admin visitor list + chat can flag them as a Customer /
59 # Lead and show their order count + LTV.
60 my $track_token = '';
61 my $raw_cookie = $ENV{HTTP_COOKIE} || '';
62 if ($raw_cookie =~ /(?:^|;\s*)repricer_track=([a-f0-9-]{36})/) {
63 $track_token = $1;
64 }
65 if ($track_token) {
66 require MODS::RePricer::Tracking;
67 my $tr = MODS::RePricer::Tracking->new;
68 $tr->link_session_to_buyer($db, $dbh, $DB, $track_token, $buyer->{id});
69 }
70
71 $db->db_disconnect($dbh);
72 print "Status: 302 Found\n";
73 print "Set-Cookie: $cookie\n" if $cookie;
74 print "Location: /my_orders.cgi?id=$store->{id}\n\n";
75 exit;
76 } else {
77 $err = 'login failed';
78 }
79}
80
81my $theme = $themes->by_id($store->{theme_id});
82my $css_vars = $themes->css_vars($theme);
83
84$db->db_disconnect($dbh);
85
86require MODS::RePricer::StoreChrome;
87my $chrome_dbh = $db->db_connect();
88my $chrome_html = MODS::RePricer::StoreChrome->header_html({
89 store_id => $store->{id},
90 store_name => $store->{name} || $store->{subdomain},
91 is_buyer_in => 0,
92 cart_count => 0,
93 db => $db,
94 dbh => $chrome_dbh,
95 DB => $DB,
96});
97$db->db_disconnect($chrome_dbh);
98
99my $tvars = {
100 theme_css_vars => $css_vars,
101 store_id => $store->{id},
102 store_name => _h($store->{name} || $store->{subdomain}),
103 store_chrome_html => $chrome_html,
104 email_value => _h($email_in),
105 has_error => $err ? 1 : 0,
106 error_message => _h($err),
107 signup_href => "/buyer_signup.cgi?id=$store->{id}",
108 back_href => "/store.cgi?id=$store->{id}",
109};
110
111print "Content-Type: text/html; charset=utf-8\nCache-Control: no-cache\n\n";
112print join('', $tfile->template('repricer_buyer_login.html', $tvars, undef));
113
114sub _h {
115 my $s = shift;
116 $s //= '';
117 $s =~ s/&/&amp;/g;
118 $s =~ s/</&lt;/g;
119 $s =~ s/>/&gt;/g;
120 $s =~ s/"/&quot;/g;
121 return $s;
122}
Keyboard: j next diff k previous diff g top G bottom r restore c compile-check ? help