v1.0

parent 7e0b54d0
......@@ -6,7 +6,9 @@ use App\Model\SupplierAccountModel;
use Illuminate\Http\Request;
use App\Http\Requests;
use RedisDB;
/*
* 登录后的api操作
*/
class ApiController extends Controller
{
public function Entrance(Request $request, $id ){
......@@ -14,12 +16,15 @@ class ApiController extends Controller
}
//登录
private function ApiLogin($request, $id){
Export((new SupplierAccountModel())->Login());
Export((new SupplierAccountModel())->Login($request));
}
//修改密码
private function ApiRestPassword($request, $id){
$yunxin_token = $request->cookie('yunxin_token');
Export((new SupplierAccountModel())->RestPassword());
Export((new SupplierAccountModel())->RestPassword($request));
}
//忘记密码
private function ApiForgetPassword($request, $id){
Export((new SupplierAccountModel())->ForgetPassword($request));
}
}
......@@ -5,16 +5,17 @@ namespace App\Http\Controllers;
use App\Http\Requests;
use Gregwar\Captcha\CaptchaBuilder;
use Illuminate\Http\Request;
use Session;
use App\Plugin\Session;
use Illuminate\Support\Facades\Redis;
class HelperController extends Controller {
//初始函数
public function Entrance(Request $request, $id ){
session_start();
$this->$id($request, $id);
}
//生成验证码
private function captcha($tmp) {
session_start(); // 初始化session
private function captcha() {
//生成验证码图片的Builder对象,配置相应属性
$builder = new CaptchaBuilder;
//可以设置图片宽高及字体
......@@ -22,7 +23,7 @@ class HelperController extends Controller {
//获取验证码的内容
$phrase = $builder->getPhrase();
//把内容存入session
$_SESSION['yunxin_captcha']= $phrase;
Session::set('yunxin_code',$phrase,60); //60秒过期
//生成图片
header("Cache-Control: no-cache, must-revalidate");
header('Content-Type: image/jpeg');
......@@ -30,10 +31,9 @@ class HelperController extends Controller {
}
//验证注册码的正确与否
private function verifyCaptcha() {
session_start();
$userInput = Request::input("code");
if ($_SESSION['yunxin_captcha'] == $userInput) {
private function verifyCaptcha($request) {
$code = $request->input("code");
if (Session::get('yunxin_code',true) == $code) {
//用户输入验证码正确
Export([0,'success']);
} else {
......@@ -41,4 +41,29 @@ class HelperController extends Controller {
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,'生成手机验证码失败']);
}
}
......@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Model\SupplierAccountModel;
use Config;
use Illuminate\Http\Request;
use App\Http\Requests;
......@@ -31,6 +32,12 @@ class WebController extends Controller
$data['time']=time();
return view('pc.Login',$data);
}
/*
* 退出登录
*/
private function LoginOut($request,$data,$id){
(new SupplierAccountModel())->LoginOut($request);
}
//修改登录密码
private function ResetPassword($request,$data,$id){
$data['title']='欢迎使用云芯系统';
......
......@@ -13,7 +13,8 @@ class CheckLogin
{
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);
$nowUrl = $request->url();
......@@ -22,7 +23,7 @@ class CheckLogin
if ($pos === 0) $isApi = true;
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,'请登录'];
}
if (strpos($nowUrl,'/web/login') == false && !$isApi){
......@@ -34,6 +35,7 @@ class CheckLogin
$request->supplier_id = $userInfoArr['supplier_id'];
$request->supplier_name = $userInfoArr['supplier_name'];
$request->role_id = $userInfoArr['role_id'];
$request->yunxin_token = $yunxin_token;
return $next($request);
}
......
<?php
namespace App\map;
namespace App\Map;
class OperationLogMap{
......
<?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
......@@ -15,21 +15,27 @@ class SupplierAccountModel extends Model
protected $table='supplier_account';
protected $primaryKey='id';
public $timestamps = false;
private $CheckCode = false; //是否开启验证码验证
/*
* 供应商登录
* @param int $account_id 账号id
*/
public function Login(){
public function Login($request){
session_start();
$mobile = Request::input('mobile');
$account_name = Request::input('account_name');
$password = Request::input('password');
$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) {
// return [1001,'验证码不正确'];
// }
$account = $this->where("mobile",$mobile)->first();
if ($this->CheckCode && $_SESSION['yunxin_captcha'] != $code) {
return [1001,'验证码不正确'];
}
$account = $this->where("mobile",$account_name)->first();
if (!$account){
return [1002,'不存在此账号'];
}
......@@ -53,7 +59,7 @@ class SupplierAccountModel extends Model
$con = DB::connection('web');
$con->beginTransaction();
#登录信息写入缓存
$key = md5($mobile.$code.time());
$key = md5($account_name.$code.time());
$expire = 7200;//过期两个小时
$res = Redis::setex('yunxin_login_'.$key, $expire, utf8JsonEncode($info));
if ($res != 'OK'){
......@@ -62,7 +68,7 @@ class SupplierAccountModel extends Model
#记录登录日志
$log['account_id'] = $account['id'];
$log['action_ip'] = $mobile;
$log['action_ip'] = $request->getClientIp();
$log['create_time'] = time();
$log['remark'] = utf8JsonEncode($info);
$logid = $yunxinCon->table("log_login")->insertGetId($log);
......@@ -82,16 +88,64 @@ class SupplierAccountModel extends Model
* 重置密码
* @param int $account_id 账号id
*/
public function ResetPassword($account_id){
$mobile = Request::input('mobile');
$password = Request::input('password');
public function RestPassword($request){
session_start();
$old_password = $request->input('old_password');
$new_password = $request->input('new_password');
$code= Request::input('code');//验证码
$password = createPassword(md5(Config("fixed.supplier_reset_password")));
$result=$this->where("id",$account_id)->update(['password'=>$password]);
return [0,"重置密码成功,密码为:".Config("fixed.supplier_reset_password")];
if ($this->CheckCode && (empty($code) || @$_SESSION['yunxin_captcha'] != $code)) {
return [1001,'验证码不正确'];
}
$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
<?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
......@@ -46,7 +46,7 @@
<i class="icn ico-2"></i>
</a>
<!--退出按钮-->
<a class="exit-btn" href="javascript:;">
<a class="exit-btn" href="/web/LoginOut">
<i class="icn arr"></i>
<i class="icn ico-1"></i>
<span>退出登录</span>
......
......@@ -13,8 +13,8 @@
<link rel="stylesheet" type="text/css" href="/pc/css/style.min.css?v={{ $time }}">
<script>
//存放公共变量
var _URL_ = "<?php echo $_URL_; ?>";
var _DOMAIN_ = "<?php echo $_DOMAIN_; ?>";
var _URL_ = "<?php echo $_URL_; ?>";
var _DOMAIN_ = "<?php echo $_DOMAIN_; ?>";
</script>
</head>
<body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment