check if unique values already exists for user and Character registration and send notification mail to moderators
This commit is contained in:
parent
f394946fa2
commit
babfe5b017
11 changed files with 290 additions and 34 deletions
|
|
@ -199,6 +199,9 @@
|
|||
// Validate Character properties
|
||||
$validation = $this->Validation->validateParams($this->request->getPostParams(), array('charactername'));
|
||||
$charactername = $this->request->getPostParam('charactername');
|
||||
if($this->Characters->characterNameExists($charactername)) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'charactername', 'exist', true);
|
||||
}
|
||||
|
||||
// Validate type
|
||||
$typeIndex = null;
|
||||
|
|
@ -245,6 +248,9 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Send mail
|
||||
$this->sendRegistrationMail($charactername);
|
||||
|
||||
// Redirect
|
||||
$this->redirect($this->linker->link(array('seminaries')));
|
||||
}
|
||||
|
|
@ -260,6 +266,31 @@
|
|||
$this->set('fieldsValidation', $fieldsValidation);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Send mail for new Character registration.
|
||||
*
|
||||
* @param string $charactername Name of newly registered Character
|
||||
*/
|
||||
private function sendRegistrationMail($charactername)
|
||||
{
|
||||
$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']);
|
||||
$moderators = $this->Users->getUsersWithSeminaryRole(self::$seminary['id'], 'moderator');
|
||||
foreach($moderators as &$moderator)
|
||||
{
|
||||
\hhu\z\Utils::sendMail($sender, $moderator['email'], $subject, $message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -164,9 +164,16 @@
|
|||
// Get params and validate them
|
||||
$validation = $this->Validation->validateParams($this->request->getPostParams(), $fields);
|
||||
$username = $this->request->getPostParam('username');
|
||||
if($this->Users->usernameExists($username)) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'username', 'exist', true);
|
||||
}
|
||||
$prename = $this->request->getPostParam('prename');
|
||||
$surname = $this->request->getPostParam('surname');
|
||||
$email = $this->request->getPostParam('email');
|
||||
if($this->Users->emailExists($email)) {
|
||||
$validation = $this->Validation->addValidationResult($validation, 'email', 'exist', true);
|
||||
}
|
||||
|
||||
|
||||
// Register
|
||||
if($validation === true)
|
||||
|
|
@ -178,7 +185,10 @@
|
|||
$email,
|
||||
$this->request->getPostParam('password')
|
||||
);
|
||||
|
||||
|
||||
// Send mail
|
||||
$this->sendRegistrationMail($username, $email);
|
||||
|
||||
// Login
|
||||
$this->Auth->setUserId($userId);
|
||||
$user = $this->Users->getUserById($userId);
|
||||
|
|
@ -323,6 +333,31 @@
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Send mail for new user registration.
|
||||
*
|
||||
* @param string $username Name of newly registered user
|
||||
* @param string $email E‑mail address of newly registered user
|
||||
*/
|
||||
private function sendRegistrationMail($username, $email)
|
||||
{
|
||||
$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']);
|
||||
$moderators = $this->Users->getUsersWithRole('moderator');
|
||||
foreach($moderators as &$moderator)
|
||||
{
|
||||
\hhu\z\Utils::sendMail($sender, $moderator['email'], $subject, $message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -110,6 +110,31 @@
|
|||
return $validation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a custom determined validation result to a validation
|
||||
* store.
|
||||
*
|
||||
* @param mixed $validation Validation store to add result to
|
||||
* @param string $param Name of parameter of the custom validation result
|
||||
* @param string $setting Name of setting of the custom validation result
|
||||
* @param mixed $result Validation result
|
||||
* @return mixed The altered validation store
|
||||
*/
|
||||
public function addValidationResult($validation, $param, $setting, $result)
|
||||
{
|
||||
if(!is_array($validation)) {
|
||||
$validation = array();
|
||||
}
|
||||
if(!array_key_exists($param, $validation)) {
|
||||
$validation[$param] = array();
|
||||
}
|
||||
$validation[$param][$setting] = $result;
|
||||
|
||||
|
||||
return $validation;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue