I have searched the forum and docs and am unable to determine if the is a way to send a new user, added via the CMS security tab, their credentials when they are created. Has anyone done this or developed a solution?
Regards,
Todd M. Kimball
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
I have searched the forum and docs and am unable to determine if the is a way to send a new user, added via the CMS security tab, their credentials when they are created. Has anyone done this or developed a solution?
Regards,
Todd M. Kimball
I have not done this before, but I'd recommend using a custom/decorator Member class and adding the email sending in an overridden onAfterWrite.
Thanks, that did the trick. However, I'm getting 2 email notifications instead of one. I'm using this to decorate, test code no flame about not using the email class please 8):
<?php
class MemberEmailNotification extends DataObjectDecorator {
function onAfterWrite() {
mail("me@email.com", "test", "did you get this?");
parent::onAfterWrite();
}
}
?>
Could this be a result of calling parent::onAfterWrite()? If I don't call it will I be omitting any necessary logic in the parent classes onAfterWrite method?
Regards,
Todd
Plan B, I'm attempting to use a native function of the Member class, sendInfo(), instead of writing my own logic to send an email. It works, but the email has variable symbols included instead of the values associated with the symbols. Here is a snippet of the email:
<--- Begin Snippet --->
Welcome, $FirstName.
Thanks for signing up to become a new member, your details are listed below for future reference.
You can login to the website using the credentials listed below:
Email$Email
Password:$Password
Contact Information
<--- End Snippet --->
As you can see, it's as if the variables aren't being parsed. Any ideas on this one?
Regards,
Todd
how about doing something like this (again untested...)
class MemberEmailNotification extends DataObjectDecorator
{
var $bSendEmailFlag;
function onAfterWrite()
{
parent::onBeforeWrite();
$this->bSendEmailFlag = true;
}
function onAfterWrite()
{
parent::onAfterWrite();
if ($this->bSendEmailFlag)
{
mail("me@email.com", "test", "did you get this?");
$this->bSendEmailFlag = false;
}
}
}
Thanks again for the latest suggestion. However, I am now trying to use existing methods to generate the email (see my previous response). If anyone could provide any insight into the Member->sendInfo() method that wold be great.
Regards,
Todd
I know I am replying to an old thread that you, toddmkimball, have moved on from, but I recently had a need to do this and since my method was untested I thought I'd post back the completed working version the way I found to work for a dataobject in general when creating it and ensuring you only get one execution of the code... note does not apply to re-saves...
function onAfterWrite()
{
parent::onAfterWrite();
if (isset($this->Created))
{
//do on after wirte action only once
}
}
Barry