Skip to content

Commit f2e2767

Browse files
author
Chris Jacobsen Work
committed
Added create function
1 parent d6b73de commit f2e2767

File tree

1 file changed

+41
-29
lines changed

1 file changed

+41
-29
lines changed

app/controllers/Users.php

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
*/
3434

3535

36+
use App\Api\Ad\ADConnection;
3637
use App\Api\Ad\ADUsers;
37-
use App\Controllers\Api\Domain;
38+
use App\Models\Audit\Action\User\CreateUserAuditAction;
3839
use App\Models\Audit\Action\User\DisableUserAuditAction;
3940
use App\Models\Audit\Action\User\EnableUserAuditAction;
4041
use App\Models\Audit\Action\User\MoveUserAuditAction;
@@ -45,12 +46,11 @@
4546
use App\Models\District\DomainUser;
4647
use App\Models\User\PermissionHandler;
4748
use App\Models\User\PermissionLevel;
48-
use App\Models\View\Modal;
4949
use App\Models\View\Toast;
5050
use System\App\AppException;
5151
use System\App\AppLogger;
52+
use System\App\LDAPLogger;
5253
use System\Post;
53-
use System\App\Picture;
5454
use System\Models\Post\UploadedFile;
5555

5656
class Users extends Controller
@@ -113,35 +113,12 @@ public function searchPost($username = null)
113113
if ($uploadedPicture->exists()) {
114114
$fileType = $uploadedPicture->getType();
115115
$this->logger->debug('File type: ' . $fileType);
116+
$uploadedPicture->resize(225);
116117

117-
switch ($uploadedPicture->getType()) {
118-
119-
120-
case 'image/png':
121-
$picture = imagecreatefrompng($uploadedPicture->getTempFileName());
122-
break;
123-
case 'image/jpeg':
124-
case 'image/jpgx':
125-
case 'image/jpg':
126-
$picture = imagecreatefromjpeg($uploadedPicture->getTempFileName());
127-
break;
128-
129-
case 'image/gif':
130-
$picture = imagecreatefromgif($uploadedPicture->getTempFileName());
131-
break;
132-
case 'image/bmp':
133-
$picture = imagecreatefrombmp($uploadedPicture->getTempFileName());
134-
break;
135-
136-
}
137-
$picture = Picture::cropSquare($picture, 225);
138-
ob_start();
139-
imagejpeg($picture);
140-
$rawPicture = ob_get_clean();
141118

142119
$user = $this->getUser($username);
143-
$this->logger->debug($rawPicture);
144-
$user->activeDirectory->setThumbnail($rawPicture, false)->save();
120+
121+
$user->activeDirectory->setThumbnail($uploadedPicture->getTempFileContents(), false)->save();
145122

146123
$this->audit(new UploadUserPhotoAudtitAction($username));
147124

@@ -165,10 +142,45 @@ public function searchPost($username = null)
165142
return $output;
166143
}
167144

145+
public function createPost()
146+
{
147+
if ($this->user->superAdmin) {
148+
$username = Post::get('logonname');
149+
$newUser = ADConnection::get()->getDefaultProvider()->make()->user()
150+
->setAccountName($username);
151+
$newUser->setCommonName(Post::get('fullname'))
152+
->setAttribute('givenName', Post::get('fname'))
153+
->setAttribute('initials', Post::get('mname'))
154+
->setAttribute('sn', Post::get('lname'))
155+
->setDn('CN=' . Post::get('fullname') . ',' . Post::get('ou'))
156+
->setAttribute('mail', Post::get('email'))
157+
->setAttribute('description', Post::get('description'));
158+
$newUser->setPassword(Post::get('password'));
159+
// Get a new account control object for the user.
160+
$ac = $newUser->getUserAccountControlObject();
161+
162+
// Mark the account as enabled (normal).
163+
164+
$ac->accountIsNormal();
165+
166+
167+
// Set the account control on the user and save it.
168+
// Set the account control on the user and save it.
169+
$newUser->setUserAccountControl($ac);
170+
LDAPLogger::get()->debug($newUser);
171+
$newUser->save();
172+
$user = new DomainUser($newUser->getAccountName());
173+
$this->audit(new CreateUserAuditAction($user));
174+
$this->redirect('/users/search/' . $user->getUsername());
175+
176+
177+
}
178+
}
168179

169180
/**
170181
* Edit Post
171182
* This is the control for editing user account via the user search
183+
*
172184
* @throws \System\CoreException
173185
*/
174186
public function editPost()

0 commit comments

Comments
 (0)