Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
yunxin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
44551066
authored
Feb 27, 2019
by
PRY5YKGJ82EZEPX\Administrator
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
v1.0
parent
7e0b54d0
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
173 additions
and
51 deletions
app/Http/Controllers/ApiController.php
app/Http/Controllers/HelperController.php
app/Http/Controllers/WebController.php
app/Http/Middleware/CheckLogin.php
app/map/OperationLogMap.php → app/Map/OperationLogMap.php
app/Model/LogLoginModel.php
app/Model/SupplierAccountModel.php
app/Plugin/Session.php
resources/views/pc.blade.php
resources/views/pc/Login.blade.php
app/Http/Controllers/ApiController.php
View file @
44551066
...
@@ -6,7 +6,9 @@ use App\Model\SupplierAccountModel;
...
@@ -6,7 +6,9 @@ use App\Model\SupplierAccountModel;
use
Illuminate\Http\Request
;
use
Illuminate\Http\Request
;
use
App\Http\Requests
;
use
App\Http\Requests
;
use
RedisDB
;
use
RedisDB
;
/*
* 登录后的api操作
*/
class
ApiController
extends
Controller
class
ApiController
extends
Controller
{
{
public
function
Entrance
(
Request
$request
,
$id
){
public
function
Entrance
(
Request
$request
,
$id
){
...
@@ -14,12 +16,15 @@ class ApiController extends Controller
...
@@ -14,12 +16,15 @@ class ApiController extends Controller
}
}
//登录
//登录
private
function
ApiLogin
(
$request
,
$id
){
private
function
ApiLogin
(
$request
,
$id
){
Export
((
new
SupplierAccountModel
())
->
Login
());
Export
((
new
SupplierAccountModel
())
->
Login
(
$request
));
}
}
//修改密码
//修改密码
private
function
ApiRestPassword
(
$request
,
$id
){
private
function
ApiRestPassword
(
$request
,
$id
){
$yunxin_token
=
$request
->
cookie
(
'yunxin_token'
);
Export
((
new
SupplierAccountModel
())
->
RestPassword
(
$request
));
Export
((
new
SupplierAccountModel
())
->
RestPassword
());
}
//忘记密码
private
function
ApiForgetPassword
(
$request
,
$id
){
Export
((
new
SupplierAccountModel
())
->
ForgetPassword
(
$request
));
}
}
}
}
app/Http/Controllers/HelperController.php
View file @
44551066
...
@@ -5,16 +5,17 @@ namespace App\Http\Controllers;
...
@@ -5,16 +5,17 @@ namespace App\Http\Controllers;
use
App\Http\Requests
;
use
App\Http\Requests
;
use
Gregwar\Captcha\CaptchaBuilder
;
use
Gregwar\Captcha\CaptchaBuilder
;
use
Illuminate\Http\Request
;
use
Illuminate\Http\Request
;
use
Session
;
use
App\Plugin\Session
;
use
Illuminate\Support\Facades\Redis
;
class
HelperController
extends
Controller
{
class
HelperController
extends
Controller
{
//初始函数
public
function
Entrance
(
Request
$request
,
$id
){
public
function
Entrance
(
Request
$request
,
$id
){
session_start
();
$this
->
$id
(
$request
,
$id
);
$this
->
$id
(
$request
,
$id
);
}
}
//生成验证码
//生成验证码
private
function
captcha
(
$tmp
)
{
private
function
captcha
()
{
session_start
();
// 初始化session
//生成验证码图片的Builder对象,配置相应属性
//生成验证码图片的Builder对象,配置相应属性
$builder
=
new
CaptchaBuilder
;
$builder
=
new
CaptchaBuilder
;
//可以设置图片宽高及字体
//可以设置图片宽高及字体
...
@@ -22,7 +23,7 @@ class HelperController extends Controller {
...
@@ -22,7 +23,7 @@ class HelperController extends Controller {
//获取验证码的内容
//获取验证码的内容
$phrase
=
$builder
->
getPhrase
();
$phrase
=
$builder
->
getPhrase
();
//把内容存入session
//把内容存入session
$_SESSION
[
'yunxin_captcha'
]
=
$phrase
;
Session
::
set
(
'yunxin_code'
,
$phrase
,
60
);
//60秒过期
//生成图片
//生成图片
header
(
"Cache-Control: no-cache, must-revalidate"
);
header
(
"Cache-Control: no-cache, must-revalidate"
);
header
(
'Content-Type: image/jpeg'
);
header
(
'Content-Type: image/jpeg'
);
...
@@ -30,10 +31,9 @@ class HelperController extends Controller {
...
@@ -30,10 +31,9 @@ class HelperController extends Controller {
}
}
//验证注册码的正确与否
//验证注册码的正确与否
private
function
verifyCaptcha
()
{
private
function
verifyCaptcha
(
$request
)
{
session_start
();
$code
=
$request
->
input
(
"code"
);
$userInput
=
Request
::
input
(
"code"
);
if
(
Session
::
get
(
'yunxin_code'
,
true
)
==
$code
)
{
if
(
$_SESSION
[
'yunxin_captcha'
]
==
$userInput
)
{
//用户输入验证码正确
//用户输入验证码正确
Export
([
0
,
'success'
]);
Export
([
0
,
'success'
]);
}
else
{
}
else
{
...
@@ -41,4 +41,29 @@ class HelperController extends Controller {
...
@@ -41,4 +41,29 @@ class HelperController extends Controller {
Export
([
1001
,
'验证码输入错误'
]);
Export
([
1001
,
'验证码输入错误'
]);
}
}
}
}
/*
* 发送手机验证码
* @param string $mobile 手机号码
* @param string $code 图形验证码
*/
private
function
moblieCode
(
$request
,
$id
){
$mobile
=
$request
->
input
(
'mobile'
);
//手机号码
$code
=
$request
->
input
(
'code'
);
//图形验证码
if
(
Session
::
get
(
'yunxin_code'
,
true
)
!=
$code
)
{
//用户输入验证码错误
Export
([
1001
,
'验证码输入错误'
]);
}
$checkTime
=
Redis
::
ttl
(
'yunxin_mobile_code_'
.
$mobile
);
if
(
$checkTime
>
0
){
Export
([
1001
,
'同一手机号一分钟只能请求一次验证码!'
]);
}
$moblie_code
=
mt_rand
(
9999
,
99999
);
$expire
=
60
;
//60秒
$check1
=
Redis
::
setex
(
'yunxin_mobile_code_'
.
$mobile
,
$expire
,
$moblie_code
);
$check2
=
SendMsg
([
'code'
=>
$moblie_code
],
'login-code'
,[
$mobile
]);
//发送验证码
$check1
==
'OK'
?
Export
([
0
,
'成功'
])
:
Export
([
1002
,
'生成手机验证码失败'
]);
}
}
}
app/Http/Controllers/WebController.php
View file @
44551066
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
App\Http\Controllers
;
namespace
App\Http\Controllers
;
use
App\Model\SupplierAccountModel
;
use
Config
;
use
Config
;
use
Illuminate\Http\Request
;
use
Illuminate\Http\Request
;
use
App\Http\Requests
;
use
App\Http\Requests
;
...
@@ -31,6 +32,12 @@ class WebController extends Controller
...
@@ -31,6 +32,12 @@ class WebController extends Controller
$data
[
'time'
]
=
time
();
$data
[
'time'
]
=
time
();
return
view
(
'pc.Login'
,
$data
);
return
view
(
'pc.Login'
,
$data
);
}
}
/*
* 退出登录
*/
private
function
LoginOut
(
$request
,
$data
,
$id
){
(
new
SupplierAccountModel
())
->
LoginOut
(
$request
);
}
//修改登录密码
//修改登录密码
private
function
ResetPassword
(
$request
,
$data
,
$id
){
private
function
ResetPassword
(
$request
,
$data
,
$id
){
$data
[
'title'
]
=
'欢迎使用云芯系统'
;
$data
[
'title'
]
=
'欢迎使用云芯系统'
;
...
...
app/Http/Middleware/CheckLogin.php
View file @
44551066
...
@@ -13,7 +13,8 @@ class CheckLogin
...
@@ -13,7 +13,8 @@ class CheckLogin
{
{
public
function
handle
(
$request
,
Closure
$next
)
public
function
handle
(
$request
,
Closure
$next
)
{
{
$yunxin_token
=
$request
->
cookie
(
'yunxin_token'
);
//前端用户登录token
$yunxin_token
=
$request
->
cookie
(
'yunxin_token'
)
==
""
?
$request
->
input
(
'yunxin_token'
)
:
""
;
$userInfo
=
Redis
::
get
(
'yunxin_login_'
.
$yunxin_token
);
$userInfo
=
Redis
::
get
(
'yunxin_login_'
.
$yunxin_token
);
$nowUrl
=
$request
->
url
();
$nowUrl
=
$request
->
url
();
...
@@ -22,7 +23,7 @@ class CheckLogin
...
@@ -22,7 +23,7 @@ class CheckLogin
if
(
$pos
===
0
)
$isApi
=
true
;
if
(
$pos
===
0
)
$isApi
=
true
;
if
(
empty
(
$yunxin_token
)
||
empty
(
$userInfo
)
){
//没有登录跳到登录页
if
(
empty
(
$yunxin_token
)
||
empty
(
$userInfo
)
){
//没有登录跳到登录页
if
(
strpos
(
$nowUrl
,
'/api/ApiLogin'
)
==
false
&&
$isApi
){
if
(
strpos
(
$nowUrl
,
'/api/ApiLogin'
)
==
false
&&
strpos
(
$nowUrl
,
'/api/ApiLogin'
)
==
false
&&
$isApi
){
return
[
-
1
,
'请登录'
];
return
[
-
1
,
'请登录'
];
}
}
if
(
strpos
(
$nowUrl
,
'/web/login'
)
==
false
&&
!
$isApi
){
if
(
strpos
(
$nowUrl
,
'/web/login'
)
==
false
&&
!
$isApi
){
...
@@ -34,6 +35,7 @@ class CheckLogin
...
@@ -34,6 +35,7 @@ class CheckLogin
$request
->
supplier_id
=
$userInfoArr
[
'supplier_id'
];
$request
->
supplier_id
=
$userInfoArr
[
'supplier_id'
];
$request
->
supplier_name
=
$userInfoArr
[
'supplier_name'
];
$request
->
supplier_name
=
$userInfoArr
[
'supplier_name'
];
$request
->
role_id
=
$userInfoArr
[
'role_id'
];
$request
->
role_id
=
$userInfoArr
[
'role_id'
];
$request
->
yunxin_token
=
$yunxin_token
;
return
$next
(
$request
);
return
$next
(
$request
);
}
}
...
...
app/
m
ap/OperationLogMap.php
→
app/
M
ap/OperationLogMap.php
View file @
44551066
<?php
<?php
namespace
App\
m
ap
;
namespace
App\
M
ap
;
class
OperationLogMap
{
class
OperationLogMap
{
...
...
app/Model/LogLoginModel.php
deleted
100644 → 0
View file @
7e0b54d0
<?php
namespace
App\Model
;
use
ClassPreloader\Config
;
use
Illuminate\Database\Eloquent\Model
;
use
League\Flysystem\Exception
;
use
Request
;
use
DB
;
class
SupplierAccountModel
extends
Model
{
protected
$connection
=
'yunxin'
;
protected
$table
=
'log_login'
;
protected
$primaryKey
=
'id'
;
public
$timestamps
=
false
;
}
\ No newline at end of file
app/Model/SupplierAccountModel.php
View file @
44551066
...
@@ -15,21 +15,27 @@ class SupplierAccountModel extends Model
...
@@ -15,21 +15,27 @@ class SupplierAccountModel extends Model
protected
$table
=
'supplier_account'
;
protected
$table
=
'supplier_account'
;
protected
$primaryKey
=
'id'
;
protected
$primaryKey
=
'id'
;
public
$timestamps
=
false
;
public
$timestamps
=
false
;
private
$CheckCode
=
false
;
//是否开启验证码验证
/*
/*
* 供应商登录
* 供应商登录
* @param int $account_id 账号id
* @param int $account_id 账号id
*/
*/
public
function
Login
(){
public
function
Login
(
$request
){
session_start
();
session_start
();
$
mobile
=
Request
::
input
(
'mobil
e'
);
$
account_name
=
Request
::
input
(
'account_nam
e'
);
$password
=
Request
::
input
(
'password'
);
$password
=
Request
::
input
(
'password'
);
$code
=
Request
::
input
(
'code'
);
//验证码
$code
=
Request
::
input
(
'code'
);
//验证码
if
(
empty
(
$account_name
))
return
[
1001
,
'账号不得为空'
];
if
(
empty
(
$password
)
)
return
[
1001
,
'登录密码不得为空'
];
if
(
utf8_strlen
(
$password
)
!=
32
)
return
[
1001
,
'登录密码长度不对'
];
if
(
empty
(
$code
))
return
[
1001
,
'验证码不得为空'
];
// if (
$_SESSION['yunxin_captcha'] != $code) {
if
(
$this
->
CheckCode
&&
$_SESSION
[
'yunxin_captcha'
]
!=
$code
)
{
//
return [1001,'验证码不正确'];
return
[
1001
,
'验证码不正确'
];
//
}
}
$account
=
$this
->
where
(
"mobile"
,
$
mobil
e
)
->
first
();
$account
=
$this
->
where
(
"mobile"
,
$
account_nam
e
)
->
first
();
if
(
!
$account
){
if
(
!
$account
){
return
[
1002
,
'不存在此账号'
];
return
[
1002
,
'不存在此账号'
];
}
}
...
@@ -53,7 +59,7 @@ class SupplierAccountModel extends Model
...
@@ -53,7 +59,7 @@ class SupplierAccountModel extends Model
$con
=
DB
::
connection
(
'web'
);
$con
=
DB
::
connection
(
'web'
);
$con
->
beginTransaction
();
$con
->
beginTransaction
();
#登录信息写入缓存
#登录信息写入缓存
$key
=
md5
(
$
mobil
e
.
$code
.
time
());
$key
=
md5
(
$
account_nam
e
.
$code
.
time
());
$expire
=
7200
;
//过期两个小时
$expire
=
7200
;
//过期两个小时
$res
=
Redis
::
setex
(
'yunxin_login_'
.
$key
,
$expire
,
utf8JsonEncode
(
$info
));
$res
=
Redis
::
setex
(
'yunxin_login_'
.
$key
,
$expire
,
utf8JsonEncode
(
$info
));
if
(
$res
!=
'OK'
){
if
(
$res
!=
'OK'
){
...
@@ -62,7 +68,7 @@ class SupplierAccountModel extends Model
...
@@ -62,7 +68,7 @@ class SupplierAccountModel extends Model
#记录登录日志
#记录登录日志
$log
[
'account_id'
]
=
$account
[
'id'
];
$log
[
'account_id'
]
=
$account
[
'id'
];
$log
[
'action_ip'
]
=
$
mobile
;
$log
[
'action_ip'
]
=
$
request
->
getClientIp
()
;
$log
[
'create_time'
]
=
time
();
$log
[
'create_time'
]
=
time
();
$log
[
'remark'
]
=
utf8JsonEncode
(
$info
);
$log
[
'remark'
]
=
utf8JsonEncode
(
$info
);
$logid
=
$yunxinCon
->
table
(
"log_login"
)
->
insertGetId
(
$log
);
$logid
=
$yunxinCon
->
table
(
"log_login"
)
->
insertGetId
(
$log
);
...
@@ -82,16 +88,64 @@ class SupplierAccountModel extends Model
...
@@ -82,16 +88,64 @@ class SupplierAccountModel extends Model
* 重置密码
* 重置密码
* @param int $account_id 账号id
* @param int $account_id 账号id
*/
*/
public
function
ResetPassword
(
$account_id
){
public
function
RestPassword
(
$request
){
$mobile
=
Request
::
input
(
'mobile'
);
session_start
();
$password
=
Request
::
input
(
'password'
);
$old_password
=
$request
->
input
(
'old_password'
);
$new_password
=
$request
->
input
(
'new_password'
);
$code
=
Request
::
input
(
'code'
);
//验证码
$code
=
Request
::
input
(
'code'
);
//验证码
$password
=
createPassword
(
md5
(
Config
(
"fixed.supplier_reset_password"
)));
if
(
$this
->
CheckCode
&&
(
empty
(
$code
)
||
@
$_SESSION
[
'yunxin_captcha'
]
!=
$code
))
{
$result
=
$this
->
where
(
"id"
,
$account_id
)
->
update
([
'password'
=>
$password
]);
return
[
1001
,
'验证码不正确'
];
return
[
0
,
"重置密码成功,密码为:"
.
Config
(
"fixed.supplier_reset_password"
)];
}
$account
=
$this
->
where
(
"id"
,
$request
->
account_id
)
->
first
();
if
(
!
$account
){
return
[
1002
,
'不存在此账号'
];
}
if
(
$account
[
'password'
]
!=
createPassword
(
$old_password
)){
return
[
1003
,
'旧密码错误'
];
}
}
if
(
utf8_strlen
(
$new_password
)
!=
32
)
return
[
1001
,
'新密码长度不对'
];
$password
=
createPassword
(
$new_password
);
$this
->
where
(
"id"
,
$request
->
account_id
)
->
update
([
'password'
=>
$password
]);
Redis
::
del
(
"yunxin_login_"
.
$request
->
yunxin_token
);
//重新登录
return
[
0
,
"重置密码成功,请重新登录"
];
}
/*
* 忘记密码
* @param int $account_id 账号id
*/
public
function
ForgetPassword
(
$request
){
$account_name
=
$request
->
input
(
'account_name'
);
$new_password
=
$request
->
input
(
'new_password'
);
$mobile_code
=
Request
::
input
(
'moblie_code'
);
//手机验证码
$yunxin_mobile_code
=
Redis
::
get
(
'yunxin_mobile_code_'
.
$account_name
);
if
(
$yunxin_mobile_code
!=
$mobile_code
){
return
[
1001
,
'手机验证码不正确'
];
}
$account
=
$this
->
where
(
"id"
,
$request
->
account_id
)
->
first
();
if
(
!
$account
){
return
[
1002
,
'不存在此账号'
];
}
if
(
utf8_strlen
(
$new_password
)
!=
32
)
return
[
1001
,
'新密码长度不对'
];
$password
=
createPassword
(
$new_password
);
$this
->
where
(
"id"
,
$request
->
account_id
)
->
update
([
'password'
=>
$password
]);
Redis
::
del
(
"yunxin_login_"
.
$request
->
yunxin_token
);
//删除缓存
return
[
0
,
"成功,请登录"
];
}
/*
* 退出登录
*/
public
function
LoginOut
(
$request
){
$del
=
Redis
::
del
(
"yunxin_login_"
.
$request
->
yunxin_token
);
if
(
$del
){
return
redirect
(
'/web/login'
);
}
else
{
return
[
1001
,
'退出失败'
];
}
}
}
}
\ No newline at end of file
app/Plugin/Session.php
0 → 100644
View file @
44551066
<?php
namespace
App\Plugin
;
/**
* Session控制类
*/
class
Session
{
/**
* 设置session
* @param String $name session name
* @param Mixed $data session data
* @param Int $expire 超时时间(秒)
*/
public
static
function
set
(
$name
,
$data
,
$expire
=
600
){
$session_data
=
array
();
$session_data
[
'data'
]
=
$data
;
$session_data
[
'expire'
]
=
time
()
+
$expire
;
$_SESSION
[
$name
]
=
$session_data
;
}
/**
* 读取session
* @param String $name session名称
* @param String $clear 是否清空session
* @return Mixed
*/
public
static
function
get
(
$name
,
$clear
=
false
){
if
(
isset
(
$_SESSION
[
$name
])){
if
(
$_SESSION
[
$name
][
'expire'
]
>
time
()){
$data
=
$_SESSION
[
$name
][
'data'
];
if
(
$clear
){
unset
(
$_SESSION
[
$name
]);
}
return
$data
;
}
if
(
$clear
){
unset
(
$_SESSION
[
$name
]);
}
}
return
false
;
}
/**
* 清除session
* @param String $name session name
*/
public
static
function
clear
(
$name
){
unset
(
$_SESSION
[
$name
]);
}
}
\ No newline at end of file
resources/views/pc.blade.php
View file @
44551066
...
@@ -46,7 +46,7 @@
...
@@ -46,7 +46,7 @@
<i
class=
"icn ico-2"
></i>
<i
class=
"icn ico-2"
></i>
</a>
</a>
<!--退出按钮-->
<!--退出按钮-->
<a
class=
"exit-btn"
href=
"
javascript:;
"
>
<a
class=
"exit-btn"
href=
"
/web/LoginOut
"
>
<i
class=
"icn arr"
></i>
<i
class=
"icn arr"
></i>
<i
class=
"icn ico-1"
></i>
<i
class=
"icn ico-1"
></i>
<span>
退出登录
</span>
<span>
退出登录
</span>
...
...
resources/views/pc/Login.blade.php
View file @
44551066
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment