Skip to content

Commit

Permalink
fix: bugs found in mail verification
Browse files Browse the repository at this point in the history
  • Loading branch information
elpwc committed Jul 19, 2024
1 parent 31beeea commit afe6ed4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
4 changes: 4 additions & 0 deletions public/api/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

session_start();

$request_type = $_SERVER['REQUEST_METHOD']; //请求类型GET POST PUT DELETE
$json = file_get_contents('php://input'); //获取CURL GET POST PUT DELETE 请求的数据
$data = json_decode($json);

switch ($request_type) {
case 'POST':
@$email = trim((string)($data->email));
Expand Down
24 changes: 12 additions & 12 deletions public/api/private/emailcfg.example.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php
$i = 2;
if($i == 1){
define("HOST", "smtp.yajuu.com");
define("USER", "tadokoro");
define("PASS", "114514simokitazawa");
define("SECURE", 'TLS');
define("PORT", 587);
define("MAIL",'[email protected]');
define("EMAIL_HOST", "smtp.yajuu.com");
define("EMAIL_USER", "tadokoro");
define("EMAIL_PASS", "114514simokitazawa");
define("EMAIL_SECURE", 'TLS');
define("EMAIL_PORT", 587);
define("EMAIL_MAIL",'[email protected]');
}else if($i == 2){
define("HOST", "smtp.1919.jp");
define("USER", "kmr514");
define("PASS", "yametekureyo~");
define("SECURE", 'SSL');
define("PORT", 587);
define("MAIL",'[email protected]');
define("EMAIL_HOST", "smtp.1919.jp");
define("EMAIL_USER", "kmr514");
define("EMAIL_PASS", "yametekureyo~");
define("EMAIL_SECURE", 'SSL');
define("EMAIL_PORT", 587);
define("EMAIL_MAIL",'[email protected]');
}else{

}
8 changes: 5 additions & 3 deletions public/api/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
require './utils.php';
require './sqlgenerator.php';

session_start();

$request_type = $_SERVER['REQUEST_METHOD']; //请求类型GET POST PUT DELETE
$json = file_get_contents('php://input'); //获取CURL GET POST PUT DELETE 请求的数据
$data = json_decode($json);
Expand All @@ -27,7 +29,7 @@
@$verify_code = trim((string)($data->verify_code));
@$pw = trim((string)($data->pw));

if ($verify_code == $_SESSION["verify_code"]) {
if ($_SESSION["verify_code"] != '' && $verify_code == $_SESSION["verify_code"]) {

unset($_SESSION['verify_code']);

Expand All @@ -50,8 +52,8 @@
} else {
// not exist
$sql = 'INSERT
INTO `user` (`name`, `pw`)
VALUES ("' . $name . '","' . $pw . '");
INTO `user` (`name`, `pw`, `email`)
VALUES ("' . $name . '","' . $pw . '","' . $email . '");
';

$result = mysqli_query($sqllink, $sql);
Expand Down
6 changes: 3 additions & 3 deletions public/api/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

require('./private/illegal_words_list.php');
require "../private/emailcfg.php";
require "./private/emailcfg.php";
require './plugin/Lib_Smtp.php';

/**
Expand Down Expand Up @@ -47,8 +47,8 @@ function send_verification_mail($target, $verify_code)
try {
$mail = new Lib_Smtp();

$mail->setServer(HOST, USER, PASS, PORT, true);
$mail->setFrom(MAIL);
$mail->setServer(EMAIL_HOST, EMAIL_USER, EMAIL_PASS, EMAIL_PORT, true);
$mail->setFrom(EMAIL_MAIL);
$mail->setReceiver($target);
$mail->addAttachment("");
$mail->setMail(
Expand Down
16 changes: 16 additions & 0 deletions src/components/MapView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2040,6 +2040,22 @@
<input style="width: -webkit-fill-available;" type="text" placeholder={$t('map.modals.register.verification_code')} bind:value={verification_code} />
<button
on:click={() => {
axios
.post('./mail.php', {
email,
})
.then(res => {
switch (res.data.res) {
case 'ok':
break;
case 'fail':
break;
default:
console.log(res)
break;
}
});

countdown_for_verification_code = 60;
const countdown_verification_timer = setInterval(() => {
countdown_for_verification_code--;
Expand Down

0 comments on commit afe6ed4

Please sign in to comment.