Exemplo n.º 1
0
 public static function paymentVoucher($voucherTemplate, $userID = null)
 {
     $model = new Model("voucher");
     do {
         $account = strtoupper(CHash::random(10, 'char'));
         $password = strtoupper(CHash::random(10, 'char'));
         $obj = $model->where("account = '{$account}'")->find();
     } while ($obj);
     $start_time = date('Y-m-d H:i:s');
     $end_time = date('Y-m-d H:i:s', strtotime('+' . $voucherTemplate['valid_days'] . ' days'));
     $model->data(array('account' => $account, 'password' => $password, 'name' => $voucherTemplate['name'], 'value' => $voucherTemplate['value'], 'start_time' => $start_time, 'end_time' => $end_time, 'money' => $voucherTemplate['money'], 'is_send' => 1, 'user_id' => $userID))->insert();
 }
Exemplo n.º 2
0
 public function testClone()
 {
     $filePath0 = CFile::createTemporary();
     $filePath1 = CFile::createTemporary();
     $filePath2 = CFile::createTemporary();
     $filePath3 = CFile::createTemporary();
     CFile::write($filePath0, "The quick");
     CFile::write($filePath1, " brown fox");
     CFile::write($filePath2, " jumps over");
     CFile::write($filePath3, " the lazy dog.");
     $hash0 = new CHash(CHash::SHA256);
     $hash0->computeMoreFromFile($filePath0);
     $hash0->computeMoreFromFile($filePath1);
     $hash0->computeMoreFromFile($filePath2);
     $hash0->computeMoreFromFile($filePath3);
     $hash1 = clone $hash0;
     $hash1->computeMoreFromFile($filePath0);
     $this->assertTrue($hash0->finalize()->equals("ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c"));
     $this->assertTrue($hash1->finalize()->equals("14dc40e99be202c4e59a0c6d1a8854bb50253624080435ed8c65bd6e5e880c95"));
     CFile::delete($filePath0);
     CFile::delete($filePath1);
     CFile::delete($filePath2);
     CFile::delete($filePath3);
 }
Exemplo n.º 3
0
 /**
  * 创建令牌
  * 
  * @access public
  * @param string $key
  * @return mixed
  */
 public function getToken($key = '')
 {
     $key = "tiny_token_" . $key;
     $token = Session::get($key);
     if ($token == null || strlen($token) != 32) {
         $token = CHash::random(32, 'char');
         Session::set($key, $token);
     }
     return $token;
 }
Exemplo n.º 4
0
 public function ad_validator()
 {
     // var_dump(Req::args());exit;
     $type = Req::args('type');
     $is_open = Req::args("is_open");
     if (!$is_open) {
         Req::args("is_open", 0);
     }
     if (!Req::args('id')) {
         $number = CHash::random(32, 'char');
         $number = preg_replace("/(\\w{8})\\w(\\w{4})\\w(\\w{4})\\w(\\w{4})\\w(\\w{8})/i", "\$1-\$2-\$3-\$4-\$5", $number);
         Req::args('number', $number);
     }
     if ($type == 1 || $type == 2 || $type == 4) {
         $path = Req::args('path');
         $url = Req::args('url');
         $title = Req::args('title');
         $content = array();
         if ($type == 2) {
             foreach ($path as $key => $value) {
                 $content[$key] = array('path' => $value, 'url' => $url[$key], 'title' => $title[$key]);
             }
         } else {
             $content[0] = array('path' => $path[0], 'url' => $url[0], 'title' => $title[0]);
             if ($type == 4) {
                 $content[0]['position'] = Req::args("position");
                 $content[0]['is_close'] = Req::args('is_close') ? 1 : 0;
             }
         }
         Req::args('content', serialize($content));
     } elseif ($type == 3) {
         $title = Req::args("font_title");
         $url = Req::args("font_url");
         $color = Req::args("font_color");
         $content = array('title' => $title, 'url' => $url, 'color' => $color);
         Req::args('content', serialize($content));
     } else {
         $content = Req::args("content");
         Req::args('content', Filter::sql($content));
     }
 }
