resend-activation.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. $params = array();
  3. parse_str($_POST['email_resend'], $params);
  4. if(!array_key_exists('email-login', $params)) {
  5. echo 400; // Missing parameters
  6. }
  7. else {
  8. //the name attribute of the input field is email-login
  9. $email = $params['email-login'];
  10. require_once('db_utils.php');
  11. $conn = db_connect(); // Connect to the database
  12. // Check if the username already exists
  13. if(!($result = mysqli_query($conn, "SELECT salt, name FROM user WHERE username = '$email'"))) {
  14. echo 400; // Wrong query
  15. }
  16. else {
  17. if(mysqli_num_rows($result) != 1) { // User not registered or duplicated
  18. echo 401;
  19. }
  20. else { // User registered
  21. // Get user details
  22. $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
  23. $salt = $row['salt'];
  24. $name = $row['name'];
  25. // Activation email
  26. $activationLink = "https://ethicscanvas.org/activation.php?salt=$salt";
  27. $activationEmail = "Hi $name,<br><br>Thanks for signing up at EthicsCanvas.org!<br><br>Please click on the link below in order to verify your email address:<br>$activationLink<br><br>Thank you,<br>The Ethics Canvas Team";
  28. // Send activation email
  29. include('mailer.php');
  30. smtpmailer($email, 'Email verification required at ethicscanvas.org', $activationEmail, null);
  31. echo 200;
  32. }
  33. }
  34. mysqli_free_result($result);
  35. db_close($conn); // Close the database
  36. }
  37. ?>