Procházet zdrojové kódy

20220916 不開放同一議程重複報名(用 company email 和 phone number 判斷)

LuluFJ.Ho před 2 roky
rodič
revize
69d676dad5

+ 7
- 35
app/Http/Controllers/Api/SeminarSignUpController.php Zobrazit soubor

@@ -61,9 +61,10 @@ class SeminarSignUpController extends ApiController
61 61
         $consentAcceptEmail = $request->input('consentAcceptEmail', '');
62 62
         $consentPrivacyPolicy = $request->input('consentPrivacyPolicy', '');
63 63
         
64
-        $overOrNot = $this->seminarSignUpSv->overLimitOrNot($trackNo);
64
+        $overOrNot = $this->seminarSignUpSv->overLimitOrNot($trackNo);          // true: 可報名 / false: 已額滿
65
+        $duplicatedOrNot = $this->seminarSignUpSv->duplicatedOrNot($trackNo, $companyEmail, $phoneNumber);   // true: 可報名 / false: 已重複
65 66
 
66
-        if ($overOrNot) {
67
+        if ($overOrNot&&$duplicatedOrNot) {
67 68
 
68 69
             $this->seminarSignUpSv->insertData(
69 70
                 $firstName, 
@@ -98,9 +99,12 @@ class SeminarSignUpController extends ApiController
98 99
                 $this->mailToUser_EN($firstName_orig, $companyEmail_orig, $backupEmail_orig);
99 100
             }
100 101
             
101
-        } else {
102
+        } elseif (!$overOrNot) {
102 103
 
103 104
             $res = '已達報名上限';
105
+        } elseif (!$duplicatedOrNot) {
106
+
107
+            $res = '已重複報名';
104 108
         }
105 109
         $data = [
106 110
             'res' => $res,
@@ -125,22 +129,6 @@ class SeminarSignUpController extends ApiController
125 129
      */
126 130
     public function safeEncrypt(string $message, string $skey): string
127 131
     {
128
-        // if (mb_strlen($key, '8bit') !== SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
129
-        //     throw new RangeException('Key is not the correct size (must be 32 bytes).');
130
-        // }
131
-        // $nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
132
-        
133
-        // $cipher = base64_encode(
134
-        //     $nonce .
135
-        //     sodium_crypto_secretbox(
136
-        //         $message,
137
-        //         $nonce,
138
-        //         $key
139
-        //     )
140
-        // );
141
-        // sodium_memzero($message);
142
-        // sodium_memzero($key);
143
-        // return $cipher;
144 132
         $strArr = str_split(base64_encode($message));
145 133
         $strCount = count($strArr);
146 134
         foreach (str_split($skey) as $key => $value)
@@ -153,22 +141,6 @@ class SeminarSignUpController extends ApiController
153 141
      */
154 142
     public function safeDecrypt(string $encrypted, string $skey): string
155 143
     {
156
-        // $decoded = base64_decode($encrypted);
157
-        // $nonce = mb_substr($decoded, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit');
158
-        // $ciphertext = mb_substr($decoded, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit');
159
-        
160
-        // $plain = sodium_crypto_secretbox_open(
161
-        //     $ciphertext,
162
-        //     $nonce,
163
-        //     $key
164
-        // );
165
-        // if (!is_string($plain)) {
166
-        //     throw new Exception('Invalid MAC');
167
-        // }
168
-        // sodium_memzero($ciphertext);
169
-        // sodium_memzero($key);
170
-        
171
-        // return $plain;
172 144
         $strArr = str_split(str_replace(array('O0O0O', 'o000o', 'oo00o'), array('=', ' ', '/'), $encrypted), 2);
173 145
         $strCount = count($strArr);
174 146
         foreach (str_split($skey) as $key => $value)

+ 22
- 2
app/Http/Services/Api/SeminarSignUpService.php Zobrazit soubor

@@ -22,8 +22,8 @@ class SeminarSignUpService
22 22
     
23 23
     public function insertData(
24 24
         $firstName, $lastName, $companyName, $companyEmail, $backupEmail, $phoneNumber, $country, $trackNo, 
25
-        $registeredSession, $lunchOptions, $typeOfIndustry, $typeOfJob, $jobTitle, $trackOfInterest, $areaOfInterest, $howToKnowAboutTheEvent, 
26
-        $consentAcceptEmail, $consentPrivacyPolicy)
25
+        $registeredSession, $lunchOptions, $typeOfIndustry, $typeOfJob, $jobTitle, $trackOfInterest, $areaOfInterest, 
26
+        $howToKnowAboutTheEvent, $consentAcceptEmail, $consentPrivacyPolicy)
27 27
     {
28 28
         
29 29
         $this->signupDb
@@ -53,6 +53,7 @@ class SeminarSignUpService
53 53
     
54 54
     public function overLimitOrNot($trackNo)
55 55
     {
56
+        $nowCount = 0;
56 57
 
57 58
         $nowCount = $this->signupDb
58 59
             ->where('trackNo', '=', $trackNo)
@@ -70,6 +71,25 @@ class SeminarSignUpService
70 71
         }
71 72
     }
72 73
     
74
+    public function duplicatedOrNot($trackNo, $companyEmail, $phoneNumber)
75
+    {
76
+        $cnt = 0;
77
+
78
+        $cnt = $this->signupDb
79
+            ->where('trackNo', '=', $trackNo)
80
+            ->where('companyEmail', '=', $companyEmail)
81
+            ->where('phoneNumber', '=', $phoneNumber)
82
+            ->count();
83
+        
84
+        \Log::info($cnt);
85
+
86
+        if ($cnt==0) {
87
+            return true;
88
+        } else {
89
+            return false;
90
+        }
91
+    }
92
+    
73 93
     public function getData()
74 94
     {
75 95