Exemplo n.º 5
0
 /**
  * 绑定用户Action
  */
 public function oauth_bind_act()
 {
     $userinfo = Session::get('oauth_user_info');
     if ($userinfo) {
         $email = Filter::sql(Req::args('email'));
         $passWord = Req::post('password');
         $rePassWord = Req::post('repassword');
         if (!Validator::email($email)) {
             $info = array('field' => 'email', 'msg' => '邮箱不能为空!');
         } elseif (strlen($passWord) < 6) {
             $info = array('field' => 'password', 'msg' => '密码长度必需大于6位!');
         } else {
             $model = $this->model->table("user as us");
             $obj = $model->join("left join customer as cu on us.id = cu.user_id")->fields("us.*,cu.group_id,cu.login_time")->where("us.email='{$email}'")->find();
             if ($obj) {
                 if ($obj['password'] == CHash::md5($passWord, $obj['validcode'])) {
                     $test = $this->model->table('oauth_user')->where("oauth_type='{$userinfo['oauth_type']}' and open_id='{$userinfo['open_id']}'")->data(array('user_id' => $obj['id']))->update();
                     $this->safebox->set('user', $obj, 1800);
                     $this->redirect("/ucenter/index");
                 } else {
                     $info = array('field' => 'password', 'msg' => '密码与用户名是不匹配的,无法绑定!');
                 }
             } else {
                 if ($passWord == $rePassWord) {
                     $model = $this->model->table("user");
                     $validcode = CHash::random(8);
                     $last_id = $model->data(array('email' => $email, 'name' => $userinfo['open_name'], 'password' => CHash::md5($passWord, $validcode), 'validcode' => $validcode))->insert();
                     $time = date('Y-m-d H:i:s');
                     $model->table("customer")->data(array('user_id' => $last_id, 'reg_time' => $time, 'login_time' => $time))->insert();
                     //记录登录信息
                     $obj = $model->table("user as us")->join("left join customer as cu on us.id = cu.user_id")->fields("us.*,cu.group_id,cu.login_time")->where("us.email='{$email}'")->find();
                     $this->safebox->set('user', $obj, 1800);
                     $this->model->table('oauth_user')->where("oauth_type='{$userinfo['oauth_type']}' and open_id='{$userinfo['open_id']}'")->data(array('user_id' => $last_id))->update();
                     $this->redirect("/ucenter/index");
                 } else {
                     $info = array('field' => 'repassword', 'msg' => '两次密码输入不一致!');
                 }
             }
         }
         $this->assign("invalid", $info);
         $this->redirect("/simple/oauth_bind", false, Req::args());
     } else {
         $this->redirect("/index/index");
     }
 }
Exemplo n.º 6
0
 public function customer_password()
 {
     $id = Req::post("id");
     $password = Req::post("password");
     $repassword = Req::post("repassword");
     $info = array('status' => 'fail');
     if ($id && $password && $password == $repassword) {
         $model = new Model("user");
         $validcode = CHash::random(8);
         $flag = $model->where("id={$id}")->data(array('password' => CHash::md5($password, $validcode), 'validcode' => $validcode))->update();
         if ($flag) {
             $info = array('status' => 'success');
         }
     }
     echo JSON::encode($info);
 }
Exemplo n.º 7
0
 public function manager_password()
 {
     $id = Req::post("id");
     $password = Req::post("password");
     $repassword = Req::post("repassword");
     $info = array('status' => 'fail', 'msg' => '密码修改失败');
     if ($id && $password && $password == $repassword) {
         $model = new Model("manager");
         $validcode = CHash::random(8);
         $key = md5($validcode);
         $password = substr($key, 0, 16) . $password . substr($key, 16, 16);
         $password = md5($password);
         $flag = $model->where("id={$id}")->data(array('password' => $password, 'validcode' => $validcode))->update();
         if ($flag) {
             $info = array('status' => 'success');
         }
         $manager = $model->where("id={$id}")->find();
         Log::op($this->manager['id'], '修改管理员密码', '修改管理员【' . $manager['name'] . '】的密码!');
     }
     echo JSON::encode($info);
 }
Exemplo n.º 8
0
 public function password_save()
 {
     if (!Tiny::app()->checkToken()) {
         $this->redirect("password_change");
     }
     $oldpassword = Req::post('oldpassword');
     $password = Req::post('password');
     $repassword = Req::post('repassword');
     $obj = $this->model->table("user")->where("id=" . $this->user['id'])->find();
     if ($password && $password == $repassword) {
         if ($obj['password'] == CHash::md5($oldpassword, $obj['validcode'])) {
             $validcode = CHash::random(8);
             $data = array('password' => CHash::md5($password, $validcode), 'validcode' => $validcode);
             $obj = $this->model->table("user")->where("id=" . $this->user['id'])->data($data)->update();
             $this->redirect("password_change", false, array('msg' => array("success", "密码修改成功!")));
         } else {
             $this->redirect("password_change", false, array('msg' => array("fail", "原密码不正确!")));
         }
     } else {
         $this->redirect("password_change", false, array('msg' => array("fail", "两次密码不一致!")));
     }
 }
