<commit_before><?php

namespace App\Http\Controllers;

use App\Models\Auth\User\User;
use App\Models\NetLicensing\NlicValidation;
use Illuminate\Http\Request;

class MembershipController extends Controller
{
    public function __construct()
    {
        $this->middleware('admin', ['except' => ['index', 'failed', 'beforeSuccessRedirect']]);
    }

    public function index(Request $request)
    {
        return view('membership')->with([
            'nlic_shop_token' => nlic_shop_token($request->user(), route('netlisensing.membership.before.redirect', ['dest' => url()->current()])),
            'nlic_validation' => collect($request->user()->nlicValidation->getValidationResult(config('netlicensing.membership.product_module_number'))),
            'user' => $request->user()
        ]);
    }

    public function failed(Request $request)
    {
        return view('membership')->with([
            'nlic_shop_token' => nlic_shop_token($request->user(), route('netlisensing.membership.before.redirect', ['dest' => $request->get('dest')])),
            'nlic_validation' => collect($request->user()->nlicValidation->getValidationResult(config('netlicensing.membership.product_module_number'))),
            'user' => $request->user()
        ]);
    }

    public function beforeSuccessRedirect(Request $request)
    {
        /** @var  $user User */
        $user = $request->user();

        //refresh nl validation
        if ($user->nlicValidation) $user->nlicValidation->delete();

        nlic_validate($request->user());

        return redirect($request->get('dest'));
    }
}<commit_msg>Add user subscription plan feature #10 v1.1.2<commit_after><?php

namespace App\Http\Controllers;

use App\Models\Auth\User\User;
use App\Models\NetLicensing\NlicValidation;
use Carbon\Carbon;
use Illuminate\Http\Request;

class MembershipController extends Controller
{
    public function __construct()
    {
        $this->middleware('admin', ['except' => ['index', 'failed', 'beforeSuccessRedirect']]);
    }

    public function index(Request $request)
    {
        return view('membership')->with([
            'nlic_shop_token' => nlic_shop_token($request->user(), route('netlisensing.membership.before.redirect', ['dest' => url()->current()])),
            'nlic_validation' => collect($request->user()->nlicValidation->getValidationResult(config('netlicensing.membership.product_module_number'))),
            'user' => $request->user()
        ]);
    }

    public function failed(Request $request)
    {
        return view('membership')->with([
            'nlic_shop_token' => nlic_shop_token($request->user(), route('netlisensing.membership.before.redirect', ['dest' => $request->get('dest')])),
            'nlic_validation' => collect($request->user()->nlicValidation->getValidationResult(config('netlicensing.membership.product_module_number'))),
            'user' => $request->user()
        ]);
    }

    public function beforeSuccessRedirect(Request $request)
    {
        /** @var  $user User */
        $user = $request->user();

        $user->nlicValidation->ttl = Carbon::now();
        $user->nlicValidation->save();

        return redirect($request->get('dest'));
    }
}
{'fraction_non_alphanumeric': 0.16801745635910226, 'fraction_numerical': 0.0015586034912718205, 'mean_word_length': 3.519718309859155, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '404570', 'n_tokens_mistral': 913, 'n_tokens_neox': 900, 'n_words': 142}