Browse Source

add friends code check

master
filesite 7 months ago
parent
commit
4652803d38
  1. 2
      controller/Controller.php
  2. 34
      plugins/Common.php
  3. 31
      themes/tajian/controller/FrontapiController.php
  4. 2
      themes/tajian/views/site/login.php
  5. 2
      themes/tajian/views/site/register.php

2
controller/Controller.php

@ -172,7 +172,7 @@ Class Controller { @@ -172,7 +172,7 @@ Class Controller {
$logOk = @error_log("{$logTime}\t{$thisUrl}\tERROR: {$error_message}\n", 3, "{$logDir}{$logFilename}");
if (!$logOk) { //try to mkdir
@mkdir($logDir, 0700, true);
@error_log("{$logTime}\t{$thisUrl}\ttERROR: {$error_message} ms\n", 3, "{$logDir}{$logFilename}");
@error_log("{$logTime}\t{$thisUrl}\tERROR: {$error_message}\n", 3, "{$logDir}{$logFilename}");
}
}
}

34
plugins/Common.php

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
<?php
/**
* 常用的公用方法
*/
Class Common {
public static function isCellphoneNumber($number) {
return preg_match("/^1[3456789][0-9]{9}$/", $number);
}
//朋友手机号码的末 6 位
public static function isFriendsCode($number) {
return preg_match("/^[0-9]{6}$/", $number);
}
//用户注册成功后,保存他的手机号码 6 位尾号作为邀请码
protected function saveFriendsCode($cellphone) {
$logTime = date('Y-m-d H:i:s');
$logDir = __DIR__ . '/../runtime/friendscode/';
$logFilename = substr($cellphone, -6) . '.log';
$logOk = @error_log("{$logTime} created\n", 3, "{$logDir}{$logFilename}");
if (!$logOk) { //try to mkdir
@mkdir($logDir, 0700, true);
@error_log("{$logTime} created\n", 3, "{$logDir}{$logFilename}");
}
}
protected function existFriendsCode($code) {
if (self::isFriendsCode($code) == false) {return false;}
$logDir = __DIR__ . '/../runtime/friendscode/';
$logFilename = "{$logDir}{$code}.log";
return file_exists($logFilename);
}
}

31
themes/tajian/controller/FrontapiController.php

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
require_once __DIR__ . '/../../../lib/DirScanner.php';
require_once __DIR__ . '/../../../plugins/Parsedown.php';
require_once __DIR__ . '/../../../plugins/Html.php';
require_once __DIR__ . '/../../../plugins/Common.php';
require_once __DIR__ . '/SiteController.php';
Class FrontApiController extends SiteController {
@ -444,8 +445,34 @@ eof; @@ -444,8 +445,34 @@ eof;
throw new Exception('Oops,操作太快了,请喝杯咖啡休息会吧...');
}
echo "Building...";
exit;
//返回给视图的变量
$code = 1;
$msg = '';
$err = '';
$newUser = array();
//用户提交的数据检查
$postParams = $this->post();
if (!empty($postParams)) {
$friends_code = $this->post('friendscode', '');
$cellphone = $this->post('username', '');
$sms_code = $this->post('smscode', '');
if (empty($friends_code) || empty($cellphone) || empty($sms_code)) {
$err = "请填写注册邀请码、手机号码和短信验证码哦";
}else if (Common::isCellphoneNumber($cellphone) == false) {
$err = "手机号码格式错误,请填写正确的手机号码";
}else if (Common::isFriendsCode($friends_code) == false) {
$err = "邀请码格式错误,请填写邀请你的朋友的手机号码末 6 位,还可以加客服微信索取";
}else if (Common::existFriendsCode($friends_code) == false) {
$err = "邀请码不存在,请填写邀请你的朋友的手机号码末 6 位,或者加客服微信索取";
}
//TODO: 验证短信验证码是否正确
}
return $this->renderJson(compact('code', 'msg', 'err', 'data'));
}
//用户登录

2
themes/tajian/views/site/login.php

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
</div>
<div class="mb-3 twocol">
<label for="text_input_sm" class="form-label">验证码</label>
<input id="text_input_sm" name="friendscode" placeholder="输入收到的短信验证码">
<input id="text_input_sm" name="smscode" placeholder="输入收到的短信验证码">
<button disabled="disabled">发送验证码</button>
</div>
<div class="avform_bt vercenter">

2
themes/tajian/views/site/register.php

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
</div>
<div class="mb-3 twocol">
<label for="text_input_sm" class="form-label">验证码</label>
<input id="text_input_sm" name="friendscode" placeholder="输入收到的短信验证码">
<input id="text_input_sm" name="smscode" placeholder="输入收到的短信验证码">
<button disabled="disabled" type="button">发送验证码</button>
</div>
<div class="avform_bt vercenter">

Loading…
Cancel
Save