11 use Symfony\Component\HttpFoundation\Request;
13 define(
"TITLE_USER_ADD", _(
"Add A User"));
17 const NAME =
"user_add";
22 function __construct()
24 parent::__construct(self::NAME, array(
25 self::TITLE => TITLE_USER_ADD,
26 self::MENU_LIST =>
'Admin::Users::Add',
27 self::REQUIRES_LOGIN =>
true,
38 public function add(Request $request)
41 $User = str_replace(
"'",
"''", $request->get(
'username'));
43 $Pass = $request->get(
'pass1');
44 $Pass2 = $request->get(
'pass2');
45 $options = array(
'cost' => 10);
46 $Hash = password_hash($Pass, PASSWORD_DEFAULT, $options);
47 $Desc = str_replace(
"'",
"''", $request->get(
'description'));
48 $Perm = $request->get(
'permission');
49 $Folder = $request->get(
'folder');
50 $Email_notify = $request->get(
'enote');
51 $Email = str_replace(
"'",
"''", $request->get(
'email'));
52 $Upload_visibility = $request->get(
'public');
53 $agentList = is_null($request->get(
'user_agent_list')) ?
userAgents() : $request->get(
'user_agent_list');
54 $default_bucketpool_fk = $request->get(
'default_bucketpool_fk');
58 $text = _(
"Username must be specified. Not added.");
62 if (strlen($User) > 64) {
63 $text = _(
"Username exceed 64 characters. Not added.");
67 if ($Pass != $Pass2) {
68 $text = _(
"Passwords did not match. Not added.");
74 $result = preg_match(
'/^' . $policyRegex .
'$/m', $Pass);
76 $text = _(
"Password does not match policy.");
82 if (! empty($Email) && ! filter_var($Email, FILTER_VALIDATE_EMAIL)) {
83 $text = _(
"Invalid email address. Not added.");
89 if (! empty($Email)) {
90 $email_count = $this->
dbManager->getSingleRow(
91 "SELECT COUNT(*) as count FROM users WHERE user_email = $1 LIMIT 1;",
92 array($Email))[
"count"];
94 if ($email_count > 0) {
95 $text = _(
"Email address already exists. Not added.");
100 $row = $this->
dbManager->getSingleRow(
"SELECT * FROM users WHERE LOWER(user_name) = LOWER($1) LIMIT 1;",
101 array($User), $stmt = __METHOD__ .
".getUserIfExisting");
102 if (! empty($row[
'user_name'])) {
103 $text = _(
"User already exists. Not added.");
110 if (empty($Email_notify) || empty($Email)) {
114 if (empty($Upload_visibility)) {
115 $Upload_visibility =
null;
118 $ErrMsg =
add_user($User, $Desc, $Hash, $Perm, $Email, $Email_notify, $Upload_visibility,
119 $agentList, $Folder, $default_bucketpool_fk);
128 $User = $request->get(
'username');
129 if (! empty($User)) {
130 $rc = $this->
add($request);
134 $vars[
'message'] =
"$text $User $text1.";
136 $vars[
'message'] = $rc;
140 $vars[
'userName'] = htmlentities($request->get(
'username'), ENT_QUOTES);
141 $vars[
'userDescription'] = htmlentities($request->get(
'description'), ENT_QUOTES);
142 $vars[
'userEmail'] = htmlentities($request->get(
'email'), ENT_QUOTES);
143 $vars[
'accessLevel'] = [
151 $vars[
'passOptional'] =
" (Optional)";
153 $vars[
'passOptional'] =
"";
156 if ($vars[
'passwordPolicy'] ==
"No policy defined.") {
157 $vars[
'passwordPolicy'] =
"";
159 $vars[
'agentSelector'] =
AgentCheckBoxMake(-1, array(
"agent_unpack",
"agent_adj2nest",
"wget_agent"));
161 $default_bucketpool_fk = 0;
163 $vars[
'formName'] =
"user_add";
166 $scripts =
"<script src='scripts/togglePasswords.js' type='text/javascript'></script>";
167 $vars[
'scripts'] = $scripts;
168 return $this->
render(
'user_add.html.twig', $this->mergeWithDefault($vars));
Contains the constants and helpers for authentication of user.
render($templateName, $vars=null, $headers=null)
add(Request $request)
Add a user.
userAgents($agents=null)
Read the UI form and format the user selected agents into a comma separated list.
AgentCheckBoxMake($upload_pk, $SkipAgents=array(), $specified_username="")
Generate a checkbox list of available agents.
generate_password_policy_string()
generate_password_policy()
SelectBucketPool($selected, $active='Y')
Return a select list containing all the active bucketpool's.
FolderListOption($ParentFolder, $Depth, $IncludeTop=1, $SelectId=-1, $linkParent=false, $OldParent=0)
Create the folder tree, using OPTION tags.
add_user($User, $Desc, $Hash, $Perm, $Email, $Email_notify, $Upload_visibility, $agentList, $Folder, $default_bucketpool_fk='')
Add a user.
char * trim(char *ptext)
Trimming whitespace.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
#define PLUGIN_DB_NONE
Plugin requires no DB permission.
#define PERM_ADMIN
Administrator.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
fo_dbManager * dbManager
fo_dbManager object