Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Admin\Controller;
- class LoginController extends \Think\Controller
- {
- public function index($username = NULL, $password = NULL, $verify = NULL, $ent = NULL)
- {
- if (IS_POST) {
- if (!check_verify($verify)) {
- $this->error('验证码输入错误');
- }
- $admin_login_verify = I('post.moble_verif');
- if(!$admin_login_verify){
- $this->error('请输入手机验证码');
- }
- if ( $admin_login_verify!= session('admin_login_verify')) {
- $this->error('短信验证码错误!');
- }
- $admin = M('Admin')->where(array('username' => trim($username)))->find();
- $ga = new \Common\Ext\GoogleAuthenticator();
- if (!($ga->verifyCode($admin['ga'], I('post.gacode'), 1))) {
- $this->error('谷歌验证失败');
- }
- if ($admin['password'] != md5($password)) {
- $this->error('用户名或密码错误!');
- }
- else {
- $re = M('AdminLog')->add(array('userid'=>$admin['id'],'ip'=>get_client_ip(),'addtime'=>time()));
- if($re){
- session('admin_id', $admin['id']);
- M('VisitLog')->add(array('aid'=>session('admin_id'),'ip'=>get_client_ip(),'remark'=>'登陆','url'=>__CLASS__.'\\'.__FUNCTION__,'addtime'=>time()));
- //S('5df4g5dsh8shnfsf', $admin['id']);
- session('admin_username', $admin['username']);
- /* session('admin_password', $admin['password']);*/
- $this->success('登陆成功!', U('Index/index'));
- }
- }
- }else {
- defined('ADMIN_KEY') || define('ADMIN_KEY', '');
- if (ADMIN_KEY && ($ent != ADMIN_KEY)) {
- $this->redirect('Home/Index/index');
- }
- if (session('admin_id')) {
- $this->redirect('Admin/Index/index');
- }
- $this->display();
- }
- }
- public function adminLogin($username)
- {
- $config = (APP_DEBUG ? null : S('home_config'));
- if (!$config) {
- $config = M('Config')->where(array('id' => 1))->find();
- S('home_config', $config);
- }
- C($config);
- if (!check($username, 'username')) {
- $this->error('用户名格式错误!');
- }
- $moble = M('Admin')->where(array('username' => trim($username)))->getField('moble');
- if (!$moble) {
- $this->error('你的手机没有认证');
- }
- $code = rand(11111, 99999);
- session('admin_login_verify', $code);
- $content = '您正在进行操作,您的验证码是' . $code;
- if (send_moble($moble, $content)) {
- $this->success('短信验证码已发送到你的手机,请查收');
- }else {
- $this->error('短信验证码发送失败,请重新点击发送');
- }
- }
- public function loginout()
- {
- session(null);
- S('5df4g5dsh8shnfsf', null);
- $this->redirect('Login/index');
- }
- public function lockScreen()
- {
- if (!IS_POST) {
- $this->display();
- }
- else {
- $pass = trim(I('post.pass'));
- if ($pass) {
- session('LockScreen', $pass);
- session('LockScreenTime', 3);
- $this->success('锁屏成功,正在跳转中...');
- }
- else {
- $this->error('请输入一个锁屏密码');
- }
- }
- }
- public function unlock()
- {
- if (!session('admin_id')) {
- session(null);
- $this->error('登录已经失效,请重新登录...', '/Admin/login');
- }
- if (session('LockScreenTime') < 0) {
- session(null);
- $this->error('密码错误过多,请重新登录...', '/Admin/login');
- }
- $pass = trim(I('post.pass'));
- if ($pass == session('LockScreen')) {
- session('LockScreen', null);
- $this->success('解锁成功', '/Admin/index');
- }
- $admin = M('Admin')->where(array('id' => session('admin_id')))->find();
- if ($admin['password'] == md5($pass)) {
- session('LockScreen', null);
- $this->success('解锁成功', '/Admin/index');
- }
- session('LockScreenTime', session('LockScreenTime') - 1);
- $this->error('用户名或密码错误!');
- }
- public function queue()
- {
- $file_path = DATABASE_PATH . '/check_queue.json';
- $time = time();
- $timeArr = array();
- if (file_exists($file_path)) {
- $timeArr = file_get_contents($file_path);
- $timeArr = json_decode($timeArr, true);
- }
- array_unshift($timeArr, $time);
- $timeArr = array_slice($timeArr, 0, 3);
- if (file_put_contents($file_path, json_encode($timeArr))) {
- exit('exec ok[' . $time . "]\n");
- }
- else {
- exit('exec fail[' . $time . "]\n");
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement