1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php namespace Manage\Api;
- use Dever;
- use Dever\Helper\Str;
- use Dever\Helper\Code;
- class Login
- {
- public function act()
- {
- //$this->checkCode();
- $system = Dever::input('system', 'is_string', '系统', 'platform');
- $system = Dever::db('system')->find(array('key' => $system));
- if (!$system) {
- Dever::error('登录失败,当前系统不存在');
- }
- $relation_id = Dever::input('relation_id', 'is_numeric', '关联表', 1);
- $info = Dever::db($system['relation_table'])->find($relation_id);
- if (!$info) {
- Dever::error('登录失败,当前系统设置错误');
- }
- if ($system['id'] == 1 && $relation_id == 1) {
- # 如果是平台,暂时不做分库
- $db = Dever::db($system['relation_user_table']);
- } else {
- # 其他系统做分库
- $db = Dever::db($system['relation_user_table'], '', 'default', array($system['partition'] => $info['id']));
- }
- $where['mobile'] = Dever::input('mobile', Dever::rule('mobile'), '手机号');
- $password = Dever::input('password', 'is_string', '密码');
- $admin = $db->find($where);
- if (!$admin) {
- $total = $db->find(1);
- if (!$total) {
- $insert['name'] = Str::hide($where['mobile']);
- $insert['mobile'] = $where['mobile'];
- $insert['role'] = 1;
- $insert += Dever::load('common')->createPwd($password);
- $id = $db->insert($insert);
- $admin = $db->find($id);
- } else {
- Dever::error('登录失败');
- }
- }
- if (!$admin) {
- Dever::error('登录失败,管理员信息无效');
- }
- if ($admin['status'] == 2) {
- Dever::error('登录失败,管理员已被封禁');
- }
- if (Dever::load('common')->hash($password, $admin['salt']) != $admin['password']) {
- Dever::error('登录失败,账号密码无效');
- }
- return Dever::load('common')->token($admin['id'], $admin['mobile'], $system['id'], $relation_id);
- }
- private function checkCode()
- {
- $code = Dever::input('verificationCode');
- if (!$code) {
- Dever::error('请输入验证码');
- }
- $save = Dever::session('code');
- if ($code != $save) {
- Dever::error('验证码错误');
- }
- }
- public function code()
- {
- echo Dever::session('code', Code::create(), 3600);die;
- }
- public function out()
- {
- return 'ok';
- }
- public function loadMenu()
- {
- return Dever::load('menu')->init();
- }
- }
|