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(); }
/** * 创建令牌 * * @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; }
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)); } }
/** * 绑定用户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"); } }
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); }
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); }
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", "两次密码不一致!"))); } }
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 . ')张')); }
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()); }