作者 李美松

Merge branch 'develop' into lms

... ... @@ -15,7 +15,7 @@ use App\Models\AyrShare\AyrShare as AyrShareModel;
class AyrShareController extends BaseController
{
//生成名称前缀
const TITLE = 'global_so_';
const TITLE = 'globalso';
/**
* @name :(社交列表)lists
* @author :lyh
... ... @@ -82,7 +82,7 @@ class AyrShareController extends BaseController
public function create_account(AyrShareRequest $ayrShareRequest,AyrShareLogic $ayrShareLogic){
$ayrShareRequest->validated();
$param = [
'title'=>self::TITLE.$this->user['project_id'].':'.$this->param['name'],
'title'=>self::TITLE . ':' . $this->user['project_id'] . '-' . $this->param['name'],
];
//发送请求注册社交用户
$ayrShareHelper = new AyrShareHelper();
... ...
... ... @@ -9,9 +9,11 @@ use App\Models\AyrShare\AyrRelease as AyrReleaseModel;
use App\Models\AyrShare\AyrShare as AyrShareModel;
use App\Models\Project\Project;
use App\Models\Project\Project as ProjectModel;
use App\Models\SmsLog;
use App\Models\User\ProjectMenu as ProjectMenuModel;
use App\Models\User\ProjectRole as ProjectRoleModel;
use App\Models\User\User as UserModel;
use App\Models\User\User;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
... ... @@ -29,12 +31,12 @@ class ComController extends BaseController
*/
public function login(){
$this->request->validate([
'mobile'=>['required'],
'mobile'=>['required', 'regex:/^1[3-9]\d{9}$/'],
'password'=>['required'],
],[
'mobile.required'=>'电话号码必须填写',
'password.required'=>'内容必须填写',
'mobile.max' => 'mobile不大于12字符.',
'mobile.regex' => '请输入正确的手机号码',
]);
$userModel = new UserModel();
$res = $userModel->login($this->param);
... ... @@ -120,60 +122,37 @@ class ComController extends BaseController
$this->response('success');
}
/**
* @name : (测试定时任务)检测用户是否无操作记录
* @author :lyh
* @method :post
* @time :2023/5/12 14:55
* 发送登录短信
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
protected function ceShi(){
$this->error = 0;
//获取所有ayr_share用户
$ayr_share_model = new AyrShareModel();
$ayr_share_list = $ayr_share_model->list($this->map);
if(!empty($ayr_share_list)){
foreach ($ayr_share_list as $k => $v){
//查询当前用户是否有未推送的博文
$ayr_release = new AyrReleaseModel();
$release_info = $ayr_release->read(['schedule_date'=>['>',date('Y-m-d H:i:s',time())],'share_id'=>$v['id']]);
//有推文时,直接跳出循环
if($release_info !== false){
continue;
}
//查看用户是否在一周内有发送博客
$start_at = Carbon::now()->modify('-7 days')->toDateString();
$end_at = Carbon::now()->toDateString();
$release_info = $ayr_release->read(['created_at'=>['between',[$start_at,$end_at]]]);
//有发送博文,则跳出循环
if($release_info == false){
continue;
}
//删除用户第三方配置
$ayr_share_helper = new AyrShareHelper();
$data_profiles = [
'title'=>$v['title'],
'profileKey'=>$v['profile_key']
];
$res = $ayr_share_helper->deleted_profiles($data_profiles);
if($res['status'] == 'fail'){
$this->error++;
continue;
}
//更新数据库
$data = [
'title'=>null,
'bind_plat_from'=>null,
'profile_key'=>null,
'ref_id'=>null,
];
$res = $ayr_share_model->edit($data,['id'=>$v['id']]);
if($res == false){
$this->error++;
}
}
public function sendLoginSms(Request $request)
{
$this->request->validate([
'mobile'=>['required', 'regex:/^1[3-9]\d{9}$/'],
],[
'mobile.required' => '手机号码不能为空',
'mobile.regex' => '请输入正确的手机号码',
]);
$mobile = $request->input('mobile');
$user = User::where(['mobile' => $mobile])->first();
if (empty($user)) {
return $this->response('请输入正确的手机号码!', Code::USER_LOGIN_ERROE);
}
$last_sms = SmsLog::getLastLog($mobile, SmsLog::TYPE_LOGIN);
if ($last_sms && $last_sms->use = SmsLog::USE_USABLE && time() - strtotime($last_sms->created_at) < 60) {
return $this->response('请不要重复发送短信!', Code::USER_LOGIN_ERROE);
}
$template = config('alisms.login_sms_temp');
$code['code'] = rand(100000,999999);
$ali_sms = new AliSms();
$send = $ali_sms->sendSms(strval($mobile), $template, $code);
if (empty($send->Code) && $send->Code != 'OK') {
return $this->response('发送失败, 请稍后重试!', Code::USER_LOGIN_ERROE);
}
return $this->error;
SmsLog::createLog($mobile, $code['code']);
return $this->response('success');
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/6/3
* Time: 17:42
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class SmsLog extends Model
{
//设置关联表名
protected $table = 'gl_sms_log';
const TYPE_REGISTER = 'register';
const TYPE_LOGIN = 'login';
const TYPE_NOTICE = 'notice';
const USE_USABLE = 0;
const USE_DISABLE = 1;
/**
* 创建日志
* @param $mobile
* @param $code
* @param $type
* @param string $content
* @return mixed
*/
public static function createLog($mobile, $code, $type = self::TYPE_LOGIN, $content = '')
{
$created_at = $updated_at = date('Y-m-d H:i:s');
$array = compact('type', 'mobile', 'code', 'content', 'updated_at', 'created_at');
return self::insert($array);
}
/**
* 查询最后一条日志
* @param $mobile
* @param $type
* @return mixed
*/
public static function getLastLog($mobile, $type)
{
return self::where(compact('type', 'mobile'))->orderBy('id', 'desc')->first();
}
}
\ No newline at end of file
... ...
... ... @@ -5,6 +5,7 @@ namespace App\Models\User;
//use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Helper\Common;
use App\Models\Base;
use App\Models\SmsLog;
use App\Models\User\ProjectRole as ProjectRoleModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Notifications\Notifiable;
... ... @@ -59,17 +60,20 @@ class User extends Base
* @method
*/
public function login($param){
if(!isset($param['login_method'])){
//密码加密
$param['password'] = base64_encode(md5($param['password']));
$info = $this->read(['mobile'=>$param['mobile']
,'password'=>$param['password'],'status'=>0], ['id','mobile','role_id','token','name','project_id']);
}else{
//TODO::验证验证码是否正确
$info = $this->read(['mobile'=>$param['mobile']],['*']);
}
//验证账号密码
$password = base64_encode(md5($param['password']));
$info = $this->read(['mobile'=>$param['mobile'],'password'=>$password,'status'=>0], ['id','mobile','role_id','token','name','project_id']);
if($info === false){
return false;
//账号密码没通过时,验证验证码
$info = $this->read(['mobile'=>$param['mobile'],'status'=>0], ['id','mobile','role_id','token','name','project_id']);
if($info === false){
return false;
}
//验证验证码是否准备
$last_sms = SmsLog::getLastLog($param['mobile'], SmsLog::TYPE_LOGIN);
if($param['password'] != $last_sms->code){
return false;
}
}
//当前用户角色是否被禁用
$projectRoleModel = new ProjectRoleModel();
... ... @@ -119,5 +123,4 @@ class User extends Base
Cache::pull($info['token']);
return true;
}
}
... ...
... ... @@ -15,7 +15,8 @@
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5",
"mongodb/mongodb": "^1.6",
"phpoffice/phpspreadsheet": "^1.28"
"phpoffice/phpspreadsheet": "^1.28",
"mrgoon/aliyun-sms": "^2.0"
},
"require-dev": {
"facade/ignition": "^2.5",
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/6/3
* Time: 17:39
*/
return [
'access_key' => env('ALIYUN_SMS_AK'), // accessKey
'access_secret' => env('ALIYUN_SMS_AS'), // accessSecret
'sign_name' => env('ALIYUN_SMS_SIGN_NAME'), // 签名
// login
'login_sms_temp' => 'SMS_272545773',
// 注册
'register_sms_temp' => 'SMS_272430790',
];
\ No newline at end of file
... ...
... ... @@ -293,7 +293,7 @@ Route::middleware(['bloginauth'])->group(function () {
//无需登录验证的路由组
Route::group([], function () {
Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login');
Route::any('/', [\App\Http\Controllers\Bside\ComController::class, 'ceShi'])->name('ce_shi');
Route::any('/sendLoginSms', [\App\Http\Controllers\Bside\ComController::class, 'sendLoginSms'])->name('sendLoginSms');
Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download');
Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\File\ImageController::class,'index'])->name('image_show');
Route::any('/file_hash/{hash}', [\App\Http\Controllers\File\FileController::class,'index'])->name('file_show');
... ...