1、修复bug

2、后台栏目分模型划分
3、前台增加微信开发用户登录功能
This commit is contained in:
2017-08-15 22:09:59 +08:00
parent d6ea6c7e80
commit ded54b79ca
14 changed files with 240 additions and 81 deletions

View File

@@ -79,13 +79,17 @@ class User extends Base{
}
/**
* 用户登录模型
*/
public function login($username = '', $password = '', $type = 1){
* 用户登录模型
* @param string $username [description]
* @param string $password [description]
* @param integer $type 登录类型1为用户名登录2为邮箱登录3为手机登录4为用户ID登录5为微信登录
* @return [type] [description]
*/
public function login($username = '', $password = '', $type = 1) {
$map = array();
if (\think\Validate::is($username,'email')) {
if (\think\Validate::is($username, 'email')) {
$type = 2;
}elseif (preg_match("/^1[34578]{1}\d{9}$/",$username)) {
} elseif (preg_match("/^1[34578]{1}\d{9}$/", $username)) {
$type = 3;
}
switch ($type) {
@@ -102,23 +106,53 @@ class User extends Base{
$map['uid'] = $username;
break;
case 5:
$map['uid'] = $username;
$map['openid'] = $username;
break;
default:
return 0; //参数错误
return 0; //参数错误
}
if (!$username) {
return false;
}
$user = $this->where($map)->find();
if(isset($user['status']) && $user['status']){
/* 验证用户密码 */
if(md5($password.$user['salt']) === $user['password']){
if (isset($user['uid']) && $user['uid'] && $user['status']) {
if ($type == 3) {
//手机验证手机动态密码
if ($password == session('mobile_login_code')) {
$this->autoLogin($user); //更新用户登录信息
return $user['uid'];
}else{
return -5;
}
} elseif ($type == 5) {
$this->autoLogin($user); //更新用户登录信息
return $user['uid']; //登录成功返回用户ID
return $user['uid'];
} else {
return -2; //密码错误
/* 验证用户密码 */
if (md5($password . $user['salt']) === $user['password']) {
$this->autoLogin($user); //更新用户登录信息
return $user['uid']; //登录成功返回用户ID
} else {
return -2; //密码错误
}
}
} else {
return -1; //用户不存在或被禁用
if ($type == 3 && preg_match("/^1[34578]{1}\d{9}$/", $username) && $password == session('mobile_login_code')) {
$data = array(
'username' => $username,
'mobile' => $username,
'salt' => rand_string(6),
'password' => $password,
);
$result = $this->save($data);
if ($result) {
$this->autoLogin($this->data); //更新用户登录信息
}
return $this->data['uid'];
} else {
return -1; //用户不存在或被禁用
}
}
}
@@ -126,16 +160,19 @@ class User extends Base{
* 用户注册
* @param integer $user 用户信息数组
*/
function register($username, $password, $repassword, $email, $isautologin = true){
function register($username, $password, $repassword, $email, $isautologin = true, $other = array()){
$data['username'] = $username;
$data['salt'] = rand_string(6);
$data['password'] = $password;
$data['repassword'] = $repassword;
$data['email'] = $email;
if (!empty($other)) {
$data = array_merge($data, $other);
}
$result = $this->validate(true)->save($data);
if ($result) {
$data['uid'] = $this->data['uid'];
$this->extend()->save($data);
//$this->extend()->save($data);
if ($isautologin) {
$this->autoLogin($this->data);
}