Skip to content

Instantly share code, notes, and snippets.

Created September 13, 2015 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anonymous/f0f576a74d976e6b48e3 to your computer and use it in GitHub Desktop.
Save anonymous/f0f576a74d976e6b48e3 to your computer and use it in GitHub Desktop.
<?php
/**
* Created by PhpStorm.
* User: magr0s
* Date: 12.09.2015
* Time: 19:17
*/
require_once MODX_PROCESSORS_PATH.'security/user/create.class.php';
class siteWebUserCreateProcessor extends modUserCreateProcessor{
public $permission = '';
function initialize(){
$this->setDefaultProperties(array(
'passwordgenmethod' => 'spec',
'specifiedpassword' => $this->getProperty('password'),
'confirmpassword' => $this->getProperty('password'),
'email' => $this->getProperty('username'),
'passwordnotifymethod' => 'e',
));
return parent::initialize();
}
function sendNotificationEmail() {
$confirmUrl = $this->prepareActivationUrl();
if ($this->getProperty('passwordnotifymethod') == 'e') {
$message = $this->modx->getOption('websignupemail_message');
$placeholders = array(
'uid' => $this->object->get('username'),
'pwd' => $this->newPassword,
'ufn' => $this->profile->get('fullname'),
'sname' => $this->modx->getOption('site_name'),
'saddr' => $this->modx->getOption('emailsender'),
'semail' => $this->modx->getOption('emailsender'),
'surl' => $this->modx->getOption('url_scheme') . $this->modx->getOption('http_host'),
'aurl' => $confirmUrl,
);
foreach ($placeholders as $k => $v) {
$message = str_replace('[[+'.$k.']]',$v,$message);
}
$this->object->sendEmail($message);
}
}
function prepareActivationUrl(){
$pword = $this->newPassword;
$confirmParams['ap'] = urlencode(base64_encode($pword));
$confirmParams['au'] = urlencode(base64_encode($this->object->get(username)));
$confirmUrl = $this->modx->makeUrl($this->modx->resource->id, '', $confirmParams, 'full');
$this->setCachePassword($pword);
return $confirmUrl;
}
function setCachePassword($password){
$this->modx->getService('registry', 'registry.modRegistry');
$this->modx->registry->addRegister('login','registry.modFileRegister');
$this->modx->registry->login->connect();
$this->modx->registry->login->subscribe('/useractivation/');
$this->modx->registry->login->send('/useractivation/',array($this->object->get('username') => $password),array(
'ttl' => 180*60,
));
$this->object->set('cachepwd',md5($password));
$success = $this->object->save();
if (!$success){
$this->modx->log(modX::LOG_LEVEL_ERROR,'[Register] Could not update cachepwd for activation for User: '.$this->object->get('username'));
}
}
}
return 'siteWebUserCreateProcessor';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment