Sponsorenverwaltung - Team StarCraft e.V.
 All Data Structures Files Functions Variables
resend_confirmation.php
Go to the documentation of this file.
1 <?php
2 
3  /**
4  * @file resend_confirmation.php
5  *
6  * @brief Resend the activation-email if the old one got lost.
7  *
8  * @details
9  * This script enables administrators to resend the email-confirmation
10  * mail to a user if the old one got lost.
11  *
12  * This file depends on inc/common.php and inc/templates/nocontent.tpl
13  *
14  * @copyright (c) 2013, Team StarCraft e.V.
15  * @version 1.0.0
16  * @author Usercake (http://www.usercake.com)
17  * @author Alexander Vorndran
18  * @date 02.07.2013
19  */
20 
21  /// @cond MAINPART
22  // include
23  include("inc/common.php");
24 
25  // UserCake
26  if (!accessGranted($_SERVER['PHP_SELF'])) {
27  if (isUserLoggedIn()) {
28  exitWithErrorTemplate(array('Die angeforderte Seite ist gesperrt.'));
29  } else {
30  exitWithErrorTemplateAndRedirect(array('Die angeforderte Seite ist gesperrt oder geschützt.'), 'login.php', 2);
31  }
32  }
33 
34  if (isset($_GET['id']) && ctype_digit($_GET['id'])) {
35  // allow this only for administrators
36  if (!isUserAdministrator()) {
37  exitWithErrorTemplateAndRedirect(array('Keine ausreichenden Rechte!'), 'users.php', 2);
38  } else {
39  $userId = $_GET['id'];
40  // check if the user id really exists
41  if (userIdExists($userId)) {
42  // fetch the details for the given user
43  $userDetails = fetchUserDetails(null, null, $userId);
44  // has the users email already been validated
45  if (hasValidMail($userId)) {
46  exitWithErrorTemplateAndRedirect(array('E-Mail-Adresse bereits validiert'), 'users.php', 2);
47  } else {
48  // Create new email-instance
49  $mail = new UserCakeMail();
50 
51  //Construct a unique activation token
52  $new_activation_token = generateActivationToken();
53 
54  // succeed only if the new token could be set
55  if (updateMailConfirmationToken($new_activation_token, $userDetails['username'])) {
56  //Build the activation message
57  $activation_url = $websiteUrl . "activate-account.php?token=" . $new_activation_token;
58 
59  //Setup our custom hooks
60  $hooks = array(
61  "searchStrs" => array("#ACTIVATION-URL", "#USERNAME#"),
62  "subjectStrs" => array($activation_url, $userDetails["user_name"])
63  );
64  $mail_failure = false;
65 
66  /* Build the template - Optional, you can just use the sendMail function
67  Instead to pass a message. */
68  if (!$mail->newTemplateMsg("resend-confirmation.txt", $hooks)) {
69  $mail_failure = true;
70  } else {
71  //Send the mail. Specify users email here and subject.
72  //SendMail can have a third parementer for message if you do not wish to build a template.
73  if (!$mail->sendMail($userDetails['email'], 'Bestätigung der E-Mail-Adresse')) {
74  $mail_failure = true;
75  $errors[] = "Die Bestätigungs-E-Mail konnte nicht versendet werden.";
76  }
77  }
78  if (!$mail_failure) {
79  $successes[] = "Es wurde eine Bestätigungs-E-Mail versendet.";
80 
81  displayTemplateWithErrorsAndSuccesses("Bestätigungs-E-Mail versenden", "nocontent.tpl");
82  } else {
84  }
85  } else {
86  $errors[] = lang('SQL_ERROR');
87  }
88  }
89  } else {
90  exitWithErrorTemplateAndRedirect(array('Ungültige Benutzer-ID!'), 'users.php', 2);
91  }
92  }
93  } else {
94  header("Refresh: home.php");
95  }
96  /// @endcond
97 ?>