<commit_before><?php

declare(strict_types=1);

namespace Cortex\Fort\Http\Requests\Frontend;

use Rinvex\Support\Http\Requests\FormRequest;

class AccountSettingsRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Process given request data before validation.
     *
     * @param array $data
     *
     * @return array
     */
    public function process($data)
    {
        $country = $data['country_code'] ?? null;
        $password = $data['password'] ?? null;
        $email = $data['email'] ?? null;
        $phone = $data['phone'] ?? null;
        $user = $this->user();
        $twoFactor = $user->getTwoFactor();

        if (! $password) {
            unset($data['password'], $data['password_confirmation']);
        }

        if ($email !== $user->email) {
            $data['email_verified'] = false;
            $data['email_verified_at'] = null;
        }

        if ($phone !== $user->phone) {
            $data['phone_verified'] = false;
            $data['phone_verified_at'] = null;
        }

        if ($twoFactor && (isset($data['phone_verified']) || $country !== $user->country_code)) {
            array_set($twoFactor, 'phone.enabled', false);
            $data['two_factor'] = $twoFactor;
        }

        return $data;
    }

    /**
     * Configure the validator instance.
     *
     * @param \Illuminate\Validation\Validator $validator
     *
     * @return void
     */
    public function withValidator($validator)
    {
        $validator->after(function ($validator) {
            $data = $this->all();
            $password = $data['password'] ?? null;

            if ($password && $password !== $data['password_confirmation']) {
                $validator->errors()->add('password', trans('validation.confirmed', ['attribute' => 'password']));
            }

            if ($password && mb_strlen($password) < config('rinvex.fort.password_min_chars')) {
                $validator->errors()->add('password', trans('validation.min.string', ['attribute' => 'password', 'min' => config('rinvex.fort.password_min_chars')]));
            }
        });
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $user = $this->user();
        $user->updateRulesUniques();

        return $user->getRules();
    }
}<commit_msg>Move password min chars to core package validation rules<commit_after><?php

declare(strict_types=1);

namespace Cortex\Fort\Http\Requests\Frontend;

use Rinvex\Support\Http\Requests\FormRequest;

class AccountSettingsRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Process given request data before validation.
     *
     * @param array $data
     *
     * @return array
     */
    public function process($data)
    {
        $country = $data['country_code'] ?? null;
        $password = $data['password'] ?? <PASSWORD>;
        $email = $data['email'] ?? null;
        $phone = $data['phone'] ?? null;
        $user = $this->user();
        $twoFactor = $user->getTwoFactor();

        if (! $password) {
            unset($data['password'], $data['password_confirmation']);
        }

        if ($email !== $user->email) {
            $data['email_verified'] = false;
            $data['email_verified_at'] = null;
        }

        if ($phone !== $user->phone) {
            $data['phone_verified'] = false;
            $data['phone_verified_at'] = null;
        }

        if ($twoFactor && (isset($data['phone_verified']) || $country !== $user->country_code)) {
            array_set($twoFactor, 'phone.enabled', false);
            $data['two_factor'] = $twoFactor;
        }

        return $data;
    }

    /**
     * Configure the validator instance.
     *
     * @param \Illuminate\Validation\Validator $validator
     *
     * @return void
     */
    public function withValidator($validator)
    {
        $validator->after(function ($validator) {
            $data = $this->all();
            $password = $data['password'] ?? null;

            if ($password && $password !== $data['password_confirmation']) {
                $validator->errors()->add('password', trans('validation.confirmed', ['attribute' => 'password']));
            }
        });
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $user = $this->user();
        $user->updateRulesUniques();

        return $user->getRules();
    }
}
{'fraction_non_alphanumeric': 0.1583419689119171, 'fraction_numerical': 0.0004145077720207254, 'mean_word_length': 2.1175710594315245, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 34, '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': '2364202', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1359, 'n_words': 284}