<commit_before><?php
/**
 * Users - A Controller for managing the Users Authentication.
 *
 * @author <NAME> - <EMAIL>
 * @version 3.0
 */

namespace Modules\Users\Http\Controllers\Admin;

use Nova\Database\ORM\ModelNotFoundException;
use Nova\Support\Facades\Auth;
use Nova\Support\Facades\Hash;
use Nova\Support\Facades\Input;
use Nova\Support\Facades\File;
use Nova\Support\Facades\Language;
use Nova\Support\Facades\Redirect;
use Nova\Support\Facades\Response;
use Nova\Support\Facades\Session;
use Nova\Support\Facades\Validator;
use Nova\Support\Facades\View;

use App\Core\BackendController;

use Modules\Users\Models\User;
use Modules\Users\Models\Role;

use Carbon\Carbon;


class Users extends BackendController
{

    public function __construct()
    {
        parent::__construct();

        //
        $this->middleware('admin');
    }

    protected function validator(array $data, $id = null)
    {
        if (! is_null($id)) {
            $ignore = ',' .intval($id);

            $required = 'sometimes|required';
        } else {
            $ignore = '';

            $required = 'required';
        }

        // The Validation rules.
        $rules = array(
            'username'              => 'required|min:4|max:100|alpha_dash|unique:users,username' .$ignore,
            'role'                  => 'required|numeric|exists:roles,id',
            'first_name'            => 'required|min:4|max:100|valid_name',
            'last_name'             => 'required|min:4|max:100|valid_name',
            'location'              => 'min:2|max:100|valid_location',
            'password'              => $required .'|<PASSWORD>|<PASSWORD>',
            'password_confirmation' => $required .'|same:password',
            'email'                 => 'required|min:5|max:100|email|unique:users,email' .$ignore,
            'image'                 => 'max:1024|mimes:png,jpeg,jpg,gif',
        );

        $messages = array(
            'valid_name'      => __d('users', 'The :attribute field is not a valid name.'),
            'valid_location'  => __d('users', 'The :attribute field is not a valid location.'),
            'strong_password' => __d('users', 'The :attribute field is not strong enough.'),
        );

        $attributes = array(
            'username'              => __d('users', 'Username'),
            'role'                  => __d('users', 'Role'),
            'first_name'            => __d('users', 'First Name'),
            'last_name'             => __d('users', 'Last Name'),
            'location'              => __d('users', 'Location'),
            'password'              => __d('<PASSWORD>', 'Password'),
            'password_confirmation' => __d('<PASSWORD>', '<PASSWORD>'),
            'email'                 => __d('users', 'E-mail'),
            'image'                 => __d('users', 'Profile Picture'),
        );

        // Add the custom Validation Rule commands.
        Validator::extend('valid_name', function($attribute, $value, $parameters)
        {
            $pattern = '~^(?:[\p{L}\p{Mn}\p{Pd}\'\x{2019}]+(?:$|\s+)){1,}$~u';

            return (preg_match($pattern, $value) === 1);
        });

        Validator::extend('valid_location', function($attribute, $value, $parameters)
        {
            $pattern = '~^(?:[\p{L}\p{Mn}\p{Pd}\',\x{2019}]+(?:$|\s+)){1,}$~u';

            return (preg_match($pattern, $value) === 1);
        });

        Validator::extend('strong_password', function($attribute, $value, $parameters)
        {
            $pattern = "/(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/";

            return (preg_match($pattern, $value) === 1);
        });

        return Validator::make($data, $rules, $messages, $attributes);
    }

