implemented email functionality, users can now request to become contributors.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
require_once 'db_functions.php';
|
||||
require_once 'article_functions.php';
|
||||
|
||||
use Postmark\PostmarkClient;
|
||||
|
||||
function user_id_exists($user_id)
|
||||
{
|
||||
$conn = get_connection();
|
||||
@@ -361,7 +363,7 @@ function request_role_change_form()
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$roles .= '
|
||||
<label class="form_checkbox_container">' . $row['role'] . '
|
||||
<input name="requested_role" value="' . $row['role_id'] . '" type="checkbox"' . ($row['role_id'] == $_COOKIE['role_id'] ? ' checked' : '') . '>
|
||||
<input name="requested_role" value="' . $row['role_id'] . '" type="radio"' . ($row['role_id'] == $_COOKIE['role_id'] ? ' checked' : '') . '>
|
||||
<span class="checkmark"></span>
|
||||
</label>
|
||||
';
|
||||
@@ -374,7 +376,7 @@ function request_role_change_form()
|
||||
<h5 class="underline">Request Role</h5>
|
||||
<span class="modal_close">×</span>
|
||||
<form method="post">
|
||||
<input type="hidden" name="form_id" value="request_role_form">
|
||||
<input type="hidden" name="form_id" value="request_role_change_form">
|
||||
' . $roles . '
|
||||
|
||||
<input type="submit" class="button" value="Request Role">
|
||||
@@ -387,7 +389,35 @@ function request_role_change_form()
|
||||
|
||||
function request_role_change($user_id, $new_role_id)
|
||||
{
|
||||
// TODO: Need to implement email handler first.
|
||||
$conn = get_connection();
|
||||
$stmt = $conn->prepare('SELECT user_id, username, email, roles.role, created_at FROM user INNER JOIN roles WHERE user.role_id = roles.role_id AND user_id = ?');
|
||||
$stmt->bind_param('i', $user_id);
|
||||
$stmt->execute();
|
||||
|
||||
$user = $stmt->get_result()->fetch_assoc();
|
||||
$stmt = $conn->prepare('SELECT role FROM roles WHERE role_id = ?');
|
||||
$stmt->bind_param('i', $new_role_id);
|
||||
$stmt->execute();
|
||||
$new_role = $stmt->get_result()->fetch_array();
|
||||
|
||||
$email_html = '
|
||||
<h1>User Role Change Request</h1>
|
||||
<p>The following user has requested their role on vintagecoding.net to be changed:</p>
|
||||
<p><strong>User ID: </strong>' . $user['user_id'] . '</p>
|
||||
<p><strong>Username: </strong>' . $user['username'] . '</p>
|
||||
<p><strong>Email: </strong>' . $user['email'] . '</p>
|
||||
<p><strong>Current Role: </strong>' . $user['role'] . ' -> ' . $new_role[0] . '</p>
|
||||
<p><strong>Created At: </strong>' . $user['created_at'] . '</p>
|
||||
';
|
||||
|
||||
$client = new PostmarkClient($_ENV['POSTMARK_API_TOKEN']);
|
||||
|
||||
$send_result = $client->sendEmail(
|
||||
'mailer@joshashton.dev',
|
||||
'me@joshashton.dev',
|
||||
'User Role Change Request - ' . $user['user_id'],
|
||||
$email_html
|
||||
);
|
||||
}
|
||||
|
||||
function delete_account_form()
|
||||
@@ -524,6 +554,7 @@ function user_view($user_id)
|
||||
<button id="reset_pw_form_button" class="modal_button underline">Reset Password</button>
|
||||
<button id="update_email_form_button" class="modal_button underline">Update Email</button>
|
||||
<button id="update_username_form_button" class="modal_button underline">Update Username</button>
|
||||
<button id="request_role_form_button" class="modal_button underline">Request Role</button>
|
||||
<button id="delete_account_form_button" class="modal_button underline">Delete Account</button>
|
||||
</div>
|
||||
|
||||
@@ -535,6 +566,7 @@ function user_view($user_id)
|
||||
<div id="reset_pw_form" class="modal_form">' . reset_pw_form() . '</div>
|
||||
<div id="update_email_form" class="modal_form">' . update_email_form() . '</div>
|
||||
<div id="update_username_form" class="modal_form">' . update_username_form() . '</div>
|
||||
<div id="request_role_change_form" class="modal_form">' . request_role_change_form() . '</div>
|
||||
<div id="delete_account_form" class="modal_form">' . delete_account_form() . '</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user