171 lines
6.6 KiB
PHP
171 lines
6.6 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
require_once APPPATH . 'controllers/pingan/BaseController.php';
|
|
|
|
/**
|
|
* Notes:登录操作
|
|
* Created on: 2022/8/29 17:15
|
|
* Created by: dengbw
|
|
*/
|
|
class Login extends BaseController
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('agent/pingan/Pingan_users_model', 'mdSysAdmin');
|
|
$this->load->model('agent/pingan/Pingan_sys_role_model', 'mdSysRole');
|
|
$this->load->model('agent/pingan/Pingan_sys_menu_model', 'mdSysMenu');
|
|
$this->load->model('agent/pingan/Pingan_sys_login_record_model', 'mdSysLoginRecord');
|
|
}
|
|
|
|
/**
|
|
* Notes:用户登录
|
|
* Created on: 2022/9/8 14:49
|
|
* Created by: dengbw
|
|
*/
|
|
public function index_post()
|
|
{
|
|
$mobile = $this->input_param('phone');
|
|
$code = $this->input_param('code');
|
|
if (!$mobile) {
|
|
$this->return_json('请输入手机号');
|
|
}
|
|
if (!$code) {
|
|
$this->return_json('请输入验证码');
|
|
}
|
|
$redis = &load_cache('redis');
|
|
$chackKey = $this->getCodeCacheKey(self::CODE_LOGIN, $mobile);
|
|
$cache_code = $redis->get($chackKey);
|
|
if (!$cache_code) {
|
|
$this->return_json('验证码已过期');
|
|
}
|
|
if ($cache_code != $code) {
|
|
$this->return_json('验证码错误');
|
|
}
|
|
$re = $this->mdSysAdmin->get(['mobile' => $mobile, 'status > 0' => null]);
|
|
if (!$re) {
|
|
$this->return_json('账号不存在');
|
|
}
|
|
if (!$re['status']) {
|
|
$this->return_json('该账号已禁用');
|
|
}
|
|
$user = [
|
|
'userId' => $re['id'], 'username' => $re['username'],
|
|
'avatar' => self::DEFAULT_AVATAR, 'phone' => $re['mobile'],
|
|
'enabled' => true, 'accountNonLocked' => true,
|
|
'credentialsNonExpired' => true, 'accountNonExpired' => true
|
|
];
|
|
$roles = $authorities = [];
|
|
if ($re['roleId']) {
|
|
$re_ro = $this->mdSysRole->get(['roleId' => $re['roleId'], 'status' => 0]);
|
|
if ($re_ro) {
|
|
$re_ro['userId'] = $re['userId'];
|
|
$roles[] = $re_ro;
|
|
if ($re_ro['menuIds']) {
|
|
$authorities = $this->mdSysMenu->select(["menuId in({$re_ro['menuIds']})" => null, 'status' => 0]
|
|
, 'sortNumber asc,menuId desc');
|
|
foreach ($authorities as $k => $v) {
|
|
$authorities[$k]['menuId'] = intval($v['menuId']);
|
|
$authorities[$k]['parentId'] = intval($v['parentId']);
|
|
$authorities[$k]['menuType'] = intval($v['menuType']);
|
|
$authorities[$k]['openType'] = intval($v['openType']);
|
|
$authorities[$k]['sortNumber'] = intval($v['sortNumber']);
|
|
$authorities[$k]['hide'] = intval($v['hide']);
|
|
$authorities[$k]['meta'] = json_decode($v['meta'], true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$user['roles'] = $roles;
|
|
$user['authorities'] = $authorities;
|
|
$data['access_token'] = Authorization::generateToken($re['id'], 'jwt_key_pingan');
|
|
$data['user'] = $user;
|
|
$this->load->library('api/record');
|
|
$this->record->loginRecordPinAn(['userId' => $re['id'], 'username' => $re['username'], 'nickname' => $re['nickname'] ?: '', 'mobile' => $re['mobile']]);
|
|
$redis->delete($chackKey);
|
|
$this->return_response($data, '登录成功');
|
|
}
|
|
|
|
public function code_get()
|
|
{
|
|
$phone = $this->input_param('phone');
|
|
$type = $this->input_param('type');//验证码类型
|
|
if (!$phone) {
|
|
$this->return_json('请输入绑定手机号');
|
|
}
|
|
$cacheKey = '';
|
|
switch ($type) {
|
|
case self::CODE_LOGIN:
|
|
$re = $this->mdSysAdmin->get(["mobile" => $phone, 'status > 0' => null]);
|
|
if (!$re) {
|
|
$this->return_json('绑定手机号不存在');
|
|
}
|
|
if (!$re['status']) {
|
|
$this->return_json('该账号已禁用');
|
|
}
|
|
$cacheKey = $this->getCodeCacheKey(self::CODE_LOGIN, $phone);
|
|
break;
|
|
case self::CODE_REGISTER:
|
|
$re = $this->mdSysAdmin->get(["mobile" => $phone, 'status > 0' => null]);
|
|
if ($re) {
|
|
$this->return_json('手机号已绑定');
|
|
}
|
|
$cacheKey = $this->getCodeCacheKey(self::CODE_REGISTER, $phone);
|
|
break;
|
|
default:
|
|
$this->return_json('验证码类型错误');
|
|
}
|
|
$redis = &load_cache('redis');
|
|
$code = $redis->get($cacheKey);
|
|
if (!$code) {
|
|
$code = rand(100000, 999999);
|
|
$content = "【" . HDY_SMS_SIGN . "】" . "您的验证码为:{$code},请勿泄露于他人!";
|
|
b2m_send_sms($phone, $content);
|
|
$redis->save($cacheKey, $code, 5 * 60);
|
|
}
|
|
$this->return_response('短信验证码发送成功, 请注意查收!');
|
|
}
|
|
|
|
/**
|
|
* Notes:忘记密码
|
|
* Created on: 2022/10/13 15:34
|
|
* Created by: dengbw
|
|
*/
|
|
// public function forget_post()
|
|
// {
|
|
// $phone = $this->input_param('phone');
|
|
// $password = $this->input_param('password');
|
|
// $password2 = $this->input_param('password2');
|
|
// $code = $this->input_param('code');
|
|
// if (!$phone) {
|
|
// $this->return_json('请输入绑定手机号');
|
|
// }
|
|
// if (!$password) {
|
|
// $this->return_json('请输入新的登录密码');
|
|
// }
|
|
// if (!$password2) {
|
|
// $this->return_json('请再次输入登录密码');
|
|
// }
|
|
// if (mb_strlen($password) < 4) {
|
|
// $this->return_json('请输入至少4个字符的新密码');
|
|
// }
|
|
// if ($password != $password2) {
|
|
// $this->return_json('两次输入密码不一致');
|
|
// }
|
|
// if (!$code) {
|
|
// $this->return_json('请输入验证码');
|
|
// }
|
|
// $redis = &load_cache('redis');
|
|
// if (!$redis->get($phone)) {
|
|
// $this->return_json('验证码已过期');
|
|
// }
|
|
// if ($redis->get($phone) != $code) {
|
|
// $this->return_json('验证码错误');
|
|
// }
|
|
// $upDate['password'] = password_hash($password, PASSWORD_BCRYPT);
|
|
// $this->mdSysAdmin->update($upDate, ['phone' => $phone, 'status' => 0]);
|
|
// $redis->delete($phone);//删除验证码
|
|
// $this->return_response([], '密码修改成功');
|
|
// }
|
|
} |