Exemplo n.º 9
0
 public function voucher_create()
 {
     $id = Req::args("id");
     $start_time = Req::args("start_time");
     $start_time = $start_time == null ? date("Y-m-d") : $start_time;
     $end_time = Req::args("end_time");
     $end_time = $end_time == null ? date("Y-m-d 23:59:59", strtotime("+30 days")) : date("Y-m-d 23:59:59", strtotime($end_time));
     $model = new Model('voucher_template');
     $voucher_template = $model->where("id = {$id}")->find();
     if ($voucher_template) {
         $voucher_model = new Model('voucher');
         $num = Req::args('num');
         $i = 0;
         while ($i < $num) {
             do {
                 $account = strtoupper(CHash::random(10, 'char'));
                 $password = strtoupper(CHash::random(10, 'char'));
                 $voucher_template['account'] = $account;
                 $voucher_template['password'] = $password;
                 $voucher_template['start_time'] = $start_time;
                 $voucher_template['end_time'] = $end_time;
                 $obj = $voucher_model->where("account = '{$account}'")->find();
             } while ($obj);
             unset($voucher_template['id'], $voucher_template['point']);
             $voucher_model->data($voucher_template)->insert();
             $i++;
         }
     }
     echo JSON::encode(array('status' => 'success', 'msg' => '已成功生成[' . $voucher_template['name'] . ']代金券(' . $num . ')张'));
 }
Exemplo n.º 10
0
test_start('serialize');
test_step(($serialized1 = $chash->serialize()) == '' ? -1 : 0);
test_end('serialized size is ' . strlen($serialized1) . ' bytes');
$chash = new CHash();
test_start('unserialize');
test_step(($count = $chash->unserialize($serialized1)) < 0 ? $count : 0);
test_end('continuum count is ' . $count);
test_start('serialize coherency');
test_step(($serialized2 = $chash->serialize()) == '' ? -1 : 0);
test_step($serialized1 != $serialized2 ? -1 : 0);
test_end('');
test_start('serializeToFile');
@unlink(SERIALIZEPATH);
test_step(($size1 = $chash->serializeToFile(SERIALIZEPATH)) < 0 ? $size1 : 0);
test_end('serialized size is ' . $size1 . ' bytes');
$chash = new CHash();
test_start('unserializeFromFile');
test_step(($count = $chash->unserializeFromFile(SERIALIZEPATH)) < 0 ? $count : 0);
test_end('continuum count is ' . $count);
test_start('file serialize coherency');
test_step(($serialized2 = $chash->serialize()) == '' ? -1 : 0);
test_step($serialized1 != $serialized2 ? -1 : 0);
test_end('');
test_start('lookupList');
$lookups = array();
for ($index = 0; $index < CANDIDATES; $index++) {
    $targets = $chash->lookupList(sprintf('candidate%07d', $index));
    test_step(count($targets) != 1 ? -1 : 0);
    @$lookups[$targets[0]]++;
}
$mean = 0;
Exemplo n.º 11
0
 public function reg_act()
 {
     $email = Filter::sql(Req::post('email'));
     $passWord = Req::post('password');
     $rePassWord = Req::post('repassword');
     $this->safebox = Safebox::getInstance();
     $code = $this->safebox->get($this->captchaKey);
     $verifyCode = Req::args("verifyCode");
     $info = array('field' => 'verifyCode', 'msg' => '验证码错误!');
     if ($verifyCode == $code) {
         if ($passWord == $rePassWord) {
             $model = $this->model->table("user");
             $obj = $model->where("email='{$email}'")->find();
             if ($obj == null) {
                 $validcode = CHash::random(8);
                 $model->data(array('email' => $email, 'name' => $email, 'password' => CHash::md5($passWord, $validcode), 'validcode' => $validcode))->insert();
                 $this->redirect("index");
             } else {
                 $info = array('field' => 'email', 'msg' => '此用户已经被注册!');
             }
         } else {
             $info = array('field' => 'repassword', 'msg' => '两次密码输入不一致!');
         }
     }
     $this->assign("invalid", $info);
     $this->redirect("reg", false, Req::args());
 }