Просмотр исходного кода

Added ID pass and fail emails.

Alan Lam 8 лет назад
Родитель
Сommit
5435f0064e
3 измененных файлов с 65 добавлено и 4 удалено
  1. 9 3
      controllers/user_verify.php
  2. 55 0
      engine/user.php
  3. 1 1
      views/user_verify.php

+ 9 - 3
controllers/user_verify.php

@@ -22,6 +22,10 @@ if($submit) {
 	try {
 		Core::validateCSRFToken($submit);
 
+		if($reject && !$reject_reason) {
+			throw new Exception("A reject reason is required.");
+		}
+
 		if($accept) {
 			$user->level = User::LEVEL_TESTER;
 			$user->verifier_id = Core::$user->id;
@@ -38,14 +42,16 @@ if($submit) {
 		if(!$success) throw new Exception("Failed to update user level. Please try again later.");
 
 		if($accept) {
-			// TODO: Send accepted email
+			$user->sendIDPassEmail();
+			$verb = "accepted";
 		}
 
 		if($reject) {
-			// TODO: Send rejection email
+			$user->sendIDFailEmail($reject_reason);
+			$verb = "rejected";
 		}
 
-		Core::addAlert("success", "User updated successfully.");
+		Core::addAlert("success", "User $verb successfully.");
 		HTTP::redirect("/account/users");
 	}
 	catch(Exception $e) {

+ 55 - 0
engine/user.php

@@ -125,6 +125,61 @@ class User extends Model {
 
 	}
 
+	public function sendIDPassEmail() {
+
+		// Content
+		$name = htmlspecialchars($this->first_name);
+
+		// Build
+		$builder = new EmailBuilder;
+		$builder->addParagraph("<b>Hi $name</b>");
+		$builder->addLeadParagraph("Your application has been successful!");
+		$builder->addParagraph("Welcome to Check Policy! Remember to check your online account for when tests become available.");
+		$builder->addParagraph("Keep an eye out for emails inviting you to accept a test.");
+		$builder->addParagraph("If you accept to do a test within the agreed period (usually 7 days) please click Accept to confirm that you would like to do the test.");
+		$builder->addParagraph("After you click Accept, you will be given the option to Begin the test whenever you want. Just load up your account and click Begin.");
+		$builder->addParagraph("Once again welcome to Check Policy - Accept, Begin, Complete and get paid for up to 8 minutes work!");
+		$content = $builder->build();
+
+		// Send
+		$mail = new Email;
+		$mail->setHtmlContent($content);
+		$mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
+		$mail->addAddress($this->email, $this->getDisplayName());
+		$mail->setSubject("ID accepted and verified");
+		$mail->send();
+
+		return true;
+
+	}
+
+	public function sendIDFailEmail($reason = "No reason given.") {
+
+		// Content
+		$name = htmlspecialchars($this->first_name);
+		$reason = htmlspecialchars($reason);
+
+		// Build
+		$builder = new EmailBuilder;
+		$builder->addParagraph("<b>Hi $name</b>");
+		$builder->addLeadParagraph("Thank you for submitting your ID details.");
+		$builder->addParagraph("Unfortunately we could not verify and accept your documents and/or image.");
+		$builder->addParagraph("The reason for this is: $reason");
+		$builder->addParagraph("Please log in again, resubmit and we will try again.");
+		$builder->addParagraph("We look forward to welcoming you on-board soon!");
+		$content = $builder->build();
+
+		// Send
+		$mail = new Email;
+		$mail->setHtmlContent($content);
+		$mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
+		$mail->addAddress($this->email, $this->getDisplayName());
+		$mail->setSubject("We could not verify your ID details");
+		$mail->send();
+
+		return true;
+	}
+
 	public function sendPasswordResetEmail() {
 
 		$this->reset_token = bin2hex(random_bytes(16));

+ 1 - 1
views/user_verify.php

@@ -46,7 +46,7 @@
 			<textarea class="form-control" name="verification_notes" id="verification-notes" placeholder="Enter verification notes" rows="4"><?=htmlspecialchars($user->verifier_notes)?></textarea>
 		</div>
 		<div class="form-group">
-			<label for="reject-reason">Reject Reason (if rejecting)</label>
+			<label for="reject-reason">Reject Reason (required if rejecting)</label>
 			<input class="form-control" name="reject_reason" id="reject-reason" placeholder="Enter reject reason" />
 		</div>