Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW email notification for MFA settings update #134

Merged

Conversation

NightJar
Copy link
Contributor

@NightJar NightJar commented May 23, 2019

As a precaution users should be notified whenever their account details pertaining to security are updated, in order to let them respond to what could be a security breach. The easiest manner to do this is to send an email to their registered address.

Closes #67

@NightJar NightJar force-pushed the pulls/4/notifications branch from b1dbd50 to 4016470 Compare May 23, 2019 02:35
Copy link
Contributor

@robbieaverill robbieaverill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Looking great. I've added some minor tidy up suggestions, but looks solid overall.

_config/notifications.yml Outdated Show resolved Hide resolved
_config/notifications.yml Outdated Show resolved Hide resolved
src/Service/Notification.php Outdated Show resolved Hide resolved
src/Service/Notification.php Show resolved Hide resolved
src/Service/Notification.php Outdated Show resolved Hide resolved
tests/php/BackupCode/VerifyHandlerTest.php Outdated Show resolved Hide resolved
tests/php/Service/RegisteredMethodManagerTest.php Outdated Show resolved Hide resolved
tests/php/Service/RegisteredMethodManagerTest.php Outdated Show resolved Hide resolved
tests/php/Service/RegisteredMethodManagerTest.php Outdated Show resolved Hide resolved
tests/php/Service/RegisteredMethodManagerTest.php Outdated Show resolved Hide resolved
Copy link
Contributor

@ScopeyNZ ScopeyNZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Haven't had a chance to check it out and have a play. I have one super minor semantics comment. Notification isn't really a Service any longer - because it's stateful. You could make it stateless by turning send into the only method that takes the contructor args. Usage within the code would then be:

Notification::singleton()->send($member, $template, $data);

You could then to the private static $dependencies configuration in the service class for the Email dependency.

@NightJar NightJar force-pushed the pulls/4/notifications branch 2 times, most recently from 9936645 to 11e6d91 Compare May 23, 2019 04:32
@NightJar
Copy link
Contributor Author

Cool, I adapted to along the lines of your comment too @ScopeyNZ - however I didn't see the point in dependencies as the execution already fetches a named service. Leaving a member variable would still have state, whether it be given or installed via Injector.

@NightJar
Copy link
Contributor Author

Broken build from race condition. Rerun has made them green.

@NightJar NightJar force-pushed the pulls/4/notifications branch 2 times, most recently from 7b7bbef to e27e005 Compare May 27, 2019 04:16
src/Service/Notification.php Outdated Show resolved Hide resolved
_config/notifications.yml Outdated Show resolved Hide resolved
@NightJar NightJar force-pushed the pulls/4/notifications branch 3 times, most recently from 20db451 to 99a1b91 Compare May 27, 2019 22:54
@NightJar
Copy link
Contributor Author

addressed and tests passed.

@@ -58,6 +59,14 @@ public function verify(HTTPRequest $request, StoreInterface $store, RegisteredMe
array_splice($candidates, $index, 1);
$registeredMethod->Data = json_encode($candidates);
$registeredMethod->write();
Notification::singleton()->send(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DI?

*/
public function send(Member $member, string $template, array $data = []): bool
{
$this->email
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make the email object a singleton (by using it in DI) - is that what you expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err, no. thanks for pointing that out.

* Ecapsulates setting up an Email in order to allow for Dependency Injection and to avoid introducing a hard
* coupling to the SilverStripe core Email class in code that consumes this class.
*/
class Notification
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you want to rename the class? The reason I suggested it because $dependencies = ['NotificationService' => Notification::class] is not as verbose as NotificationService::class despite it being namespaced. If you think it's fine then I'm happy too. You could also use Notification\Service::class, or leave it as is. The property name helps 👍

As a precaution users should be notified whenever their account details pertaining to security are updated, in order to let them respond to what could be a security breach. The easiest manner to do this is to send an email to their registered address.
@NightJar NightJar force-pushed the pulls/4/notifications branch from 99a1b91 to 02fa370 Compare May 28, 2019 05:20
$this->extend('onAfterSend', $email, $sendResult);

// Could no longer be a bool as a result of the extension point above, so is cast to bool.
return (bool) $sendResult;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also use a SilverStripe\MFA\State\Result object which could provide more context. That was extensions can say why they're changing it to a failure as well. We could also provide $ex->getMessage() as context when catching exceptions and setting it to be a failure. I think a bool is fine for now but maybe something you might want to follow up on later 👍

@robbieaverill robbieaverill merged commit bae652b into silverstripe:master May 28, 2019
@robbieaverill robbieaverill deleted the pulls/4/notifications branch May 28, 2019 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changes to user's MFA should result in email
3 participants