<commit_before><?php

/*
 * NOTICE OF LICENSE
 *
 * Part of the Rinvex Fort Package.
 *
 * This source file is subject to The MIT License (MIT)
 * that is bundled with this package in the LICENSE file.
 *
 * Package: Rinvex Fort Package
 * License: The MIT License (MIT)
 * Link:    https://rinvex.com
 */

namespace Rinvex\Fort\Http\Controllers\Frontend;

use Illuminate\Http\Request;
use Rinvex\Fort\Contracts\UserRepositoryContract;
use Rinvex\Fort\Http\Controllers\AuthenticatedController;
use Rinvex\Fort\Http\Requests\Frontend\UserSettingsUpdateRequest;

class UserSettingsController extends AuthenticatedController
{
    /**
     * The user repository instance.
     *
     * @var \Rinvex\Fort\Contracts\UserRepositoryContract
     */
    protected $userRepository;

    /**
     * Create a new profile update controller instance.
     *
     * @param \Rinvex\Fort\Contracts\UserRepositoryContract $userRepository
     */
    public function __construct(UserRepositoryContract $userRepository)
    {
        parent::__construct();

        $this->userRepository = $userRepository;
    }

    /**
     * Show the account update form.
     *
     * @return \Illuminate\Http\Response
     */
    public function edit(Request $request)
    {
        $countries = array_map(function ($country) {
            return $country['name'];
        }, countries());
        $twoFactor = $request->user($this->getGuard())->getTwoFactor();

        return view('rinvex/fort::frontend/user.settings', compact('twoFactor', 'countries'));
    }

    /**
     * Process the account update form.
     *
     * @param \Rinvex\Fort\Http\Requests\Frontend\UserSettingsUpdateRequest $request
     *
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
     */
    public function update(UserSettingsUpdateRequest $request)
    {
        $currentUser = $request->user($this->getGuard());
        $data = $request->except(['_token', 'id']);
        $twoFactor = $currentUser->getTwoFactor();

        $emailVerification = $data['email'] != $currentUser->email ? [
            'email_verified'    => false,
            'email_verified_at' => null,
        ] : [];

        $phoneVerification = $data['phone'] != $currentUser->phone ? [
            'phone_verified'    => false,
            'phone_verified_at' => null,
        ] : [];

        $countryVerification = $data['country'] !== $currentUser->country;

        if ($phoneVerification || $countryVerification) {
            array_set($twoFactor, 'phone.enabled', false);
        }

        $this->userRepository->update($request->get('id'), $data + $emailVerification + $phoneVerification + $twoFactor);

        return intend([
            'back' => true,
            'with' => [
                          'rinvex.fort.alert.success' => trans('rinvex/fort::frontend/messages.account.'.(! empty($emailVerification) ? 'reverify' : 'updated')),
                      ] + ($twoFactor !== $currentUser->getTwoFactor() ? ['rinvex.fort.alert.warning' => trans('rinvex/fort::frontend/messages.verification.twofactor.phone.auto_disabled')] : []),
        ]);
    }
}<commit_msg>Fix wrong two factor settings field name<commit_after><?php

/*
 * NOTICE OF LICENSE
 *
 * Part of the Rinvex Fort Package.
 *
 * This source file is subject to The MIT License (MIT)
 * that is bundled with this package in the LICENSE file.
 *
 * Package: Rinvex Fort Package
 * License: The MIT License (MIT)
 * Link:    https://rinvex.com
 */

namespace Rinvex\Fort\Http\Controllers\Frontend;

use Illuminate\Http\Request;
use Rinvex\Fort\Contracts\UserRepositoryContract;
use Rinvex\Fort\Http\Controllers\AuthenticatedController;
use Rinvex\Fort\Http\Requests\Frontend\UserSettingsUpdateRequest;

class UserSettingsController extends AuthenticatedController
{
    /**
     * The user repository instance.
     *
     * @var \Rinvex\Fort\Contracts\UserRepositoryContract
     */
    protected $userRepository;

    /**
     * Create a new profile update controller instance.
     *
     * @param \Rinvex\Fort\Contracts\UserRepositoryContract $userRepository
     */
    public function __construct(UserRepositoryContract $userRepository)
    {
        parent::__construct();

        $this->userRepository = $userRepository;
    }

    /**
     * Show the account update form.
     *
     * @return \Illuminate\Http\Response
     */
    public function edit(Request $request)
    {
        $countries = array_map(function ($country) {
            return $country['name'];
        }, countries());
        $twoFactor = $request->user($this->getGuard())->getTwoFactor();

        return view('rinvex/fort::frontend/user.settings', compact('twoFactor', 'countries'));
    }

    /**
     * Process the account update form.
     *
     * @param \Rinvex\Fort\Http\Requests\Frontend\UserSettingsUpdateRequest $request
     *
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
     */
    public function update(UserSettingsUpdateRequest $request)
    {
        $currentUser = $request->user($this->getGuard());
        $data = $request->except(['_token', 'id']);
        $twoFactor = $currentUser->getTwoFactor();

        $emailVerification = $data['email'] != $currentUser->email ? [
            'email_verified'    => false,
            'email_verified_at' => null,
        ] : [];

        $phoneVerification = $data['phone'] != $currentUser->phone ? [
            'phone_verified'    => false,
            'phone_verified_at' => null,
        ] : [];

        $countryVerification = $data['country'] !== $currentUser->country;

        if ($twoFactor && ($phoneVerification || $countryVerification)) {
            array_set($twoFactor, 'two_factor.phone.enabled', false);
        }

        $this->userRepository->update($request->get('id'), $data + $emailVerification + $phoneVerification + $twoFactor);

        return intend([
            'back' => true,
            'with' => [
                          'rinvex.fort.alert.success' => trans('rinvex/fort::frontend/messages.account.'.(! empty($emailVerification) ? 'reverify' : 'updated')),
                      ] + ($twoFactor !== $currentUser->getTwoFactor() ? ['rinvex.fort.alert.warning' => trans('rinvex/fort::frontend/messages.verification.twofactor.phone.auto_disabled')] : []),
        ]);
    }
}
{'fraction_non_alphanumeric': 0.14046187915216704, 'fraction_numerical': 0.0, 'mean_word_length': 2.7953181272509005, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 2, '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': '11183', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1777, 'n_words': 339}