Inheritance: extends Core\Model
Exemple #1
0
 /**
  *	Invite list 
  *	2015.11.11 start
  */
 public function Invite()
 {
     global $user;
     $inviteList = Invite::GetInvitesByUid($user->id, 0);
     include Template::load("panel/invite");
     //throw new Error("This page is not available", 404);
 }
Exemple #2
0
 /**
  *    Invite list
  *    2015.11.11 start
  */
 public function invite()
 {
     $data['user'] = User::getUserByUserId(User::getCurrent()->uid);
     $data['inviteList'] = Invite::getInvitesByUid($data['user']->uid, "0");
     Template::setContext($data);
     Template::setView("panel/invite");
 }
Exemple #3
0
 /**
  * 生成邀请码,必要权限检查
  *
  * @JSON
  * @Authorization
  */
 public function create()
 {
     $user = User::getUserByUserId(User::getCurrent()->uid);
     $result = array('error' => 1, 'message' => '创建邀请码失败,您没有再次创建邀请码的次数了。当然,你可以用流量购买次数。(10GB/个)');
     if ($user->invite_num > 0) {
         $invite = InviteModel::addInvite($user->uid, 'A', false);
         $result = array('error' => 0, 'message' => '创建邀请码成功,刷新后可见', 'invite_num' => $user->invite_num - 1, 'invite' => $invite);
         $user->invite_num = $user->invite_num - 1;
         $user->save();
     }
     return $result;
 }
Exemple #4
0
 public function userAddInvite()
 {
     global $user;
     $result = array('error' => 1, 'message' => '添加邀请码失败');
     if (!$user) {
         $result = array('error' => 1, 'message' => '没有权限');
     }
     if ($user->getFlow() > 10) {
         $invite = InviteModel::addInvite($user->uid);
         if ($invite != null) {
             $result = array('error' => 0, 'message' => '添加成功,邀请码为:' . $invite . " ,您可以稍后在列表内查看到您新增的邀请码");
         }
     } else {
         $result = array('error' => 1, 'message' => '您的流量不足');
     }
     echo json_encode($result);
     exit;
 }
 public function index()
 {
     $inviteList = \Model\Invite::GetInvitesByUid(-1);
     include Template::load('/home/invite');
 }
Exemple #6
0
 public static function addInvite($uid, $plan = 'A')
 {
     $iv = $uid . substr(hash("sha256", $uid . Util::GetRandomChar(10)), 0, 26);
     $invite = new Invite();
     $invite->uid = $uid;
     $invite->dateLine = time();
     $invite->expiration = 10;
     $invite->inviteIp = Util::GetUserIP();
     $invite->invite = $iv;
     //invite code.
     $invite->reguid = 0;
     $invite->regDateLine = 0;
     $invite->plan = $plan;
     $invite->status = 0;
     $user = User::GetUserByUserId($uid);
     $user->transfer = $user->transfer - Util::GetGB() * 10;
     $user->updateUser();
     return $invite->insertToDB();
 }
Exemple #7
0
 public function addInvite()
 {
     global $user;
     $user = User::GetUserByUserId($user->uid);
     Invite::addInvite($user->uid, 'VIP');
     echo 'add ok';
     exit;
 }
 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) < 8) {
                 $result['message'] = '密码太短,至少8字符';
             } else {
                 if (strlen($userName) < 4) {
                     $result['message'] = '昵称太短,至少2中文字符或6个英文字符';
                 } else {
                     if ($chkEmail = Util::MailFormatCheck($email)) {
                         $result['message'] = $chkEmail;
                     } else {
                         $user = new User();
                         $user->email = $email;
                         $user->nickname = $userName;
                         $user->transfer = Util::GetGB() * TRANSFER;
                         // 流量大小
                         $user->invite = $inviteCode;
                         $user->plan = $invite->plan;
                         //将邀请码的账户类型设定到注册用户上.
                         $user->regDateLine = time();
                         $user->lastConnTime = $user->regDateLine;
                         $user->sspwd = Util::GetRandomPwd();
                         $user->insertToDB();
                         $user->port = $user->uid;
                         $invite->reguid = $user->uid;
                         $invite->regDateLine = $user->regDateLine;
                         $invite->status = 1;
                         //-1过期 0-未使用 1-已用
                         $invite->inviteIp = Util::GetUserIP();
                         $invite->updateInvite();
                         $user->updateUser();
                         $user->savePassword($passwd);
                         if (null != $user->uid && 0 != $user->uid) {
                             $result['error'] = 0;
                             $result['message'] = '注册成功';
                         }
                     }
                 }
             }
         }
     }
     echo json_encode($result);
     exit;
 }
Exemple #9
0
 /**
  * 导出邀请码
  */
 public function export()
 {
     $invites = InviteModel::getInviteArray(0);
     $file_name = '邀请码列表_' . time() . '.csv';
     $data = 'id,邀请码,邀请码等级,创建时间,状态' . "\n";
     foreach ($invites as $invite) {
         $data .= $invite->id . ',' . $invite->invite . ',' . Utils::planAutoShow($invite->plan) . '(' . $invite->plan . '),' . date('Y-m-d H:i:s', $invite->dateLine) . ',' . '可用' . "\n";
     }
     header("Content-type:text/csv;charset=utf-8");
     header("Content-Disposition:attachment;filename=" . $file_name);
     header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
     header('Expires:0');
     header('Pragma:public');
     $data = iconv('utf-8', 'gb2312', $data);
     echo $data;
     exit;
 }
Exemple #10
0
 public static function addInvite($uid, $plan = 'A')
 {
     $iv = $uid . hash("sha256", $uid . Util::GetRandomChar(10));
     $invite = new Invite();
     $invite->uid = $uid;
     $invite->dateLine = time();
     $invite->expiration = 10;
     $invite->inviteIp = Util::GetUserIP();
     $invite->invite = $iv;
     //invite code.
     $invite->reguid = 0;
     $invite->regDateLine = 0;
     $invite->plan = $plan;
     $invite->status = 0;
     $invite->insertToDB();
 }
Exemple #11
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;
 }