Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-kuendig committed Jun 2, 2024
2 parents dfe3b57 + 1674856 commit f3c94c7
Show file tree
Hide file tree
Showing 126 changed files with 3,222 additions and 417 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Deploy Docs to GH Pages

on:
push:
branches: [master, develop]
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: pages
cancel-in-progress: false

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Not needed if lastUpdated is not enabled
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Install dependencies
run: npm ci
- name: Build with VitePress
run: npm run docs:build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist

deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
.phpunit.result.cache
.vscode
composer.lock
src/docs/.vitepress/cache
src/docs/.vitepress/dist
docs/.vitepress/cache
docs/.vitepress/dist
nbproject
node_modules
package-lock.json
vendor
vendor
40 changes: 33 additions & 7 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace OFFLINE\Mall;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Facades\View;
use October\Rain\Database\Relations\Relation;
use OFFLINE\Mall\Classes\Registration\BootComponents;
use OFFLINE\Mall\Classes\Registration\BootEvents;
use OFFLINE\Mall\Classes\Registration\BootExtensions;
use OFFLINE\Mall\Classes\Registration\BootMails;
use OFFLINE\Mall\Classes\Registration\BootRelations;
use OFFLINE\Mall\Classes\Registration\BootServiceContainer;
use OFFLINE\Mall\Classes\Registration\BootSettings;
use OFFLINE\Mall\Classes\Registration\BootTwig;
Expand All @@ -16,6 +17,16 @@
use OFFLINE\Mall\Console\IndexCommand;
use OFFLINE\Mall\Console\PurgeCommand;
use OFFLINE\Mall\Console\SeedDataCommand;
use OFFLINE\Mall\Models\CustomField;
use OFFLINE\Mall\Models\CustomFieldOption;
use OFFLINE\Mall\Models\Discount;
use OFFLINE\Mall\Models\ImageSet;
use OFFLINE\Mall\Models\PaymentMethod;
use OFFLINE\Mall\Models\Product;
use OFFLINE\Mall\Models\ServiceOption;
use OFFLINE\Mall\Models\ShippingMethod;
use OFFLINE\Mall\Models\ShippingMethodRate;
use OFFLINE\Mall\Models\Variant;
use System\Classes\PluginBase;

class Plugin extends PluginBase
Expand All @@ -28,7 +39,6 @@ class Plugin extends PluginBase
use BootMails;
use BootValidation;
use BootTwig;
use BootRelations;

/**
* Required plugin dependencies.
Expand All @@ -40,16 +50,32 @@ class Plugin extends PluginBase
'RainLab.Translate'
];

/**
* Required model morph-map relations, must be registered n the constructor
* to make them available when the plugin migrations are run.
* @var array
*/
protected $relations = [
Variant::MORPH_KEY => Variant::class,
Product::MORPH_KEY => Product::class,
ImageSet::MORPH_KEY => ImageSet::class,
Discount::MORPH_KEY => Discount::class,
CustomField::MORPH_KEY => CustomField::class,
PaymentMethod::MORPH_KEY => PaymentMethod::class,
ShippingMethod::MORPH_KEY => ShippingMethod::class,
CustomFieldOption::MORPH_KEY => CustomFieldOption::class,
ShippingMethodRate::MORPH_KEY => ShippingMethodRate::class,
ServiceOption::MORPH_KEY => ServiceOption::class,
];

