实例介绍
【实例简介】
【实例截图】
【实例截图】
【核心代码】
<?php
namespace Index\Controller;
use Think\Controller;
class IndexController extends CommonController {
//Page
public function index(){
$this->_display("首页","index");
}
public function login(){
//检测是否允许登录
$system = M("SystemOptions");
$system = $system->where("name='site_login'")->find();
if($system['value']!="Y"){
$this->assign("_title","关闭登录");
$this->assign("_closeTitle","Loofir工作室暂时无法登录");
$this->assign("_closeBody","十分抱歉的通知您,Loofir工作室官方网站(以下简称本站)暂时无法进行登录!<br />
原因如下:<font color='red'>{$system['value']}</font><br />
我们再次为本次站点关闭登录系统为您带来的不便致歉,希望您能理解和包涵,感谢您对Loofir工作室的支持与厚爱!<br />");
$this->siteaccelerate();
$this->display("Common:close");
exit();
}
$this->_display("登录","login");
}
public function loofirpassport(){
//检测是否允许注册
$system = M("SystemOptions");
$system = $system->where("name='site_register'")->find();
if($system['value']!="Y"){
$this->assign("_title","关闭注册");
$this->assign("_closeTitle","Loofir工作室暂时无法注册");
$this->assign("_closeBody","十分抱歉的通知您,Loofir工作室官方网站(以下简称本站)暂时无法进行注册!<br />
原因如下:<font color='red'>{$system['value']}</font><br />
我们再次为本次站点关闭注册系统为您带来的不便致歉,希望您能理解和包涵,感谢您对Loofir工作室的支持与厚爱!<br />");
$this->siteaccelerate();
$this->display("Common:close");
exit();
}
$this->_display("Loofir账号通注册",null);
}
public function accountverifyemail(){
//检测是否允许验证邮箱
$system = M("SystemOptions");
$system = $system->where("name='site_register'")->find();
if($system['value']!="Y"){
$this->assign("_title","关闭验证");
$this->assign("_closeTitle","Loofir工作室暂时无法验证邮箱");
$this->assign("_closeBody","十分抱歉的通知您,Loofir工作室官方网站(以下简称本站)暂时无法进行邮箱验证!<br />
原因如下:<font color='red'>{$system['value']}</font><br />
我们再次为本次站点关闭邮箱验证系统为您带来的不便致歉,希望您能理解和包涵,感谢您对Loofir工作室的支持与厚爱!<br />");
$this->siteaccelerate();
$this->display("Common:close");
exit();
}
$user = M("UserAccount");
$user = $user->where("uid={$_COOKIE['uid']}")->find();
$this->assign("email",$user['email']);
$this->_display("邮箱验证",null);
}
//Action
public function login_verify(){
if(!IS_POST){
$this->siteaccelerate();
$this->error("非法访问!",U("Index/Index/index"));
}
$username = $_POST['username'];
$password = md5($_POST['password']);
$user = M("UserAccount");
$user = $user->where("username='{$username}'")->find();
//用户是否存在
if(empty($user)){
echo "EU"; //emptyUser
exit();
}
//是否禁止登陆
if($user['value']!="Y"){
cookie("uid",$user['uid']);
cookie("username",$user['username']);
$userDisable = M("UserDisable");
$userDisable = $userDisable->where("uid={$user['uid']}")->find();
if(empty($userDisable)){
echo "UE";
exit();
}else if($userDisable['type']=='email'){
echo "VE";
exit();
}else{
echo "UE";
exit();
}
}
if($username==$user['username']&&$password==$user['password']){
//登录
$login = M("UserLoginRecord");
date_default_timezone_set("PRC");
$last_login = $login->where("uid={$user['uid']}")->find();
$last_login = $last_login['last_login'];
if($last_login!=date("Y-m-d")){
$login->last_login = date("Y-m-d");
$login->where("uid={$user['uid']}")->save();
$exp = M("UserExp");
$exps = $exp->where("uid={$user['uid']}")->find();
$exps = $exps['exp'];
$exp->exp = $exps 2;
$exp->where("uid={$user['uid']}")->save();
}
cookie('uid',$user['uid']);
cookie('username',$user['username']);
cookie('shell',md5($user['uid'].$user['username'].$user['password']."loofirstudio"));
echo "SL"; //successLogin
exit();
}else{
echo "EI"; //errorInfo
exit();
}
}
public function logout(){
cookie("uid",null);
cookie("username",null);
cookie("shell",null);
$this->siteaccelerate();
$this->success("成功退出登录!");
}
public function regsiter_verifyinfo(){
if(!IS_POST){
$this->siteaccelerate();
$this->error("非法访问!",U("Index/Index/index"));
}
//判断验证码是否正确
$verify = new \Think\Verify();
$verify = $verify->check($_POST['verify']);
if(!$verify){
//不正确
echo "VE"; //verifyError
exit();
}else{
//初始化信息
$username = $_POST['username'];
$password = $_POST['password'];
$repassword = $_POST['repassword'];
$email = $_POST['email'];
//判断用户名格式是否正确
$pattern = "/^[a-zA-Z][a-zA-Z0-9_]{5,15}$/"; //字母开头,允许6-16字节,允许字母数字下划线
$verify = preg_match($pattern,$username);
if(!$verify){
echo "UFE"; //usernameFormateError
exit();
}
//判断密码格式是否正确
$pattern = "/^\w $/";
$verify = preg_match($pattern,$password);
if(!$verify){
echo "PFE"; //passwordFormateError
exit();
}
//判断两次密码是否一致
if($password!=$repassword){
echo "PNS"; //passwordNotSame
exit();
}
//判断邮箱是否正确
$pattern = "/\w ([- .]\w )*@\w ([-.]\w )*\.\w ([-.]\w )*/";
$verify = preg_match($pattern,$email);
if(!$verify){
echo "EFE"; //emailFormateError
exit();
}
//进行注册
$user = M("UserAccount");
//判断重复
$v_user = $user->where("username='{$username}'")->find();
if(!empty($v_user)){
echo "UNU"; //usernameNotUnique
exit();
}
//验证邮箱重复
$v_email = $user->where("email='{$email}'")->find();
if(!empty($v_email)){
echo "SEE"; //theSameEmailExist
exit();
}
$user->username = $username;
$user->password = md5($password);
$user->email = $email;
$user->value = "Y";
$user = $user->add();
if(!$user){
echo "UKE"; //unKnowError
exit();
}
//设置基础权限
$jurisdiction = M("UserJurisdiction");
$jurisdiction->uid = $user;
$jurisdiction->u_value = 1;
$jurisdiction->a_value = 0;
$jurisdiction->add();
//初始化账户
$exp = M("UserExp");
$exp->uid = $user;
$exp->exp = 2;
$exp->add();
$login = M("UserLoginRecord");
$login->uid = $user;
$login->last_login = "0000-00-00";
$login->add();
//设置邮箱,关闭
/* $disable = M("UserDisable");
$disable->uid = $user;
$disable->type = "email";
$disable->value = $email;
$disable->add();
cookie("uid",$user);
cookie("username",$username); */
echo "S"; //success
}
}
public function send_verify_email(){
if(!IS_POST){
$this->siteaccelerate();
$this->error("非法访问!",U("Index/Index/index"));
}
//判断邮箱是否正确
$pattern = "/\w ([- .]\w )*@\w ([-.]\w )*\.\w ([-.]\w )*/";
$verify = preg_match($pattern,$_POST['email']);
if(!$verify){
echo "EFE"; //emailFormateError
exit();
}
//验证邮箱重复
$user = M("UserAccount");
$v_email = $user->where("username!='{$_POST['username']}' AND email='{$_POST['email']}'")->find();
if(!empty($v_email)){
echo "SEE"; //theSameEmailExist
exit();
}
session("sve",rand(100000,999999));
vendor("PHPMailer.PHPMailerAutoload");
vendor("PHPMailer.class#phpmailer");
$mail = new \PHPMailer();
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.ym.163.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'service@loofir.tk'; // SMTP username
$mail->Password = '19990521'; // SMTP password
$mail->Port = 25;
$mail->CharSet = "UTF-8";
$mail->From = 'service@loofir.tk';
$mail->FromName = 'Loofir服务中心';
$mail->addAddress("{$_POST['email']}", "{$_POST['username']}");
$mail->isHTML(true);
$mail->Subject = 'Loofir账号邮箱验证';
$mail->Body = "<table cellpadding='0' cellspacing='0' style='text-align:left;border:1px solid #50a5e6;color:#fff;font-size:18px;' width='740'><tbody><tr height='39' style='background-color:#50a5e6;'><td style='padding-left:15px;font-family:".'微软雅黑'.",".'黑体'.",arial;'>Loofir工作室</td></tr></tbody></table>
<table cellpadding='0' cellspacing='0' style='text-align:left;border:1px solid #f0f0f0;border-top:none;color:#585858;background-color:#fafafa;font-size:14px;' width='740'>
<tbody>
<tr height='25'><td></td></tr>
<tr height='40'><td style='padding-left:25px;padding-right:25px;font-size:18px;font-family:".'微软雅黑'.",".'黑体'.",arial;'>您好,{$_POST['username']}:</td><iframe id='tmp_downloadhelper_iframe' style='display: none;'></iframe></tr>
<tr height='15'><td></td></tr>
<tr height='30'><td style='padding-left:55px;padding-right:55px;font-family:".'微软雅黑'.",".'黑体'.",arial;font-size:14px;'>感谢您使用Loofir服务。</td></tr>
<tr height='30'><td style='padding-left:55px;padding-right:55px;font-family:".'微软雅黑'.",".'黑体'.",arial;font-size:14px;'>请输入以下庐码进行邮箱验证,以便开始使用您的Loofir账号:</td></tr>
<tr height='60'><td style='padding-left:55px;padding-right:55px;font-family:".'微软雅黑'.",".'黑体'.",arial;font-size:14px;'><a style='color: rgb(255,255,255);text-decoration: none;display: block;min-height: 39px;width: 158px;line-height: 39px;background-color:rgb(80,165,230);font-size:20px;text-align:center;'>{$_SESSION['sve']}</a></td></tr>
<tr height='10'><td></td></tr>
<tr height='20'><td style='padding-left:55px;padding-right:55px;font-family:".'微软雅黑'.",".'黑体'.",arial;font-size:12px;'>如果您并未申请Loofir账号,可能是其他用户误输入了您的邮箱地址。请忽略此邮件,或与我们联系。</td></tr>
<tr height='20'><td style='padding-left:55px;padding-right:55px;font-family:".'微软雅黑'.",".'黑体'.",arial;font-size:12px;'>请认准发件者邮箱,Loofir服务中心邮箱:service@loofir.tk。</td></tr>
<tr height='20'><td></td></tr>
</tbody>
<table cellpadding='0' cellspacing='0' style='text-align:left;border:1px solid #f0f0f0;border-top:none;color:#585858;background-color:#fafafa;font-size:14px;' width='740'>
<table cellpadding='0' cellspacing='0' style='color:#969696;font-size:12px;vertical-align:middle;text-align:center;' width='740'><tbody>
<tr height='5'><td></td></tr>
<tr height='20'><td width='680' style='text-align:left;font-family:".'微软雅黑'.",".'黑体'.",arial;'> 2015 <span>©</span><a href='http://loofir.tk/' target='_blank' style='text-decoration:none;color:#969696;padding-left:5px;' title='Loofir工作室'>Loofir工作室</a></td></tr>
<tr height='20'><td style='text-align:left;font-family:".'微软雅黑'.",".'黑体'.",arial;' colspan='2'>客户支持: jokin@loofir.tk</td></tr>
<tr height='45'><td></td></tr>
</tbody></table>";
$mail->AltBody = '[Loofir服务中心]您的验证码为:';
if(!$mail->send()){
echo "Error";
}else{
echo "Success";
}
}
public function verify_loonumber(){
if(!IS_POST){
$this->siteaccelerate();
$this->error("非法访问!",U("Index/Index/index"));
}
$sve = $_SESSION['sve'];
if($_POST['verify']==$sve){
//开通账户
$user = M("UserAccount");
$user->email = $_POST['email'];
$user->value = "Y";
$user->where("username='{$_POST['username']}'")->save();
$uInfo = $user->where("username='{$_POST['username']}'")->find();
cookie('uid',$uInfo['uid']);
cookie('username',$uInfo['username']);
cookie('shell',md5($uInfo['uid'].$uInfo['username'].$uInfo['password']."loofirstudio"));
//-
$disable = M("UserDisable");
//查询禁用记录
$v_disable = $disable->where("uid={$uInfo['uid']}")->find();
if(empty($v_disable)){
echo "AR";
exit();
}
//删除禁用记录
$disable->where("uid={$uInfo['uid']}")->delete();
echo "Success";
exit();
}else{
echo "Error";
exit();
}
}
//Function
protected function _display($title,$nav){
$this->assign("_nav",$nav);
$this->assign("_title",$title);
$this->siteaccelerate();
$this->display();
}
}
?>
好例子网口号:伸出你的我的手 — 分享!
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


支持(0) 盖楼(回复)