/** * 用户报名参加团购 * * 用户可以参加本次团购的条件: * 1.本次团购还没有满员 * 2.一小时二十五分钟内,用户在本次团购中没有未完成的交易 * * regiment_user_relation表中的is_over:0代表着还没有完成,1代表着已经完成交易了 * 如果用户没有登录便参加团购,会生成一个hash存在cookie里,名字为regiment_100,其中100是相应团购的id * 并将此hash保存在regiment_user_relation表的hash字段里。在用户付账需要登录的时候应该查询这个hash并更新相应的user_id * * @static */ public static function join($id, $user_id = null) { $id = intval($id); $now = time(); $regiment = self::getRegimentById($id); $time_limit = self::time_limit(); if ($regiment === false || 0 != $regiment['store_nums'] && $regiment['user_num'] >= $regiment['store_nums'] || strtotime($regiment['end_time']) < $now || strtotime($regiment['start_time']) > $now) { return array('flag' => 'msg', 'data' => '本次团购已过期或者人满'); } $tb = new IModel("regiment_user_relation"); $data = array('user_id' => "", 'hash' => "", 'regiment_id' => $id, 'join_time' => date("Y-m-d H:i:s", $now), 'is_over' => 0); if ($user_id !== null) { $user_id = intval($user_id); $re = $tb->query("regiment_id={$id} AND user_id={$user_id} AND is_over=0"); $data['user_id'] = $user_id; } else { $hash = ICookie::get("regiment_{$id}"); if ($hash === null) { $hash = IHash::md5(serialize($_SERVER) . microtime(1)); ICookie::set("regiment_{$id}", $hash, $time = $time_limit * 60); } $re = $tb->query("regiment_id={$id} AND hash='{$hash}' AND is_over=0"); $data['hash'] = $hash; } if ($re) { $re = end($re); } if (count($re) == 0 || strtotime($re['join_time']) < $now - $time_limit * 60) { $tb->setData($data); //$relation_id是关系表的主键 if ($re) { $tb->update("id={$re['id']}"); $relation_id = $re['id']; } else { $relation_id = $tb->add(); } return array('flag' => true, 'data' => '参与成功', 'relation_id' => $relation_id); } else { return array('flag' => false, 'data' => '本次团购您存在未完成交易'); } }
/** * @brief 邮箱找回密码进行 */ function find_password_email() { $username = IReq::get('username'); if ($username === null || !Util::is_username($username)) { IError::show(403, "请输入正确的用户名"); } $email = IReq::get("email"); if ($email === null || !IValidate::email($email)) { IError::show(403, "请输入正确的邮箱地址"); } $tb_user = new IModel("user"); $username = IFilter::act($username); $email = IFilter::act($email); $user = $tb_user->getObj(" username='******' AND email='{$email}' "); if (!$user) { IError::show(403, "对不起,用户不存在"); } $hash = IHash::md5(microtime(true) . mt_rand()); //重新找回密码的数据 $tb_find_password = new IModel("find_password"); $tb_find_password->setData(array('hash' => $hash, 'user_id' => $user['id'], 'addtime' => time())); if ($tb_find_password->query("`hash` = '{$hash}'") || $tb_find_password->add()) { $url = IUrl::getHost() . IUrl::creatUrl("/simple/restore_password/hash/{$hash}"); $content = mailTemplate::findPassword(array("{url}" => $url)); $smtp = new SendMail(); $result = $smtp->send($user['email'], "您的密码找回", $content); if ($result === false) { IError::show(403, "发信失败,请重试!或者联系管理员查看邮件服务是否开启"); } } else { IError::show(403, "生成HASH重复,请重试"); } $message = "恭喜您,密码重置邮件已经发送!请到您的邮箱中去激活"; $this->redirect("/site/success/message/" . urlencode($message)); }
function do_find_password() { $username = IReq::get('username'); if ($username === null || !Util::is_username($username)) { die("请输入正确的用户名"); } $useremail = IReq::get("useremail"); if ($useremail === null || !IValidate::email($useremail)) { die("请输入正确的邮箱地址"); } $captcha = IReq::get("captcha"); if ($captcha != ISafe::get('Captcha')) { die('验证码输入不正确'); } $tb_user = new IModel("user"); $username = IFilter::act($username); $useremail = IFilter::act($useremail); $user = $tb_user->query("username='******' AND email='{$useremail}'"); if (!$user) { die("没有这个用户"); } $user = end($user); $hash = IHash::md5(microtime(true) . mt_rand()); $tb_find_password = new IModel("find_password"); //重新生成 $tb_find_password->setData(array('hash' => $hash, 'user_id' => $user['id'], 'addtime' => time())); $sendMail = true; if ($tb_find_password->query("`hash` = '{$hash}'") || $tb_find_password->add()) { $smtp = new SendMail(); $url = IUrl::creatUrl("/simple/restore_password/hash/{$hash}"); $url = IUrl::getHost() . $url; $content = "请你点击下面这个链接修改密码:<a href='{$url}'>{$url}</a>。<br />如果不能点击,请您把它复制到地址栏中打开。<br />本链接在3天后将自动失效。"; $re = $smtp->send($user['email'], "您的密码找回", $content); if ($re === false) { die("发信失败"); } die("success"); } die("找回密码失败"); }