147 lines
3.7 KiB
PHP
147 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Classc\GoogleAuthenticator;
|
|
use App\Services\DateServices;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use Log;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use App\Models\SystemUpdateLog;
|
|
|
|
class HomeController extends BaseController
|
|
{
|
|
public function index()
|
|
{
|
|
$this->setTitle('网站后台');
|
|
if (is_mobile_client()) {
|
|
//$this->setViewPath('','mobile');
|
|
return redirect()->action('Admin\HomeController@console');
|
|
}
|
|
return $this->display();
|
|
}
|
|
|
|
public function console()
|
|
{
|
|
$data = [];
|
|
$data['day_before_7'] = DateServices::decrDay('', 6);
|
|
$data['update_log'] = SystemUpdateLog::where('type', 'system')->limit(10)->orderBy('id', 'desc')->get();
|
|
|
|
//DateServices::diffDay('2019-01-02','2019-01-05');
|
|
|
|
return $this->display($data);
|
|
}
|
|
|
|
public function online($id)
|
|
{
|
|
$this->setViewPath('', 'online');
|
|
|
|
$data = [
|
|
|
|
];
|
|
return $this->display($data);
|
|
}
|
|
|
|
public function showNotice($id, $request)
|
|
{
|
|
$this->setViewPath('', 'notice');
|
|
$notice = NoticeArticle::find($id);
|
|
$data = [
|
|
'show' => $notice
|
|
];
|
|
return $this->display($data);
|
|
}
|
|
|
|
public function show($type, $id, Request $request)
|
|
{
|
|
return $this->$type($id, $request);
|
|
}
|
|
|
|
public function password($id)
|
|
{
|
|
$this->setViewPath('', 'password');
|
|
|
|
$data = [
|
|
|
|
];
|
|
return $this->display($data);
|
|
}
|
|
|
|
public function googleAuth($id, Request $request)
|
|
{
|
|
$user = admin();
|
|
$this->setViewPath('', 'googleauth');
|
|
$googleAuthSecretLength = 24;
|
|
$ga = new GoogleAuthenticator();
|
|
$key = $ga->createSecret($googleAuthSecretLength);
|
|
$content = $ga->getQrContent($request->root(), $key, $user->account);
|
|
$data = ['secret' => $key, 'content' => $content];
|
|
return $this->display($data);
|
|
}
|
|
|
|
|
|
public function googleAuthUpdate(Request $request)
|
|
{
|
|
$code = $request->post('code');
|
|
$secret = $request->post('secret');
|
|
if (empty($secret) || empty($code)) {
|
|
return $this->alertError('验证码不能为空', 1);
|
|
}
|
|
$ga = new GoogleAuthenticator();
|
|
$user = admin();
|
|
$code = strval($code);
|
|
if ($ga->verifyCode($secret, $code)) {
|
|
$user->google_secret = $secret;
|
|
if ($user->save()) {
|
|
return $this->alertError('绑定成功', 0);
|
|
} else {
|
|
return $this->alertError('绑定失败', 1);
|
|
}
|
|
} else {
|
|
return $this->alertError('验证失败', 1);
|
|
}
|
|
}
|
|
|
|
public function update($method, Request $request)
|
|
{
|
|
|
|
return $this->$method($request);
|
|
}
|
|
|
|
public function passwordUpdate($request)
|
|
{
|
|
$error = $this->validatorForm($request, 'password');
|
|
if (count($error) > 0) {
|
|
return $this->formError($error);
|
|
};
|
|
$user = admin();
|
|
$password = $request->input('password');
|
|
$old_password = $request->input('old_password');
|
|
if (!Hash::check($old_password, $user->password)) {
|
|
return $this->alertError('旧密码不对');
|
|
}
|
|
$user->password = $password;
|
|
if ($user->save()) {
|
|
return $this->alertError('修改密码成功', 0);
|
|
}
|
|
return $this->alertError('修改密码失败', 1);
|
|
|
|
}
|
|
|
|
public function checkRule($id = '')
|
|
{
|
|
return [
|
|
'password' => 'required|confirmed',
|
|
'old_password' => 'required'
|
|
];
|
|
}
|
|
|
|
public function setErrorMsg()
|
|
{
|
|
return [
|
|
'old_password' => '旧密码'
|
|
];
|
|
}
|
|
}
|