Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/worker/PhabricatorAuthInviteWorker.php
12256 views
1
<?php
2
3
final class PhabricatorAuthInviteWorker
4
extends PhabricatorWorker {
5
6
protected function doWork() {
7
$data = $this->getTaskData();
8
$viewer = PhabricatorUser::getOmnipotentUser();
9
10
$address = idx($data, 'address');
11
$author_phid = idx($data, 'authorPHID');
12
13
$author = id(new PhabricatorPeopleQuery())
14
->setViewer($viewer)
15
->withPHIDs(array($author_phid))
16
->executeOne();
17
if (!$author) {
18
throw new PhabricatorWorkerPermanentFailureException(
19
pht('Invite has invalid author PHID ("%s").', $author_phid));
20
}
21
22
$invite = id(new PhabricatorAuthInviteQuery())
23
->setViewer($viewer)
24
->withEmailAddresses(array($address))
25
->executeOne();
26
if ($invite) {
27
// If we're inviting a user who has already been invited, we just
28
// regenerate their invite code.
29
$invite->regenerateVerificationCode();
30
} else {
31
// Otherwise, we're creating a new invite.
32
$invite = id(new PhabricatorAuthInvite())
33
->setEmailAddress($address);
34
}
35
36
// Whether this is a new invite or not, tag this most recent author as
37
// the invite author.
38
$invite->setAuthorPHID($author_phid);
39
40
$code = $invite->getVerificationCode();
41
$invite_uri = '/auth/invite/'.$code.'/';
42
$invite_uri = PhabricatorEnv::getProductionURI($invite_uri);
43
44
$template = idx($data, 'template');
45
$template = str_replace('{$INVITE_URI}', $invite_uri, $template);
46
47
$invite->save();
48
49
$mail = id(new PhabricatorMetaMTAMail())
50
->addRawTos(array($invite->getEmailAddress()))
51
->setForceDelivery(true)
52
->setSubject(
53
pht(
54
'[%s] %s has invited you to join %s',
55
PlatformSymbols::getPlatformServerName(),
56
$author->getFullName(),
57
PlatformSymbols::getPlatformServerName()))
58
->setBody($template)
59
->saveAndSend();
60
}
61
62
}
63
64