Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $allFormFields = $hook->getValues();
- if(is_array($allFormFields)){
- foreach($allFormFields as $k => $v){
- if (filter_var($v, FILTER_VALIDATE_EMAIL)) {
- $mail = trim($v);
- }
- }
- if($mail){
- $keys = array('name', 'order-name'); //имена полей формы с именами юзеров <input name="name"> и т.п.
- foreach($keys as $key){
- if(isset($allFormFields[$key])){
- $name = $allFormFields[$key];
- break;
- }
- }
- $count = $modx->getCount('modUserProfile', array('email' => $mail)); //проверяем наличие юзера по e-mail
- // Если такого пользователя нет
- if($count == 0) {
- $pass = md5($mail);
- $user = $modx->newObject('modUser', array('username' => $name ? $name : 'Неизвестно имя'));
- $user->set('password', $pass);
- $profile = $modx->newObject('modUserProfile');
- $user->addOne($profile);
- // Назначаем дополнительные поля
- $profile->set('fullname', $name ? $name : 'Неизвестно имя');
- $profile->set('email', $mail);
- $profile->save();
- $user->save();
- //добавляем в группу с ID = 2
- $user->joinGroup(2, null, null);
- }
- /*else
- $modx->log(modX::LOG_LEVEL_ERROR, print_r('Юзер уже существует', true));*/
- }
- }
- return true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement