Рамзесс
Создатель
- Регистрация
- 13 Июл 2014
- Сообщения
- 11
- Реакции
- 1
- Автор темы
- #1
При авторизации на сайте логином пользователя user. Может ли кто подсказать как сделать авторизацию по email
PHP:
<?php
session_start();
if(!empty($_GET["action"]))
$post=$_GET;
else
$post=$_POST;
if(!empty($post["action"])&&$post["action"]=="submit")
{
if(strtolower($_SESSION["auth"])!=strtolower($post["randcode"]))
{
header("Location: login.php?erry=-3");//ÑéÖ¤Âë´íÎó
exit();
}
include_once("includes/global.php");
include_once("includes/smarty_config.php");
include_once("config/reg_config.php");
$config = array_merge($config,$reg_config);
if($config['openbbs']==2)
{ //ucenter1.5 login
$sql="select userid,user,password,email from ".ALLUSER." a where user='$post[user]'";
$db->query($sql);
$re=$db->fetchRow();//bbÓû§ÊÇ·ñ´æÔÚ
if(!empty($re['password']))
{
if(substr($re['password'],0,4)=='lock')
msg('login.php?erry=-4');//֮ǰʹÓÃÁËÕÒ»ØÃÜÂ빦ÄÜ£¬ÕË»§±»Ëø¶¨
if($re['password']!=md5($post['password']))
msg('login.php?erry=-2');//ÃÜÂë´íÎó
}
include_once('uc_client/client.php');
list($uid, $username, $password, $email) = uc_user_login($post['user'], $post['password']);//ucÊÇ·ñ´æÔÚ
if($uid>0||$re["userid"])
{ //Èç¹ûuc»òÕßBBÖ®ÖÐÓÐÒ»¸öÕË»§ÊÇÕýÈ·µÄÖ´ÐÐÈçϲÙ×÷
if($uid<=0&&$re["userid"]>0)//UC²»´æÔڣ£´æÔÚ
{
$uid = uc_user_register($re['user'], $post['password'], $re['email']);
if($re['pid'])
login($re['pid'],$re['user'],$re['userid']);//×ÓÕ˺ŵǼ
else
login($re['userid'],$re['user']);//Ö÷Õ˺ŵǼ
}
elseif($uid>0&&$re["userid"]<=0)//UC´æÔÚBB²»´æÔÚ
{
$dbc=new dba($config['dbhost'],$config['dbuser'],$config['dbpass'],$config['dbname']);
$ip=getip();
$dbc->query("insert into ".ALLUSER." (user,email,password,ip) values
('$post[user]','$email','".md5($post['password'])."','$ip')");
$re['userid']=$dbc->lastid();
$re['user']=$_POST['user'];
if(empty($config['user_reg']))
$user_reg=1;
elseif($config['user_reg']==3)
$user_reg=1;
else
$user_reg=$config['user_reg'];
$sql="INSERT INTO ".USER."
(userid,regtime,template,country,ifpay) VALUES
('$re[userid]','".date("Y-m-d H:i:s")."','".$config['default_user_tem']."','$country','$user_reg')";
$db->query($sql);
login($re['userid'],$re['user']);//ÍøÕ¾µÇ¼
}
else
{
if($re['pid'])
login($re['pid'],$re['user'],$re['userid']);//×ÓÕ˺ŵǼ
else
login($re['userid'],$re['user']);//Ö÷Õ˺ŵǼ
}
echo uc_user_synlogin($uid);//£Õ£Ãͬ²½µÇ¼
$forward = $post['forward']?$post['forward']:$config["weburl"]."/main.php";
msg($forward);
}
else
{
header("Location: login.php?erry=-1");//Óû§²»´æÔÚ
exit();
}
}
else
{
// no ucenter login
$sql="select * from ".ALLUSER." where user='$post[user]'";
$db->query($sql);
$re=$db->fetchRow();
if($re["userid"])
{
if(substr($re['password'],0,4)=='lock')
msg('login.php?erry=-4');//֮ǰʹÓÃÁËÕÒ»ØÃÜÂ빦ÄÜ£¬ÕË»§±»Ëø¶¨
if($re['password']!=md5($post['password']))
msg('login.php?erry=-2');//ÃÜÂë´íÎó
if($re["password"]==md5($post['password']))
{
if($re['pid'])
login($re['pid'],$re['user'],$re['userid']);//×ÓÕ˺ŵǼ
else
login($re['userid'],$re['user']);
$forward = $post['forward']?$post['forward']:$config["weburl"]."/main.php";
msg($forward);
}
}
else
msg('login.php?erry=-1');//Óû§²»´æÔÚ
}
}
//========================================================
function login($uid,$username,$pid=NULL)
{
global $post,$config;
$db=new dba($config['dbhost'],$config['dbuser'],$config['dbpass'],$config['dbname']);
$sql="select a.lastLoginTime,b.regtime,b.ifpay from ".ALLUSER." a left join ".USER." b on a.userid=b.userid where a.user='$post[user]'";
$db->query($sql);
$re=$db->fetchRow();
if(is_dir("$config[webroot]/t/"))
{
//=====΢²©°ó¶¨µÇ¼=====
if($re)
{
include_once 't/application/adapter/account/xauthCookie_account.adp.php';
$xwbAccount = new xauthCookie_account();
$xwbAccount->_setLocalToken(null);
$xwbAccount->_setLocalToken( array('uid'=>$uid,'uname'=>$username));
}
//=====================
}
bsetcookie("USERID","$uid\t$username\t$pid",NULL,"/",$config['baseurl']);
setcookie("USER",$username,NULL,"/",$config['baseurl']);
$_SESSION["IFPAY"]=$re['ifpay'];
if(time()-$re["lastLoginTime"]>=3600)
{
include("config/point_config.php");
if($point_config['point']=='1'&&$point_config['every_logo']!='0')
renew_point('',$point_config['every_logo']);
}
if(!empty($re["lastLoginTime"])&&empty($re['regtime']))
{
$sql="update ".USER." set regtime='".date("Y-m-d H:i:s")."' WHERE userid='$uid'";
$db->query($sql);
}
else
{
$sql="update ".ALLUSER." set lastLoginTime='".time()."' WHERE userid='$uid'";
$db->query($sql);
}
}
//==================================================================================
include_once("includes/global.php");
include_once("includes/smarty_config.php");
include_once("config/reg_config.php");
$config = array_merge($config,$reg_config);
if(!empty($_GET["user"])&&!empty($_GET["email"]))
{
$sql="select user,userid from ".ALLUSER." where user='$_GET[user]' and email='$_GET[email]'";
$db->query($sql);
$re=$db->fetchRow();
if(!empty($re['user']))
{
$sql="update ".USER." set ifpay=2 where userid=$re[userid]";
$db->query($sql);
header("Location:login.php?user_name=$re[user]");
exit();
}
}
if($buid&&empty($_GET['style']))
{
header("Location:main.php");
exit();
}
include_once("footer.php");
$tpl -> assign("current","office");
if(!empty($_GET['style']))
$tpl->display("login_box.htm");
else
$tpl->display("login.htm");
?>
HTML:
<{include file="header.htm"}>
<div class="menu_bottom L1">
<div class="headtop_L">
<a href='<{$config.weburl}>/'><{$lang.indexpage}></a> » <{$lang.title}></a>
</div>
<div class="headtop_R"></div>
</div>
<!--主体开始 -->
<div id="mainbody1" class="topm">
<script type=text/javascript>
var nousername='<{$lang.nouname}>';
var nouserpass='<{$lang.noupass}>';
var norandcode='<{$lang.nocode}>';
</script>
<script src="script/login.js" type=text/javascript></script>
<!--主体左侧开始 -->
<div class="title4"><div class="title_left2 L2"><{$lang.ulogo}></div></div>
<div class="content4 overflow">
<form id="login" name="login" action="login.php" method="post">
<table width='25%' border='0' cellspacing='0' cellpadding='0' align="left">
<tr>
<td height="28" colspan="2" align="left" bgcolor="#eeeeee" style=" padding-left:20px;"> <{$lang.iamuser}></td>
</tr>
<{if $smarty.get.user}>
<tr>
<td height="36" align="center"></td>
<td align="left" style="font-size:14px; color:#FF0000; font-weight:bold">
<{$lang.youpass}>
</td>
</tr>
<{/if}>
<tr>
<td height="36" align="right"> </td>
<td align="left">
<span id="tishi" style="font-size:14px; color:#FF0000; font-weight:bold"></span>
<div style="margin-left:3px;"><{$lang.uname}></div>
<input value='<{$smarty.get.user}>' name='user' type='text' id="user" size="25" class="tstyle" maxlength="25" tabindex="1" style="width:200px;"/></br>
<{if $smarty.get.erry=="-1"}>
<font color="red"><{$lang.noname}></font>
<{elseif $smarty.get.erry=="-4"}>
<br /><font color="red"><{$lang.have_restpass}></font>
<{else}>
<{/if}>
</td>
</tr>
<tr>
<td height="37" align="right"> </td>
<td align="left">
<div style="margin-left:3px;"><{$lang.logpass}></div>
<input type='password' name='password' id="password" size="25" maxlength="25" height="20" tabindex="2" class="tstyle" style="width:200px;"/><br />
<{if $smarty.get.erry=="-2"}><font color="red"><{$lang.passerr}></font><{/if}>
</td>
</tr>