· 8 years ago · Jul 03, 2018, 09:24 PM
1<?php
2defined('C5_EXECUTE') or die(_("Access Denied."));
3$u = new User();
4$uh = Loader::helper('concrete/user');
5$txt = Loader::helper('text');
6$vals = Loader::helper('validation/strings');
7$valt = Loader::helper('validation/token');
8$valc = Loader::helper('concrete/validation');
9$dtt = Loader::helper('form/date_time');
10$form = Loader::helper('form');
11$ih = Loader::helper('concrete/interface');
12$av = Loader::helper('concrete/avatar');
13
14if ($_POST['create']) {
15
16 if (USER_REGISTRATION_WITH_EMAIL_ADDRESS == true) {
17 $_POST['uName'] = $_POST['uEmail'];
18 }
19
20
21 $username = $_POST['uName'];
22 $username = trim($username);
23 $username = ereg_replace(" +", " ", $username);
24 $password = $_POST['uPassword'];
25
26 if (!$vals->email($_POST['uEmail'])) {
27 $error[] = t('Invalid email address provided.');
28 } else if (!$valc->isUniqueEmail($_POST['uEmail'])) {
29 $error[] = t("The email address '%s' is already in use. Please choose another.",$_POST['uEmail']);
30 }
31
32 if (USER_REGISTRATION_WITH_EMAIL_ADDRESS == false) {
33 if (strlen($username) < USER_USERNAME_MINIMUM) {
34 $error[] = t('A username must be between at least %s characters long.',USER_USERNAME_MINIMUM);
35 }
36
37 if (strlen($username) > USER_USERNAME_MAXIMUM) {
38 $error[] = t('A username cannot be more than %s characters long.',USER_USERNAME_MAXIMUM);
39 }
40
41 if (strlen($username) >= USER_USERNAME_MINIMUM && !$valc->username($username)) {
42 if(USER_USERNAME_ALLOW_SPACES) {
43 $e->add(t('A username may only contain letters, numbers and spaces.'));
44 } else {
45 $e->add(t('A username may only contain letters or numbers.'));
46 }
47
48 }
49
50 if (!$valc->isUniqueUsername($username)) {
51 $error[] = t("The username '%s' already exists. Please choose another",$username);
52 }
53 }
54
55 if ($username == USER_SUPER) {
56 $error[] = t('Invalid Username');
57 }
58
59
60 if ((strlen($password) < USER_PASSWORD_MINIMUM) || (strlen($password) > USER_PASSWORD_MAXIMUM)) {
61 $error[] = t('A password must be between %s and %s characters',USER_PASSWORD_MINIMUM,USER_PASSWORD_MAXIMUM);
62 }
63
64 if (strlen($password) >= USER_PASSWORD_MINIMUM && !$valc->password($password)) {
65 $error[] = t('A password may not contain ", \', >, <, or any spaces.');
66 }
67
68 if (!$valt->validate('create_account')) {
69 $error[] = $valt->getErrorMessage();
70 }
71
72 if (!$error) {
73 // do the registration
74 $data = array('uName' => $username, 'uPassword' => $password, 'uEmail' => $_POST['uEmail']);
75 $uo = UserInfo::add($data);
76
77 if (is_object($uo)) {
78
79 if (is_uploaded_file($_FILES['uAvatar']['tmp_name'])) {
80 $uHasAvatar = $av->updateUserAvatar($_FILES['uAvatar']['tmp_name'], $uo->getUserID());
81 }
82
83 $uo->updateSelectedUserAttributes($data['editAKID'], $_POST);
84 $uo->updateGroups($_POST['gID']);
85 $uID = $uo->getUserID();
86 $this->controller->redirect('/dashboard/users/search?uID=' . $uID . '&user_created=1');
87 } else {
88 $error[] = t('An error occurred while trying to create the account.');
89 }
90
91 }
92}
93
94?>
95 <h1><span><?php echo t('Create Account')?></span></h1>
96
97 <div class="ccm-dashboard-inner">
98
99 <div class="actions">
100 <span class="required">*</span> - <?php echo t('required field')?>
101 </div>
102
103 <form method="post" enctype="multipart/form-data" id="ccm-user-form" action="<?php echo $this->url('/dashboard/users/add')?>">
104 <?php echo $valt->output('create_account')?>
105
106 <input type="hidden" name="_disableLogin" value="1">
107
108 <h2><?php echo t('Required Information')?></h2>
109
110 <div style="margin:0px; padding:0px; width:100%; height:auto" >
111 <table class="entry-form" border="0" cellspacing="1" cellpadding="0">
112 <tr>
113 <td class="subheader" width="50%"><?php if (USER_REGISTRATION_WITH_EMAIL_ADDRESS == false) { ?><?php echo t('Username')?> <span class="required">*</span><?php } else { ?><?php echo t('Email Address')?> <span class="required">*</span><?php } ?></td>
114 <td class="subheader" width="50%"><?php echo t('Password')?> <span class="required">*</span></td>
115 </tr>
116 <tr>
117 <td><?php if (USER_REGISTRATION_WITH_EMAIL_ADDRESS == false) { ?><input type="text" name="uName" autocomplete="off" value="<?php echo $_POST['uName']?>" style="width: 95%"><?php } else { ?><input type="text" name="uEmail" autocomplete="off" value="<?php echo $_POST['uEmail']?>" style="width: 95%"><?php } ?></td>
118 <td><input type="password" autocomplete="off" name="uPassword" value="" style="width: 95%"></td>
119 </tr>
120 <tr>
121 <td class="subheader"><?php if (USER_REGISTRATION_WITH_EMAIL_ADDRESS == true) { ?> <?php } else { ?><?php echo t('Email Address')?> <span class="required">*</span><?php } ?></td>
122 <td class="subheader"><?php echo t('User Avatar')?></td>
123 </tr>
124 <tr>
125 <td><?php if (USER_REGISTRATION_WITH_EMAIL_ADDRESS == true) { ?> <?php } else { ?><input type="text" name="uEmail" autocomplete="off" value="<?php echo $_POST['uEmail']?>" style="width: 95%"><?php } ?></td>
126 <td><input type="file" name="uAvatar" style="width: 95%"/></td>
127 </tr>
128 </table>
129 </div>
130
131 <h2><?php echo t('Groups')?></h2>
132
133 <p><?php echo t('Once you create the account you may assign it to groups.')?></p>
134
135
136 <div class="ccm-buttons">
137 <input type="hidden" name="create" value="1" />
138 <a href="javascript:void(0)" onclick="$('#ccm-user-form').get(0).submit()" class="ccm-button-right accept"><span><?php echo t('Create User')?></span></a>
139 </div>
140
141 <div class="ccm-spacer"> </div>
142
143 </div>
144 </form>