/**
* Create a new plugin instance.
* @return void
* @param Application $app
*/
public function __construct($app)
public function __construct(Application $app)
{
parent::__construct($app);
// The morph map has to be registered in the constructor so it is available
// when plugin migrations are run.
$this->registerRelations();
Relation::morphMap($this->relations);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,5 @@ If you found a bug or want to request a feature please file a GitHub issue.

### Pull requests

PRs are always welcome! Open them against the `develop` branch. If you plan a time consuming
PRs are always welcome! Open them against the `next` branch. If you plan a time consuming
contribution please open an issue first and describe what changes you have in mind.
1 change: 1 addition & 0 deletions assets/css/nouislider.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/js/nouislider.min.js

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
21 changes: 0 additions & 21 deletions classes/customer/AuthManager.php

This file was deleted.

22 changes: 16 additions & 6 deletions classes/customer/DefaultSignInHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

namespace OFFLINE\Mall\Classes\Customer;

use Auth;
use Event;
use Exception;
use Flash;
use October\Rain\Auth\AuthException;
use October\Rain\Exception\ValidationException;
use OFFLINE\Mall\Classes\User\Settings;
use OFFLINE\Mall\Models\Cart;
use OFFLINE\Mall\Models\Customer;
use OFFLINE\Mall\Models\User;
use Auth;
use OFFLINE\Mall\Models\Wishlist;
use Redirect;
use RainLab\User\Models\Setting;
use RainLab\User\Models\User;
use Validator;

class DefaultSignInHandler implements SignInHandler
Expand Down Expand Up @@ -52,9 +53,18 @@ protected function login(array $data)
Event::fire('rainlab.user.beforeAuthenticate', [$this, $credentials]);
Event::fire('mall.customer.beforeAuthenticate', [$this, $credentials]);

$user = Auth::authenticate($credentials, true);
// RainLab.User 3.0 compatibility
if (class_exists(\RainLab\User\Models\Setting::class)) {
if (Auth::attempt(['email' => $credentials['login'], 'password' => $credentials['password']], true)) {
$user = Auth::getUser();
} else {
throw new AuthException('rainlab.user::lang.account.invalid_login');
}
} else {
$user = Auth::authenticate($credentials, true);
}

if ($user->isBanned()) {
if (method_exists($user, 'isBanned') && $user->isBanned()) {
Auth::logout();
throw new AuthException('rainlab.user::lang.account.banned');
}
Expand Down Expand Up @@ -88,7 +98,7 @@ protected function login(array $data)
*/
protected function validate(array $data)
{
$minPasswordLength = \RainLab\User\Models\User::getMinPasswordLength();
$minPasswordLength = Settings::getMinPasswordLength();
$rules = [
'login' => 'required|email|between:6,255',
'password' => sprintf('required|min:%d|max:255', $minPasswordLength),
Expand Down
22 changes: 17 additions & 5 deletions classes/customer/DefaultSignUpHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
use Event;
use Illuminate\Support\Facades\Validator;
use October\Rain\Exception\ValidationException;
use OFFLINE\Mall\Classes\User\Settings;
use OFFLINE\Mall\Models\Address;
use OFFLINE\Mall\Models\Cart;
use OFFLINE\Mall\Models\Customer;
use OFFLINE\Mall\Models\GeneralSettings;
use OFFLINE\Mall\Models\User;
use OFFLINE\Mall\Models\Wishlist;
use RainLab\User\Facades\Auth;
use OFFLINE\Mall\Classes\User\Auth;
use RainLab\User\Models\UserGroup;
use RainLab\User\Models\User;
use System\Classes\PluginManager;

class DefaultSignUpHandler implements SignUpHandler
Expand All @@ -29,8 +30,9 @@ public function handle(array $data, bool $asGuest = false): ?User

/**
* @throws ValidationException
* @return User
*/
protected function signUp(array $data): ?User
protected function signUp(array $data)
{
if ($this->asGuest) {
$data['password'] = $data['password_repeat'] = str_random(30);
Expand Down Expand Up @@ -121,13 +123,23 @@ protected function validate(array $data)
}
}

protected function createUser($data, $requiresConfirmation): User
/**
* @param $data
* @param $requiresConfirmation
*/
protected function createUser($data, $requiresConfirmation)
{
$data['name'] = $data['firstname'];
$data['surname'] = $data['lastname'];
$data['email'] = $data['email'];
$data['password'] = $data['password'];
$data['password_confirmation'] = $data['password_repeat'];

// RainLab.User 3.0
if (class_exists(\RainLab\User\Models\Setting::class)) {
$data['first_name'] = $data['firstname'];
$data['last_name'] = $data['lastname'];
}

$user = Auth::register($data, ! $requiresConfirmation);
if ($this->asGuest && $user && $group = UserGroup::getGuestGroup()) {
Expand Down Expand Up @@ -170,7 +182,7 @@ protected function renameExistingGuestAccounts(array $data, $user)

public static function rules($forSignup = true): array
{
$minPasswordLength = \RainLab\User\Models\User::getMinPasswordLength();
$minPasswordLength = Settings::getMinPasswordLength();
$rules = [
'firstname' => 'required',
'lastname' => 'required',
Expand Down
2 changes: 1 addition & 1 deletion classes/customer/SignInHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace OFFLINE\Mall\Classes\Customer;

use OFFLINE\Mall\Models\User;
use RainLab\User\Models\User;

interface SignInHandler
{
Expand Down
2 changes: 1 addition & 1 deletion classes/customer/SignUpHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace OFFLINE\Mall\Classes\Customer;

use OFFLINE\Mall\Models\User;
use RainLab\User\Models\User;

interface SignUpHandler
{
Expand Down
48 changes: 27 additions & 21 deletions classes/downloads/VirtualProductFileDownload.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
namespace OFFLINE\Mall\Classes\Downloads;

use Auth;
use Cms\Classes\Controller;
use Cms\Classes\Page;
use Flash;
use OFFLINE\Mall\Models\Product;
use OFFLINE\Mall\Models\ProductFile;
use Request;
use Session;
use Illuminate\Support\Facades\Log;
Expand All @@ -14,7 +17,7 @@

class VirtualProductFileDownload
{
public function handle(string $key, ?string $idx = null)
public function handle(string $key)
{
$grant = $this->findGrant($key);
if ( ! $grant) {
Expand All @@ -40,30 +43,33 @@ public function handle(string $key, ?string $idx = null)
return response($this->trans('expired'), 403);
}

// Get File
if (!empty($idx)) {
$file = $product->files->where('id', $idx)->first();
} else {
$file = $grant->file ? $grant->file : $product->latest_file;
// Increase the download counter, then send the file as a response.
$grant->increment('download_count');
if ($product->latest_file) {
$product->latest_file->increment('download_count');
}

// If no file is around, return and log an error. The site admin needs to fix this!
if (empty($file)) {
Log::error(
'[OFFLINE.Mall] A virtual product without a file attachment has been purchased. You need to fix this!',
['grant' => $grant, 'product' => $product, 'user' => Auth::getUser()]
);
return response($this->trans('not_found'), 500);
// If the grant has a file attached, send it.
if ($grant->file) {
$filename = sprintf('%s.%s', $grant->display_name, $grant->file->getExtension());

return response()->download($grant->file->getLocalPath(), $filename);
}

// Increase the download counter, then send the file as a response.
$grant->increment('download_count');
$file->increment('download_count');
// If no grant specific file is available, return the product file.
if ($product->latest_file && $product->latest_file->file) {
$filename = sprintf('%s.%s', $grant->display_name, $product->latest_file->file->getExtension());

return response()->download($product->latest_file->file->getLocalPath(), $filename);
}

// If no file is around, return and log an error. The site admin needs to fix this!
Log::error(
'[OFFLINE.Mall] A virtual product without a file attachment has been purchased. You need to fix this!',
['grant' => $grant, 'product' => $product, 'user' => Auth::getUser()]
);

// Download File
$filename = sprintf('%s.%s', $file->display_name, $file->file->getExtension());
$filename = urlencode($filename);
return response()->download($file->file->getLocalPath(), $filename);
return response($this->trans('not_found'), 500);
}

/**
Expand Down Expand Up @@ -91,7 +97,7 @@ protected function redirectToLogin()
Session::put('mall.login.redirect', Request::url());
Flash::warning(trans('offline.mall::frontend.session.login_required'));

$url = Page::url(GeneralSettings::get('account_page'));
$url = (new Controller)->pageUrl(GeneralSettings::get('account_page'));

return Redirect::to($url);
}
Expand Down
Loading

0 comments on commit f3c94c7

Please sign in to comment.