    public function data()
    {
        $columns = array(
            array('data' => 'userid',   'field' => 'id'),
            array('data' => 'username', 'field' => 'username'),
            array('data' => 'name',     'field' => 'first_name'),
            array('data' => 'surname',  'field' => 'last_name'),
            array('data' => 'email',    'field' => 'email'),

            array('data' => 'role', 'field' => 'role_id', 'uses' => function($user)
            {
                return $user->role->name;
            }),

            array('data' => 'date', 'uses' => function($user)
            {
                $format = __d('users', '%d %b %Y, %H:%M');

                return $user->created_at->formatLocalized($format);
            }),

            array('data' => 'actions', 'uses' => function($user)
            {
                return View::make('Partials/UsersTableActions', array(), 'Users')<commit_msg>Improve the Users SSP<commit_after><?php
/**
 * Users - A Controller for managing the Users Authentication.
 *
 * @author <NAME> - <EMAIL>
 * @version 3.0
 */

namespace Modules\Users\Http\Controllers\Admin;

use Nova\Database\ORM\ModelNotFoundException;
use Nova\Support\Facades\Auth;
use Nova\Support\Facades\Hash;
use Nova\Support\Facades\Input;
use Nova\Support\Facades\File;
use Nova\Support\Facades\Language;
use Nova\Support\Facades\Redirect;
use Nova\Support\Facades\Response;
use Nova\Support\Facades\Session;
use Nova\Support\Facades\Validator;
use Nova\Support\Facades\View;

use App\Core\BackendController;

use Modules\Users\Models\User;
use Modules\Users\Models\Role;

use Carbon\Carbon;


class Users extends BackendController
{

    public function __construct()
    {
        parent::__construct();

        //
        $this->middleware('admin');
    }

    protected function validator(array $data, $id = null)
    {
        if (! is_null($id)) {
            $ignore = ',' .intval($id);

            $required = 'sometimes|required';
        } else {
            $ignore = '';

            $required = 'required';
        }

        // The Validation rules.
        $rules = array(
            'username'              => 'required|min:4|max:100|alpha_dash|unique:users,username' .$ignore,
            'role'                  => 'required|numeric|exists:roles,id',
            'first_name'            => 'required|min:4|max:100|valid_name',
            'last_name'             => 'required|min:4|max:100|valid_name',
            'location'              => 'min:2|max:100|valid_location',
            'password'              => $<PASSWORD> .'|<PASSWORD>',
            'password_confirmation' => $<PASSWORD> .'|same:password',
            'email'                 => 'required|min:5|max:100|email|unique:users,email' .$ignore,
            'image'                 => 'max:1024|mimes:png,jpeg,jpg,gif',
        );

        $messages = array(
            'valid_name'      => __d('users', 'The :attribute field is not a valid name.'),
            'valid_location'  => __d('users', 'The :attribute field is not a valid location.'),
            'strong_password' => __d('users', 'The :attribute field is not strong enough.'),
        );

        $attributes = array(
            'username'              => __d('users', 'Username'),
            'role'                  => __d('users', 'Role'),
            'first_name'            => __d('users', 'First Name'),
            'last_name'             => __d('users', 'Last Name'),
            'location'              => __d('users', 'Location'),
            'password'              => __d('users', 'Password'),
            'password_confirmation' => __d('users', '<PASSWORD>'),
            'email'                 => __d('users', 'E-mail'),
            'image'                 => __d('users', 'Profile Picture'),
        );

        // Add the custom Validation Rule commands.
        Validator::extend('valid_name', function($attribute, $value, $parameters)
        {
            $pattern = '~^(?:[\p{L}\p{Mn}\p{Pd}\'\x{2019}]+(?:$|\s+)){1,}$~u';

            return (preg_match($pattern, $value) === 1);
        });

        Validator::extend('valid_location', function($attribute, $value, $parameters)
        {
            $pattern = '~^(?:[\p{L}\p{Mn}\p{Pd}\',\x{2019}]+(?:$|\s+)){1,}$~u';

            return (preg_match($pattern, $value) === 1);
        });

        Validator::extend('strong_password', function($attribute, $value, $parameters)
        {
            $pattern = "/(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/";

            return (preg_match($pattern, $value) === 1);
        });

        return Validator::make($data, $rules, $messages, $attributes);
    }

    public function data()
    {
        $columns = array(
            array('data' => 'userid',   'field' => 'id'),
            array('data' => 'username', 'field' => 'username'),
            array('data' => 'name',     'field' => 'first_name'),
            array('data' => 'surname',  'field' => 'last_name'),
            array('data' => 'email',    'field' => 'email'),

            array('data' => 'role', 'field' => 'role_id', 'uses' => function($user)
            {
                return $user->role->name;
            }),

            array('data' => 'date', 'field' => 'created_at', 'uses' => function($user)
            {
                $format = __d('users', '%d %b %Y, %H:%M');

                return $user->created_at->formatLocalized($format);
            }),

            array('data' => 'actions', 'uses' => function($user)
            {
                return View::make('Partials/UsersTableActions', array(), 'Users')
{'fraction_non_alphanumeric': 0.18852633823843037, 'fraction_numerical': 0.008530603540200469, 'mean_word_length': 2.0362576885723533, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 103, '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': '3862182', 'n_tokens_mistral': 2889, 'n_tokens_neox': 2762, 'n_words': 514}