发布推送
This commit is contained in:
@ -2,11 +2,10 @@
|
||||
|
||||
namespace App\Http\Controllers\Base;
|
||||
|
||||
use App\Const\Responses;
|
||||
use App\Service\ReplyService;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class BaseController extends Controller
|
||||
abstract class BaseController extends Controller
|
||||
{
|
||||
public array $validateMethodParams = [];
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Base;
|
||||
|
||||
class CustomerBaseController extends BaseController
|
||||
abstract class CustomerBaseController extends BaseController
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@ -1,17 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Customer;
|
||||
|
||||
use App\Const\Im;
|
||||
use App\Const\VrCode;
|
||||
use App\Exceptions\AppException;
|
||||
use App\Http\Controllers\Base\CustomerBaseController;
|
||||
use App\Models\Customer\CustomerUser;
|
||||
use App\Models\Customer\CustomerUserModel;
|
||||
use App\Service\AuthService;
|
||||
use App\Service\ImService;
|
||||
use App\Service\VrCodeService;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use App\Tools\Tools;
|
||||
|
||||
class CustomerUserController extends CustomerBaseController
|
||||
{
|
||||
@ -21,6 +20,7 @@ class CustomerUserController extends CustomerBaseController
|
||||
'phone' => 'required|numeric|max:15',
|
||||
'password' => 'required|alpha_dash:ascii|max:50',
|
||||
'device' => 'required|numeric|max:10',
|
||||
'vr_code' => 'required|numeric|max:10',
|
||||
],
|
||||
'register' => [
|
||||
'phone_area' => 'required|alpha_dash:ascii|max:5',
|
||||
@ -35,7 +35,7 @@ class CustomerUserController extends CustomerBaseController
|
||||
'phone' => 'numeric|max:15',
|
||||
'email' => 'email|max:30',
|
||||
],
|
||||
'setUserInfo' => [
|
||||
'updateUserInfo' => [
|
||||
'nickname' => 'max:20',
|
||||
'email' => 'email|max:30',
|
||||
'username' => 'alpha_dash:ascii|max:50',
|
||||
@ -43,11 +43,6 @@ class CustomerUserController extends CustomerBaseController
|
||||
'phone' => 'numeric|max:15',
|
||||
'is_google_auth' => 'numeric|max:2',
|
||||
],
|
||||
'sendVrcodeCode' => [
|
||||
'topic' => 'required|numeric',
|
||||
'phone_area' => 'alpha_dash:ascii|max:5',
|
||||
'phone' => 'numeric|max:15',
|
||||
],
|
||||
];
|
||||
|
||||
function getCustomerUserInfo(): \Illuminate\Http\JsonResponse
|
||||
@ -58,7 +53,7 @@ class CustomerUserController extends CustomerBaseController
|
||||
$data = [
|
||||
'token' => $token,
|
||||
'user' => [
|
||||
'id' =>$aUser['id'],
|
||||
'id' => $aUser['id'],
|
||||
'username' => $aUser['username'],
|
||||
'nickname' => $aUser['nickname'],
|
||||
'is_google_auth' => $aUser['is_google_auth'],
|
||||
@ -69,29 +64,45 @@ class CustomerUserController extends CustomerBaseController
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws AppException
|
||||
*/
|
||||
function signIn(): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$request = request();
|
||||
$username = $request->input('username');
|
||||
$phone_area = $request->input('phone_area');
|
||||
$phone = $request->input('phone');
|
||||
$password = $request->input('password');
|
||||
$vrcode = $request->input('vrcode');
|
||||
$device = $request->input('device');
|
||||
if(!in_array($device,Im::PLATFORM)) return $this->error('invalid device');
|
||||
if (!in_array($device, Im::PLATFORM)) return $this->error('invalid device');
|
||||
|
||||
$oCustomerUser = new CustomerUser();
|
||||
$oUser = $oCustomerUser->findItemByUsername($username);
|
||||
$oCustomerUser = new CustomerUserModel();
|
||||
$oUser = $oCustomerUser->findItemByPhone($phone_area, $phone);
|
||||
|
||||
if (!$oUser) {
|
||||
return $this->error('用户名不存在');
|
||||
}
|
||||
|
||||
if (!$oCustomerUser->checkPasswd($oUser->id,$password)) {
|
||||
return $this->error('密码错误');
|
||||
if (!empty($vrcode)) { //phone login
|
||||
//check vrcode
|
||||
$oVrCodeService = new VrCodeService();
|
||||
$oVrCodeService->setIType(VrCode::TOPIC_LOGIN);
|
||||
$oVrCodeService->setSPhoneArea($phone_area);
|
||||
$oVrCodeService->setSPhone($phone);
|
||||
if (!$oVrCodeService->checkCode($vrcode)) return $this->error('验证码错误');
|
||||
} elseif (!empty($password)) { //password login
|
||||
if (!$oCustomerUser->checkPasswd($oUser->id, $password)) {
|
||||
return $this->error('密码错误');
|
||||
}
|
||||
} else {
|
||||
return $this->error('登录失败');
|
||||
}
|
||||
|
||||
$oAuthService = new AuthService();
|
||||
$oImService = new ImService();
|
||||
$token = $oAuthService->createTokenToUser($oUser->id,$device);
|
||||
$imToken = $oImService->authUserToken($oUser->id,$device);
|
||||
$token = $oAuthService->createTokenToUser($oUser->id, $device);
|
||||
$imToken = $oImService->authUserToken($oUser->id, $device);
|
||||
|
||||
$data = [
|
||||
'token' => $token,
|
||||
@ -109,11 +120,12 @@ class CustomerUserController extends CustomerBaseController
|
||||
|
||||
}
|
||||
|
||||
function setUserInfo(): \Illuminate\Http\JsonResponse
|
||||
function updateUserInfo(): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$request = request();
|
||||
$aReqData = $request->only([
|
||||
'nickname',
|
||||
'username',
|
||||
'email',
|
||||
'phone_area',
|
||||
'phone',
|
||||
@ -123,8 +135,8 @@ class CustomerUserController extends CustomerBaseController
|
||||
$aUser = $oAuthService->getCurrentUser();
|
||||
$aReqData['id'] = $aUser['id'];
|
||||
$aReqData = array_filter($aReqData);
|
||||
$oCustomerUser = new CustomerUser();
|
||||
if(!$oCustomerUser->updateItem($aReqData)) return $this->error();
|
||||
$oCustomerUser = new CustomerUserModel();
|
||||
if (!$oCustomerUser->updateItem($aReqData)) return $this->error();
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
@ -133,29 +145,39 @@ class CustomerUserController extends CustomerBaseController
|
||||
$oAuthService = new AuthService();
|
||||
$token = $oAuthService->getTokenFromReq();
|
||||
$aUser = $oAuthService->getCurrentUser();
|
||||
$oAuthService->delTokenToUser($aUser['id'],$token);
|
||||
$oAuthService->delTokenToUser($aUser['id'], $token);
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
function register(): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$request = request();
|
||||
$username = $request->input('username');
|
||||
$phone_area = $request->input('phone_area');
|
||||
$phone = $request->input('phone');
|
||||
$password = $request->input('password');
|
||||
$device = $request->input('device');
|
||||
$sVrCode = $request->input('vr_code');
|
||||
|
||||
$oCustomerUser = new CustomerUser();
|
||||
$oUser = $oCustomerUser->findItemByUsername($username,['id']);
|
||||
|
||||
//check vrcode
|
||||
$oVrCodeService = new VrCodeService();
|
||||
$oVrCodeService->setIType(VrCode::TOPIC_REGISTER);
|
||||
$oVrCodeService->setSPhoneArea($phone_area);
|
||||
$oVrCodeService->setSPhone($phone);
|
||||
if (!$oVrCodeService->checkCode($sVrCode)) return $this->error('验证码错误');
|
||||
|
||||
$oCustomerUser = new CustomerUserModel();
|
||||
$oUser = $oCustomerUser->findItemByPhone($phone_area, $phone);
|
||||
|
||||
if ($oUser) {
|
||||
return $this->error('用户名已存在');
|
||||
}
|
||||
|
||||
$oUser = $oCustomerUser->addUser([
|
||||
'username' => $username,
|
||||
'phone_area' => $phone_area,
|
||||
'phone' => $phone,
|
||||
'password' => $password,
|
||||
'nickname' => $username,
|
||||
'nickname' => 'user_' . Tools::generateRandStr(10),
|
||||
]);
|
||||
|
||||
if (!$oUser) {
|
||||
@ -164,10 +186,10 @@ class CustomerUserController extends CustomerBaseController
|
||||
|
||||
//向im注册
|
||||
$oImService = new ImService();
|
||||
if(!$oImService->userUserRegister($oUser->id)) throw new AppException('im register error');
|
||||
if (!$oImService->userUserRegister($oUser->id)) throw new AppException('im register error');
|
||||
|
||||
$oAuthService = new AuthService();
|
||||
$token = $oAuthService->createTokenToUser($oUser->id,$device);
|
||||
$token = $oAuthService->createTokenToUser($oUser->id, $device);
|
||||
|
||||
$data = [
|
||||
'token' => $token,
|
||||
@ -188,64 +210,20 @@ class CustomerUserController extends CustomerBaseController
|
||||
{
|
||||
$request = request();
|
||||
$aReqData = $request->only([
|
||||
'nickname',
|
||||
'username',
|
||||
'email',
|
||||
'phone_area',
|
||||
'phone',
|
||||
]);
|
||||
$aReqData = array_filter($aReqData);
|
||||
if (empty($aReqData)) return $this->error();
|
||||
$oCustomerUser = new CustomerUser();
|
||||
$oUser = $oCustomerUser->findItemByAccount($aReqData,['id']);
|
||||
$oCustomerUser = new CustomerUserModel();
|
||||
$oUser = $oCustomerUser->findItemByAccount($aReqData, ['id']);
|
||||
if ($oUser) {
|
||||
return $this->error('用户已存在');
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws AppException
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
function sendVrcodeCode(): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
//发送短信验证码
|
||||
$request = request();
|
||||
$aReqData = $request->only([
|
||||
'topic',
|
||||
'phone_area',
|
||||
'phone',
|
||||
]);
|
||||
if(!in_array($aReqData['topic'],VrCode::TOPIC)) return $this->error('invalid vrcode type');
|
||||
$oVrCodeService = new VrCodeService();
|
||||
$oVrCodeService->setIType($aReqData['topic']);
|
||||
if($aReqData['topic'] == VrCode::TOPIC_REGISTER){
|
||||
|
||||
$validator = Validator::make($aReqData, [
|
||||
'phone_area' => 'required|alpha_dash:ascii|max:5',
|
||||
'phone' => 'required|numeric|max:15',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
$oCustomerUser = new CustomerUser();
|
||||
$oUser = $oCustomerUser->findItemByPhone($aReqData['phone_area'],$aReqData['phone'],['id']);
|
||||
if ($oUser) {
|
||||
return $this->error('vrcode error');
|
||||
}
|
||||
$oVrCodeService->setSPhoneArea($aReqData['phone_area']);
|
||||
$oVrCodeService->setSPhone($aReqData['phone']);
|
||||
$oVrCodeService->sendCode();
|
||||
return $this->success();
|
||||
}else{
|
||||
$oAuthService = new AuthService();
|
||||
$aUser = $oAuthService->getCurrentUser();
|
||||
if($aUser == null) return $this->error('user not login');
|
||||
$oVrCodeService->setIUid($aUser['id']);
|
||||
$oVrCodeService->sendCode();
|
||||
return $this->success();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
59
app/Http/Controllers/Follow/FollowController.php
Normal file
59
app/Http/Controllers/Follow/FollowController.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Follow;
|
||||
|
||||
use App\Exceptions\ModelException;
|
||||
use App\Http\Controllers\Base\BaseController;
|
||||
use App\Models\Follow\FollowHistoryModel;
|
||||
use App\Models\Follow\FollowModel;
|
||||
use App\Service\AuthService;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class FollowController extends BaseController
|
||||
{
|
||||
|
||||
public array $validateMethodParams = [
|
||||
'addFollow' => [
|
||||
'uid' => 'required|numeric|max:15',
|
||||
],
|
||||
'unFollow' => [
|
||||
'uid' => 'required|numeric|max:15',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ModelException
|
||||
*/
|
||||
function addFollow()
|
||||
{
|
||||
$oAuthService = new AuthService();
|
||||
$aUser = $oAuthService->getCurrentUser();
|
||||
|
||||
$follow_uid = request()->input('uid');
|
||||
if($aUser['id'] == $follow_uid) return $this->error('不能关注自己');
|
||||
|
||||
$oFollowModel = new FollowModel();
|
||||
$aFollow = $oFollowModel->isFollow($aUser['id'], $follow_uid);
|
||||
if($aFollow) return $this->error('已关注');
|
||||
|
||||
$oFollowModel->addFollow($aUser['id'], $follow_uid);
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
function unFollow()
|
||||
{
|
||||
$oAuthService = new AuthService();
|
||||
$aUser = $oAuthService->getCurrentUser();
|
||||
|
||||
$follow_uid = request()->input('uid');
|
||||
$oFollowModel = new FollowModel();
|
||||
$oFollowModel->unFollow($aUser['id'], $follow_uid);
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
}
|
||||
11
app/Http/Controllers/Post/PostController.php
Normal file
11
app/Http/Controllers/Post/PostController.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Post;
|
||||
|
||||
use App\Http\Controllers\Base\BaseController;
|
||||
|
||||
class PostController extends BaseController
|
||||
{
|
||||
|
||||
}
|
||||
86
app/Http/Controllers/Sms/SmsController.php
Normal file
86
app/Http/Controllers/Sms/SmsController.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Sms;
|
||||
|
||||
use App\Const\VrCode;
|
||||
use App\Exceptions\AppException;
|
||||
use App\Http\Controllers\Base\CustomerBaseController;
|
||||
use App\Models\Customer\CustomerUserModel;
|
||||
use App\Service\AuthService;
|
||||
use App\Service\VrCodeService;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class SmsController extends CustomerBaseController
|
||||
{
|
||||
public array $validateMethodParams = [
|
||||
'sendRegCode' => [
|
||||
'phone_area' => 'alpha_dash:ascii|max:5',
|
||||
'phone' => 'numeric|max:15',
|
||||
],
|
||||
'sendVrcodeCode' => [
|
||||
'topic' => 'required|numeric',
|
||||
'phone_area' => 'alpha_dash:ascii|max:5',
|
||||
'phone' => 'numeric|max:15',
|
||||
],
|
||||
];
|
||||
|
||||
// no need login
|
||||
function sendRegCode(): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
//发送短信验证码
|
||||
$request = request();
|
||||
$aReqData = $request->only([
|
||||
'phone_area',
|
||||
'phone',
|
||||
]);
|
||||
|
||||
$oVrCodeService = new VrCodeService();
|
||||
$oVrCodeService->setIType(VrCode::TOPIC_REGISTER);
|
||||
|
||||
$validator = Validator::make($aReqData, [
|
||||
'phone_area' => 'required|alpha_dash:ascii|max:5',
|
||||
'phone' => 'required|numeric|max:15',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
$oCustomerUser = new CustomerUserModel();
|
||||
$oUser = $oCustomerUser->findItemByPhone($aReqData['phone_area'],$aReqData['phone'],['id']);
|
||||
if ($oUser) {
|
||||
return $this->error('vrcode error');
|
||||
}
|
||||
$oVrCodeService->setSPhoneArea($aReqData['phone_area']);
|
||||
$oVrCodeService->setSPhone($aReqData['phone']);
|
||||
$oVrCodeService->sendCode();
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
//must login
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws AppException
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
function sendVrcodeCode(): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
//发送短信验证码
|
||||
$request = request();
|
||||
$aReqData = $request->only([
|
||||
'topic',
|
||||
'phone_area',
|
||||
'phone',
|
||||
]);
|
||||
if(!in_array($aReqData['topic'],VrCode::TOPIC)) return $this->error('invalid vrcode type');
|
||||
$oVrCodeService = new VrCodeService();
|
||||
$oVrCodeService->setIType($aReqData['topic']);
|
||||
|
||||
$oAuthService = new AuthService();
|
||||
$aUser = $oAuthService->getCurrentUser();
|
||||
if($aUser == null) return $this->error('user not login');
|
||||
$oVrCodeService->setIUid($aUser['id']);
|
||||
$oVrCodeService->sendCode();
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
}
|
||||
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Const\Responses;
|
||||
use App\Models\Customer\CustomerUserModel;
|
||||
use App\Service\AuthService;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
@ -14,7 +15,8 @@ class AuthMiddleware
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
@ -28,15 +30,15 @@ class AuthMiddleware
|
||||
'msg'=>'未登录',
|
||||
]);
|
||||
}
|
||||
$oCustomerUser = new \App\Models\Customer\CustomerUser();
|
||||
$oCustomerUser = $oCustomerUser->findUserByUidWithCache($aUserInfo['uid']);
|
||||
if(empty($oCustomerUser)){
|
||||
$oCustomerUser = new CustomerUserModel();
|
||||
$aCustomerUser = $oCustomerUser->findUserByUidWithCache($aUserInfo['uid']);
|
||||
if(empty($aCustomerUser)){
|
||||
return response()->json([
|
||||
'code'=>Responses::CODE_ERROR,
|
||||
'msg'=>'用户不存在',
|
||||
]);
|
||||
}
|
||||
$oAuthService->setCurrentUser($oCustomerUser->toArray());
|
||||
$oAuthService->setCurrentUser($aCustomerUser);
|
||||
|
||||
|
||||
return $next($request);
|
||||
|
||||
Reference in New Issue
Block a user