@@ 540-566 (lines=27) @@ | ||
537 | * |
|
538 | * @internal param $group (array) The groups to create the user in |
|
539 | */ |
|
540 | public function createUser($username, $password, $createdb, $createuser, $expiry, $groups) |
|
541 | { |
|
542 | $enc = $this->_encryptPassword($username, $password); |
|
543 | $this->fieldClean($username); |
|
544 | $this->clean($enc); |
|
545 | $this->clean($expiry); |
|
546 | $this->fieldArrayClean($groups); |
|
547 | ||
548 | $sql = "CREATE USER \"{$username}\""; |
|
549 | if ($password != '') { |
|
550 | $sql .= " WITH ENCRYPTED PASSWORD '{$enc}'"; |
|
551 | } |
|
552 | ||
553 | $sql .= $createdb ? ' CREATEDB' : ' NOCREATEDB'; |
|
554 | $sql .= $createuser ? ' CREATEUSER' : ' NOCREATEUSER'; |
|
555 | if (is_array($groups) && sizeof($groups) > 0) { |
|
556 | $sql .= ' IN GROUP "'.join('", "', $groups).'"'; |
|
557 | } |
|
558 | ||
559 | if ($expiry != '') { |
|
560 | $sql .= " VALID UNTIL '{$expiry}'"; |
|
561 | } else { |
|
562 | $sql .= " VALID UNTIL 'infinity'"; |
|
563 | } |
|
564 | ||
565 | return $this->execute($sql); |
|
566 | } |
|
567 | ||
568 | /** |
|
569 | * Adjusts a user's info and renames the user. |
@@ 73-99 (lines=27) @@ | ||
70 | * |
|
71 | * @internal param $group (array) The groups to create the user in |
|
72 | */ |
|
73 | public function createUser($username, $password, $createdb, $createrole, $expiry, $groups) |
|
74 | { |
|
75 | $enc = $this->_encryptPassword($username, $password); |
|
76 | $this->fieldClean($username); |
|
77 | $this->clean($enc); |
|
78 | $this->clean($expiry); |
|
79 | $this->fieldArrayClean($groups); |
|
80 | ||
81 | $sql = "CREATE USER \"{$username}\""; |
|
82 | if ($password != '') { |
|
83 | $sql .= " WITH ENCRYPTED PASSWORD '{$enc}'"; |
|
84 | } |
|
85 | ||
86 | $sql .= $createdb ? ' CREATEDB' : ' NOCREATEDB'; |
|
87 | $sql .= $createrole ? ' CREATEROLE' : ' NOCREATEROLE'; |
|
88 | if (is_array($groups) && sizeof($groups) > 0) { |
|
89 | $sql .= ' IN GROUP "'.join('", "', $groups).'"'; |
|
90 | } |
|
91 | ||
92 | if ($expiry != '') { |
|
93 | $sql .= " VALID UNTIL '{$expiry}'"; |
|
94 | } else { |
|
95 | $sql .= " VALID UNTIL 'infinity'"; |
|
96 | } |
|
97 | ||
98 | return $this->execute($sql); |
|
99 | } |
|
100 | } |
|
101 |