implement MailAgent and use it for user and Character registration
This commit is contained in:
parent
082f38ef49
commit
7c10592f6b
8 changed files with 183 additions and 31 deletions
35
agents/intermediate/MailAgent.inc
Normal file
35
agents/intermediate/MailAgent.inc
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||
*/
|
||||
|
||||
namespace hhu\z\agents\intermediate;
|
||||
|
||||
|
||||
/**
|
||||
* Agent to generate a mail-message.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MailAgent extends \nre\agents\IntermediateAgent
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*/
|
||||
public function index(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -283,16 +283,17 @@
|
|||
if($validation === true && $fieldsValidation === true)
|
||||
{
|
||||
$characterId = $this->Characters->createCharacter($this->Auth->getUserId(), $types[$typeIndex]['id'], $charactername);
|
||||
$character = $this->Characters->getCharacterById($characterId);
|
||||
|
||||
// Add Seminary fields
|
||||
foreach($fields as &$field) {
|
||||
if(!empty($fieldsValues[$field['url']])) {
|
||||
$this->Seminarycharacterfield->setSeminaryFieldOfCharacter($field['id'], $characterId, $fieldsValues[$field['url']]);
|
||||
$this->Seminarycharacterfields->setSeminaryFieldOfCharacter($field['id'], $characterId, $fieldsValues[$field['url']]);
|
||||
}
|
||||
}
|
||||
|
||||
// Send mail
|
||||
$this->sendRegistrationMail($charactername);
|
||||
$this->sendRegistrationMail($character);
|
||||
|
||||
// Redirect
|
||||
$this->redirect($this->linker->link(array('seminaries')));
|
||||
|
|
@ -633,23 +634,34 @@
|
|||
/**
|
||||
* Send mail for new Character registration.
|
||||
*
|
||||
* @param string $charactername Name of newly registered Character
|
||||
* @param arary $newCharacter Newly registered Character
|
||||
*/
|
||||
private function sendRegistrationMail($charactername)
|
||||
private function sendRegistrationMail($newCharacter)
|
||||
{
|
||||
$sender = \nre\configs\AppConfig::$app['mailsender'];
|
||||
if(empty($sender)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Send notification mail to system moderators
|
||||
$subject = sprintf('new Character registration: %s', $charactername);
|
||||
$message = sprintf('User “%s” <%s> has registered a new Character “%s” for the Seminary “%s”', self::$user['username'], self::$user['email'], $charactername, self::$seminary['title']);
|
||||
// Get Seminary moderators
|
||||
$characters = $this->Characters->getCharactersWithCharacterRole(self::$seminary['id'], 'moderator');
|
||||
foreach($characters as &$character)
|
||||
{
|
||||
$moderator = $this->Users->getUserById($character['user_id']);
|
||||
\hhu\z\Utils::sendMail($sender, $moderator['email'], $subject, $message);
|
||||
|
||||
// Send notification mail
|
||||
try {
|
||||
foreach($characters as &$character)
|
||||
{
|
||||
$moderator = $this->Users->getUserById($character['user_id']);
|
||||
\hhu\z\Utils::sendMail(
|
||||
$moderator['email'],
|
||||
'characterregistration',
|
||||
true,
|
||||
array(
|
||||
$moderator,
|
||||
\hhu\z\controllers\SeminaryController::$seminary,
|
||||
\hhu\z\controllers\IntermediateController::$user,
|
||||
$newCharacter
|
||||
),
|
||||
$this->linker
|
||||
);
|
||||
}
|
||||
}
|
||||
catch(\hhu\z\exceptions\MailingException $e) {
|
||||
$this->log($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
85
controllers/MailController.inc
Normal file
85
controllers/MailController.inc
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||
*/
|
||||
|
||||
namespace hhu\z\controllers;
|
||||
|
||||
|
||||
/**
|
||||
* Controller of the MailAgent to generate a mail message.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MailController extends \nre\core\Controller
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prefilter.
|
||||
*
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current response
|
||||
*/
|
||||
public function preFilter(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
parent::preFilter($request, $response);
|
||||
|
||||
|
||||
// Set linker
|
||||
$this->set('linker', ($request instanceof \hhu\z\requests\MailRequest && !is_null($request->getLinker())) ? $request->getLinker() : null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: userregistration.
|
||||
*
|
||||
* Generate a mail message to notify of a new user registration.
|
||||
*
|
||||
* @param array $receiver User that the message will be send to
|
||||
* @param array $neUser Newly registered user
|
||||
*/
|
||||
public function userregistration($receiver, $newUser)
|
||||
{
|
||||
// Set subject
|
||||
$this->response->setSubject(_('New user registration'));
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('user', $newUser);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: characterregistration.
|
||||
*
|
||||
* Generate a mail message to notify of a new Character
|
||||
* registration.
|
||||
*
|
||||
* @param array $receiver User that the message will be send to
|
||||
* @param array $seminary Seminary which the Character was created for
|
||||
* @param array $newCharacter Newly registered user
|
||||
*/
|
||||
public function characterregistration($receiver, $seminary, $user, $newCharacter)
|
||||
{
|
||||
// Set subject
|
||||
$this->response->setSubject(_('New Character registration'));
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('user', $user);
|
||||
$this->set('character', $newCharacter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -203,14 +203,15 @@
|
|||
$email,
|
||||
$this->request->getPostParam('password')
|
||||
);
|
||||
$user = $this->Users->getUserById($userId);
|
||||
|
||||
// Send mail
|
||||
$this->sendRegistrationMail($username, $email);
|
||||
$this->sendRegistrationMail($user);
|
||||
|
||||
// Login
|
||||
$this->Auth->setUserId($userId);
|
||||
$user = $this->Users->getUserById($userId);
|
||||
|
||||
|
||||
|
||||
// Redirect to user page
|
||||
$this->redirect($this->linker->link(array($user['url']), 1));
|
||||
}
|
||||
|
|
@ -555,20 +556,29 @@
|
|||
* @param string $username Name of newly registered user
|
||||
* @param string $email E‑mail address of newly registered user
|
||||
*/
|
||||
private function sendRegistrationMail($username, $email)
|
||||
private function sendRegistrationMail($user)
|
||||
{
|
||||
$sender = \nre\configs\AppConfig::$app['mailsender'];
|
||||
if(empty($sender)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Send notification mail to system moderators
|
||||
$subject = sprintf('new user registration: %s', $username);
|
||||
$message = sprintf('User “%s” <%s> has registered themself to %s', $username, $email, \nre\configs\AppConfig::$app['name']);
|
||||
// Get system moderators
|
||||
$moderators = $this->Users->getUsersWithRole('moderator');
|
||||
foreach($moderators as &$moderator)
|
||||
{
|
||||
\hhu\z\Utils::sendMail($sender, $moderator['email'], $subject, $message);
|
||||
|
||||
// Send notification mail
|
||||
try {
|
||||
foreach($moderators as &$moderator)
|
||||
{
|
||||
\hhu\z\Utils::sendMail(
|
||||
$moderator['email'],
|
||||
'userregistration',
|
||||
true,
|
||||
array(
|
||||
$moderator,
|
||||
$user
|
||||
),
|
||||
$this->linker
|
||||
);
|
||||
}
|
||||
}
|
||||
catch(\hhu\z\exceptions\MailingException $e) {
|
||||
$this->log($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
2
views/htmlmail/mail/characterregistration.tpl
Normal file
2
views/htmlmail/mail/characterregistration.tpl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
<?=sprintf(_('User “%s” has registered a new Character for the Seminary “%s”'), $user['username'], $seminary['title'])?>:
|
||||
<?php if(!is_null($linker)) : ?><a href="<?=$linker->link(array('characters',$seminary['url'],$user['url']),0,false,null,false,null,true)?>"><?=$character['name']?></a><?php else : ?><?=$character['name']?><?php endif ?>
|
||||
2
views/htmlmail/mail/userregistration.tpl
Normal file
2
views/htmlmail/mail/userregistration.tpl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
<?=_('A new user has been registered')?>:
|
||||
<?php if(!is_null($linker)) : ?><a href="<?=$linker->link(array('users',$user['url']),0,true,null,false,null,true)?>"><?=$user['username']?></a><?php else : ?><?=$user['username']?><?php endif ?>
|
||||
3
views/textmail/mail/characterregistration.tpl
Normal file
3
views/textmail/mail/characterregistration.tpl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<?=sprintf(_('User “%s” has registered a new Character for the Seminary “%s”'), $user['username'], $seminary['title'])?>: <?=$character['name']?>
|
||||
|
||||
<?php if(!is_null($linker)) : ?><?=$linker->link(array('characters',$seminary['url'],$user['url']),0,false,null,false,null,true)?><?php endif ?>
|
||||
3
views/textmail/mail/userregistration.tpl
Normal file
3
views/textmail/mail/userregistration.tpl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<?=_('A new user has been registered')?>: <?=$user['username']?>
|
||||
|
||||
<?php if(!is_null($linker)) : ?><?=$linker->link(array('users',$user['url']),0,false,null,false,null,true)?><?php endif ?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue