mailCheck() public static method

邮件地址检测
public static mailCheck ( $address ) : null | string
$address
return null | string
Beispiel #1
0
 /**
  * @JSON
  */
 public function register()
 {
     $result = array('error' => 1, 'message' => '注册失败');
     $email = strtolower(trim($_POST['r_email']));
     $userName = trim($_POST['r_user_name']);
     $passwd = trim($_POST['r_passwd']);
     $repasswd = trim($_POST['r_passwd2']);
     $inviteCode = trim($_POST['r_invite']);
     $invite = Invite::getInviteByInviteCode($inviteCode);
     //校验 invite 是否可用
     if ($invite->status != 0 || $invite == null || empty($invite)) {
         $result['message'] = '邀请码不可用';
     } else {
         if ($repasswd != $passwd) {
             $result['message'] = '两次密码输入不一致';
         } else {
             if (strlen($passwd) < 6) {
                 $result['message'] = '密码太短,至少8字符';
             } else {
                 if ($chkEmail = Utils::mailCheck($email)) {
                     $result['message'] = $chkEmail;
                 } else {
                     $user = new User();
                     $user->email = $email;
                     if ($userName == null) {
                         $userName = $email;
                     }
                     $userCount = Stats::countUser();
                     $user->nickname = $userName;
                     // LEVEL 从数据库中获取
                     $custom_transfer_level = json_decode(Option::get('custom_transfer_level'), true);
                     // 定义邀请码套餐与流量单位
                     $transferNew = Utils::GB * intval($custom_transfer_level[$invite->plan]);
                     $user->transfer = $transferNew;
                     $user->invite = $inviteCode;
                     $user->plan = $invite->plan;
                     // 将邀请码的账户类型设定到注册用户上.
                     $user->regDateLine = time();
                     $user->lastConnTime = $user->regDateLine;
                     $user->sspwd = Utils::randomChar();
                     $user->payTime = time();
                     // 注册时支付时间
                     $user_test_day = Option::get('user_test_day') ?: 7;
                     $user->expireTime = time() + 3600 * 24 * intval($user_test_day);
                     // 到期时间
                     $mailVerify = Option::get('mail_verify');
                     // 邮件验证是否开启
                     if ($userCount > 0 && $mailVerify) {
                         $user->enable = 0;
                         // 停止账户
                         $code = Utils::randomChar(10);
                         $forgePwdCode['verification'] = $code;
                         $forgePwdCode['time'] = time();
                         $user->forgePwdCode = json_encode($forgePwdCode);
                         $mailer = Mailer::getInstance();
                         $mailer->toQueue(false);
                         $mail = new Mail();
                         $mail->to = $user->email;
                         $mail->subject = '[' . SITE_NAME . '] 新账户注册邮箱校验';
                         $mail->content = Option::get('custom_mail_verification_content');
                         $params = ['code' => $code, 'nickname' => $user->nickname, 'email' => $user->email, 'useTraffic' => Utils::flowAutoShow($user->flow_up + $user->flow_down), 'transfer' => Utils::flowAutoShow($user->transfer), 'expireTime' => date('Y-m-d H:i:s', $user->expireTime), 'REGISTER_URL' => base64_encode($user->email . "\t" . $forgePwdCode['verification'] . "\t" . $forgePwdCode['time'])];
                         $mail->content = Utils::placeholderReplace($mail->content, $params);
                         $mailer->send($mail);
                     } else {
                         $user->enable = 1;
                         // 第一个账户,默认设定为启用
                         $user->forgePwdCode = null;
                     }
                     $user->port = Utils::getNewPort();
                     // 端口号
                     $user->setPassword($passwd);
                     $user->save();
                     $invite->reguid = $user->uid;
                     $invite->regDateLine = $user->regDateLine;
                     $invite->status = 1;
                     // -1过期 0-未使用 1-已用
                     $invite->inviteIp = Utils::getUserIP();
                     $invite->save();
                     if (null != $user->uid && 0 != $user->uid) {
                         $result['error'] = 0;
                         $result['message'] = '注册成功';
                     }
                     if ($mailVerify) {
                         $result['message'] .= ',您需要验证邮箱后才能使用本站功能。';
                     }
                     Logger::getInstance()->info('user [' . $user->email . '] register success');
                 }
             }
         }
     }
     return $result;
 }