8000 Dev by Qsnh · Pull Request #96 · Qsnh/meedu · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Dev #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Feb 11, 2020
Merged

Dev #96

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number< EDBE /th> Diff line number Diff line change
@@ -1,4 +1,4 @@
<p align="center"><img src="public/images/meedu.jpg"/></p>
<p align="center"><img src="public/images/meedu.png"/></p>

<p align="center">
<a href="https://github.styleci.io/repos/127536154"><img src="https://github.styleci.io/repos/127536154/shield?branch=master" alt="StyleCI"></a>
Expand Down
56 changes: 0 additions & 56 deletions app/Console/Commands/AutoGenerateCommand.php

This file was deleted.

12 changes: 8 additions & 4 deletions app/Console/Commands/SwitchTemplateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ public function __construct()
public function handle()
{
$template = $this->argument('template');
$path = base_path('templates/' . $template);
if (!is_dir($path)) {
$this->warn('模板不存在');
return;
if ($template == 'default') {
$path = resource_path('views');
} else {
$path = base_path('templates/' . $template);
if (!is_dir($path)) {
$this->warn('模板不存在');
return;
}
}
$config = [];
$config['meedu.system.theme.use'] = $template;
Expand Down
4 changes: 0 additions & 4 deletions app/Console/Commands/TemplatePublicLinkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ public function __construct()
public function handle()
{
$template = $this->argument('template');
if (!$template) {
$this->error('请指定template');
return;
}

$path = base_path('templates/' . $template . '/public');
if (!is_dir($path)) {
Expand Down
2 changes: 2 additions & 0 deletions app/Constant/ApiV2Constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class ApiV2Constant
const MOBILE_OR_PASSWORD_ERROR = 'mobile not exists or password error';
const MOBILE_CODE_ERROR = 'mobile code error';

const MEMBER_HAS_LOCKED = 'current user was locked,please contact administrator';

const VIDEO_NO_AUTH = 'please buy this video before see';

const SMS_CODE_EXPIRE = 60;
Expand Down
8 changes: 8 additions & 0 deletions app/Constant/FrontendConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@ class FrontendConstant

const INVITE_BALANCE_WITHDRAW_STATUS_SUCCESS = 1;
const INVITE_BALANCE_WITHDRAW_STATUS_FAILURE = 2;

const LOGIN_CALLBACK_URL_KEY = 'login_callback_url';

const LOGIN_REFERER_BLACKLIST = [
'/register',
'/password/reset',
''
];
}
7 changes: 7 additions & 0 deletions app/Http/Controllers/Api/V2/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Illuminate\Support\Str;
use App\Constant\ApiV2Constant;
use App\Constant\FrontendConstant;
use App\Exceptions\ApiV2Exception;
use Illuminate\Support\Facades\Auth;
use App\Services\Member\Services\UserService;
Expand Down Expand Up @@ -70,6 +71,9 @@ public function passwordLogin(PasswordLoginRequest $request)
if (!$user) {
return $this->error(__(ApiV2Constant::MOBILE_OR_PASSWORD_ERROR));
}
if ($user['is_lock'] == FrontendConstant::YES) {
return $this->error(__(ApiV2Constant::MEMBER_HAS_LOCKED));
}
$token = Auth::guard($this->guard)->tokenById($user['id']);

return $this->data(compact('token'));
Expand Down Expand Up @@ -109,6 +113,9 @@ public function mobileLogin(MobileLoginRequest $request)
// 直接注册
$user = $this->userService->createWithMobile($mobile, Str::random(6), Str::random(3) . '_' . $mobile);
}
if ($user['is_lock'] == FrontendConstant::YES) {
return $this->error(__(ApiV2Constant::MEMBER_HAS_LOCKED));
}
$token = Auth::guard($this->guard)->tokenById($user['id']);

return $this->data(compact('token'));
Expand Down
9 changes: 8 additions & 1 deletion app/Http/Controllers/Backend/Api/V1/CourseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
use App\Services\Course\Models\Video;
use App\Services\Course\Models\Course;
use App\Http\Requests\Backend\CourseRequest;
use App\Services\Course\Models\CourseCategory;

class CourseController extends BaseController
{
public function index(Request $request)
{
$keywords = $request->input('keywords', '');
$courses = Course::when($keywords, function ($query) use ($keywords) {
return $query->where('title', 'like', '%'.$keywords.'%');
return $query->where('title', 'like', '%' . $keywords . '%');
})
->orderByDesc('created_at')
->paginate(12);
Expand All @@ -33,6 +34,12 @@ public function index(Request $request)
return $this->successData($courses);
}

public function create()
{
$categories = CourseCategory::show()->get();
return $this->successData(compact('categories'));
}

public function store(CourseRequest $request, Course $course)
{
$course->fill($request->filldata())->save();
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Controllers/Frontend/CourseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public function show($id, $slug)
public function showBuyPage($id)
{
$course = $this->courseService->find($id);
if ($this->userService->hasCourse(Auth::id(), $id)) {
flash(__('You have already purchased this course'), 'success');
return back();
}
$title = __('buy course', ['course' => $course['title']]);

return v('frontend.course.buy', compact('course', 'title'));
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Frontend/ForgotPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ForgotPasswordController extends Controller
public function __construct(UserServiceInterface $userService)
{
$this->userService = $userService;
$this->middleware('guest');
}

public function showPage()
Expand Down
16 changes: 15 additions & 1 deletion app/Http/Controllers/Frontend/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@
namespace App\Http\Controllers\Frontend;

use App\Events\AdFromEvent;
use App\Services\Other\Services\LinkService;
use App\Services\Base\Services\ConfigService;
use App\Services\Other\Interfaces\LinkServiceInterface;
use App\Services\Base\Interfaces\ConfigServiceInterface;

class IndexController extends FrontendController
{
/**
* @var LinkService
*/
protected $linkService;
/**
* @var ConfigService
*/
protected $configService;

public function __construct(
LinkServiceInterface $linkService,
ConfigService $configService
ConfigServiceInterface $configService
) {
$this->linkService = $linkService;
$this->configService = $configService;
Expand All @@ -47,4 +55,10 @@ public function index()
compact('title', 'keywords', 'description', 'links')
);
}

public function userProtocol()
{
$protocol = $this->configService->getMemberProtocol();
return v('frontend.index.user_protocol', compact('protocol'));
}
}
44 changes: 34 additions & 10 deletions app/Http/Controllers/Frontend/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Socialite;
use App\Events\UserLoginEvent;
use App\Constant\FrontendConstant;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\BaseController;
use App\Services\Member\Services\UserService;
Expand All @@ -39,11 +40,7 @@ public function __construct(UserServiceInterface $userService, SocialiteServiceI
$this->userService = $userService;
$this->socialiteService = $socialiteService;
$this->middleware('guest')->except(
'logout',
'showLoginPage',
'passwordLoginHandler',
'socialLogin',
'socialiteLoginCallback'
'logout'
);
}

Expand All @@ -52,6 +49,14 @@ public function __construct(UserServiceInterface $userService, SocialiteServiceI
*/
public function showLoginPage()
{
$previousUrl = request()->server('HTTP_REFERER') ?: url('/');
foreach (FrontendConstant::LOGIN_REFERER_BLACKLIST as $item) {
if (preg_match("#{$item}#ius", $previousUrl)) {
$previousUrl = url('/');
break;
}
}
session([FrontendConstant::LOGIN_CALLBACK_URL_KEY => $previousUrl]);
return v('frontend.auth.login');
}

Expand All @@ -70,11 +75,15 @@ public function passwordLoginHandler(LoginPasswordRequest $request)
flash(__('mobile not exists or password error'), 'error');
return back();
}
if ($user['is_lock'] == FrontendConstant::YES) {
flash(__('current user was locked,please contact administrator'));
return back();
}
Auth::loginUsingId($user['id'], $request->has('remember'));

event(new UserLoginEvent($user['id']));

return redirect(url('/'));
return redirect($this->redirectTo());
}

/**
Expand Down Expand Up @@ -102,12 +111,17 @@ public function socialiteLoginCallback($app)
return redirect('member');
}
if ($bindUserId = $this->socialiteService->getBindUserId($app, $appId)) {
Auth::loginUsingId($bindUserId);
return redirect(url('/'));
$userId = $bindUserId;
} else {
$userId = $this->socialiteService->bindAppWithNewUser($app, $appId, (array)$user);
}
$user = $this->userService->find($userId);
if ($user['is_lock'] == FrontendConstant::YES) {
flash(__('current user was locked,please contact administrator'));
return back();
}
$userId = $this->socialiteService->bindAppWithNewUser($app, $appId, (array)$user);
Auth::loginUsingId($userId, true);
return redirect(url('/'));
return redirect($this->redirectTo());
}

/**
Expand All @@ -119,4 +133,14 @@ public function logout()
flash(__('success'), 'success');
return redirect(url('/'));
}

/**
* @return \Illuminate\Contracts\Routing\UrlGenerator|\Illuminate\Session\SessionManager|\Illuminate\Session\Store|mixed|string
*/
protected function redirectTo()
{
$callbackUrl = session()->has(FrontendConstant::LOGIN_CALLBACK_URL_KEY) ?
session(FrontendConstant::LOGIN_CALLBACK_URL_KEY) : url('/');
return $callbackUrl;
}
}
1 change: 1 addition & 0 deletions app/Http/Controllers/Frontend/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class RegisterController extends BaseController
public function __construct(UserServiceInterface $userService)
{
$this->userService = $userService;
$this->middleware('guest');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/Frontend/VideoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,13 @@ public function show($courseId, $id, $slug)
public function showBuyPage($id)
{
$video = $this->videoService->find($id);
if ($this->userService->hasVideo(Auth::id(), $video['id'])) {
flash(__('You have already purchased this course'), 'success');
return back();
}
$title = __('buy video', ['video' => $video['title']]);

return v('frontend.video.buy', compact('video', compact('title')));
return v('frontend.video.buy', compact('video', 'title'));
}

public function buyHandler(Request $request, $id)
Expand Down
Loading
0