<commit_before><?php

namespace App\Http\Controllers\Api\v1\Modules;

use App\Http\Controllers\Controller;
use App\Http\Requests\Modules\Persons\Credentials\UpdateRequest;
use App\Models\Credential;
use App\Models\Person;
use Hash;
use Illuminate\Http\Request;

class CredentialController extends Controller
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(Request $request, Person $person)
    {
        return response()->json($person->credential !== null);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  UpdateRequest $request
     * @param  \App\Models\Person $person
     * @return \Illuminate\Http\Response
     */
    public function store(UpdateRequest $request, Person $person)
    {
        if ($request->has('password')) {
            if ($person->credential === null) {
                $c = new Credential();
            } else {
                $c = $person->credential;
            }
            $c->unguard();
            $c->fill(['password' => <PASSWORD>($request->input('password'))]);
            $person->credential()->save($c);
        }
        if ($request->has('active')) {
            if ($request->input('active')) {
                $person->credential()->restore();
            } else {
                $person->credential()->delete();
            }
        }
        if ($request->has('roles')) {
            $person->syncRoles($request->input('roles', []));
        }
        return response()->json(['status' => 'ok']);
    }
}<commit_msg>fixed: added random api_token on credetial creation.<commit_after><?php

namespace App\Http\Controllers\Api\v1\Modules;

use App\Http\Controllers\Controller;
use App\Http\Requests\Modules\Persons\Credentials\UpdateRequest;
use App\Models\Credential;
use App\Models\Person;
use Hash;
use Illuminate\Http\Request;

class CredentialController extends Controller
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(Request $request, Person $person)
    {
        return response()->json($person->credential !== null);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  UpdateRequest $request
     * @param  \App\Models\Person $person
     * @return \Illuminate\Http\Response
     */
    public function store(UpdateRequest $request, Person $person)
    {
        if ($request->has('password')) {
            if ($person->credential === null) {
                $c = new Credential();
                $c->api_token = str_random(60);
            } else {
                $c = $person->credential;
            }
            $c->unguard();
            $c->fill(['password' => <PASSWORD>($request->input('password'))]);
            $person->credential()->save($c);
        }
        if ($request->has('active')) {
            if ($request->input('active')) {
                $person->credential()->restore();
            } else {
                $person->credential()->delete();
            }
        }
        if ($request->has('roles')) {
            $person->syncRoles($request->input('roles', []));
        }
        return response()->json(['status' => 'ok']);
    }
}
{'fraction_non_alphanumeric': 0.1605546995377504, 'fraction_numerical': 0.0012326656394453005, 'mean_word_length': 2.13926499032882, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 50, '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': '3017690', 'n_tokens_mistral': 899, 'n_tokens_neox': 907, 'n_words': 170}