Skip to content

Commit

Permalink
Merge pull request #2537 from phili67/phili67-people-veryfy-confirm
Browse files Browse the repository at this point in the history
Phili67 people veryfy confirm
  • Loading branch information
phili67 authored Feb 12, 2024
2 parents 6202582 + b7aff73 commit de4a647
Show file tree
Hide file tree
Showing 17 changed files with 1,013 additions and 591 deletions.
2 changes: 1 addition & 1 deletion src/EcclesiaCRM/APIControllers/PeopleFamilyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public function verifyFamilyPDF (ServerRequest $request, Response $response, arr
if ($family != null) {
$fams_to_contact = new EmailUsers([$familyId]);

$familyEmailSent = $fams_to_contact->renderAndSend();
$familyEmailSent = $fams_to_contact->renderAndSend('family');

return $response->withJson(["status" => $familyEmailSent]);
} else {
Expand Down
109 changes: 108 additions & 1 deletion src/EcclesiaCRM/APIControllers/PeoplePersonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,28 @@
use EcclesiaCRM\dto\SystemURLs;
use EcclesiaCRM\dto\SystemConfig;
use EcclesiaCRM\dto\MenuEventsCount;

use EcclesiaCRM\Emails\PersonVerificationEmail;
use EcclesiaCRM\Utils\MiscUtils;
use EcclesiaCRM\Utils\OutputUtils;

use EcclesiaCRM\PersonQuery;
use EcclesiaCRM\Record2propertyR2pQuery;
use EcclesiaCRM\Note;
use EcclesiaCRM\NoteQuery;
use EcclesiaCRM\Token;
use EcclesiaCRM\TokenQuery;
use EcclesiaCRM\VolunteerOpportunityQuery;
use EcclesiaCRM\PersonVolunteerOpportunityQuery;
use EcclesiaCRM\PersonVolunteerOpportunity;
use EcclesiaCRM\PersonCustomMasterQuery;
use EcclesiaCRM\ListOptionQuery;
use EcclesiaCRM\FamilyQuery;
use EcclesiaCRM\UserQuery;

use EcclesiaCRM\SessionUser;
use EcclesiaCRM\Emails\UpdateAccountEmail;
use EcclesiaCRM\Reports\EmailUsers;
use EcclesiaCRM\TokenPassword;

use EcclesiaCRM\Map\Record2propertyR2pTableMap;
use EcclesiaCRM\Map\PropertyTableMap;
Expand Down Expand Up @@ -703,4 +708,106 @@ public function addressBook (ServerRequest $request, Response $response, array $
$response->getBody()->write($output);
return $response;
}

public function verifyPerson (ServerRequest $request, Response $response, array $args): Response {
$personId = $args["personId"];
$person = PersonQuery::create()->findPk($personId);
if ($person != null) {
TokenQuery::create()->filterByType("verifyPerson")->filterByReferenceId($person->getId())->delete();
$token = new Token();
$token->build("verifyPerson", $person->getId());
$token->save();

$tokenPassword = new TokenPassword();

$password = MiscUtils::random_password(8);

$tokenPassword->setTokenId($token->getPrimaryKey());
$tokenPassword->setPassword(md5($password));
$tokenPassword->setMustChangePwd(false);

$tokenPassword->save();

$emails = [];

if ($person->getEmail() == "") {
$emails = $person->getFamily()->getEmails();
} else {
$emails = [$person->getEmail()];
}

$email = new PersonVerificationEmail($emails, $person->getFirstName(), $person->getLastName(), $token->getToken(), $emails, $password);
if ($email->send()) {
$person->createTimeLineNote("verify-link");
$response = $response->withStatus(200);
} else {
$logger = $this->container->get('Logger');
$logger->error($email->getError());
throw new \Exception($email->getError());
}
} else {
$response = $response->withStatus(404)->getBody()->write("personId: " . $personId . " not found");
}
return $response;
}

public function verifyPersonPDF (ServerRequest $request, Response $response, array $args): Response {
$personId = $args["personId"];
$person = PersonQuery::create()->findPk($personId);
if ($person != null) {
$person_to_contact = new EmailUsers(null, [(int)$personId]);

$personEmailSent = $person_to_contact->renderAndSend('person');

return $response->withJson(["status" => $personEmailSent]);
} else {
$response = $response->withStatus(404)->getBody()->write("personId: " . $personId . " not found");
}
return $response;
}

public function verifyPersonNow (ServerRequest $request, Response $response, array $args): Response {
$personId = $args["personId"];
$person = PersonQuery::create()->findPk($personId);
if ($person != null) {
$person->verify();
$response = $response->withStatus(200);
} else {
$response = $response->withStatus(404)->getBody()->write("personId: " . $personId . " not found");
}
return $response;
}

public function verifyPersonURL (ServerRequest $request, Response $response, array $args): Response {
$input = (object)$request->getParsedBody();

if ( isset ($input->perId) ) {
$person = PersonQuery::create()->findOneById($input->perId);
$token = TokenQuery::create()
->filterByType("verifyPerson")
->findOneByReferenceId($person->getId());
if (!is_null($token)) {
$token->delete();
}
$token = new Token();
$token->build("verifyPerson", $person->getId());
$token->save();

$tokenPassword = new TokenPassword();

$password = MiscUtils::random_password(8);

$tokenPassword->setTokenId($token->getPrimaryKey());
$tokenPassword->setPassword(md5($password));
$tokenPassword->setMustChangePwd(false);

$tokenPassword->save();


$person->createTimeLineNote("verify-URL");
return $response->withJSON(["url" => "ident/my-profile/" . $token->getToken(), 'password' => $password]);
}

return $response;
}
}
2 changes: 1 addition & 1 deletion src/EcclesiaCRM/Emails/verify/PersonVerificationEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct($emails, $firstName, $LastName, $token = "", $logins

parent::__construct($emails);

$this->mail->Subject = _("Person"). " : ". $firstName . " ". $LastName . " (" . gettext("Please verify your family's information").")";
$this->mail->Subject = _("Person"). " : ". $firstName . " ". $LastName . " (" . gettext("Please verify your informations").")";
$this->mail->isHTML(true);
$this->mail->msgHTML($this->buildMessage());
}
Expand Down
Loading

0 comments on commit de4a647

Please sign in to comment.