Skip to content

Instantly share code, notes, and snippets.

View woganmay's full-sized avatar

Wogan May woganmay

View GitHub Profile
@woganmay
woganmay / auth.php
Created February 12, 2017 13:38
PHP CURL code to authenticate with Flarum API
<?php
// Details to access Flarum
$api_url = "https://my.forum.url/api/token";
$username = "my_flarum_user";
$password = "my_flarum_pass";
// CURL call
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
@woganmay
woganmay / new-flarum-user.php
Last active March 9, 2024 20:34
Use the Flarum API to create a new user
<?php
$api_url = "https://my.flarum.url/api/users";
$token = $session->token; // See: https://gist.github.com/woganmay/88f15e96fc019657a0e594366403b5cf
// This must be a token for a user with Administrator access
$new_username = "johnsmith";
$new_password = "password1234";
$new_email = "john.smith@example.org";
@woganmay
woganmay / activate-flarum-user.php
Created February 12, 2017 13:47
Activate an existing Flarum user
<?php
$api_url = "https://my.flarum.url/api/users/" . $userid; // See: https://gist.github.com/woganmay/4c15a0f7c16e41ab3a3ea1a73c595bf9
$token = $session->token; // See: https://gist.github.com/woganmay/88f15e96fc019657a0e594366403b5cf
// This must be a token for a user with Administrator access
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
@woganmay
woganmay / set-flarum-cookie.php
Created February 12, 2017 13:54
Set the flarum_remember cookie from a GET parameter
@woganmay
woganmay / index.php
Created February 12, 2017 13:56
Check for Flarum authentication before the main site even loads
<?php
if (isset($_COOKIE['flarum_remember']))
{
$mysql = new mysqli("localhost", "flarum_sql_user", "flarum_sql_pass", "flarum_database");
$result = $mysql->query("SELECT * FROM access_tokens WHERE id = '". $mysql->real_escape_string($_COOKIE['flarum_remember']) ."'");
if ($result->num_rows == 0)
{
// Invalid cookie
header('Location:https://my.laravel.site/login');
@woganmay
woganmay / custom-header.html
Created February 12, 2017 13:59
Modify the Flarum UI
<script type="text/javascript">
var thisHackInterval = setInterval(function(){
// Check if app is available yet
if (typeof(app) == "object")
{
// Set app routes to whatever I need
// This will repaint the DOM automatically
app.routes.settings.path = "https://my.laravel.site/preferences";
<?php
// See: https://gist.github.com/woganmay/4c15a0f7c16e41ab3a3ea1a73c595bf9
$api_url = sprintf("https://my.flarum.site/api/users/%s/avatar", $user->id);
// See: https://gist.github.com/woganmay/88f15e96fc019657a0e594366403b5cf
$token = $session->token;
$ch = curl_init($api_url);
@woganmay
woganmay / upload-flarum-avatar.php
Created February 12, 2017 14:03
Upload a new avatar image to Flarum
<?php
// See: https://gist.github.com/woganmay/4c15a0f7c16e41ab3a3ea1a73c595bf9
$api_url = sprintf("https://my.flarum.site/api/users/%s/avatar", $user->id);
// See: https://gist.github.com/woganmay/88f15e96fc019657a0e594366403b5cf
$token = $session->token;
$avatar_file = "/storage/avatars/1234.jpg"; // Absolute path preferred
@woganmay
woganmay / sample.php
Last active February 19, 2017 07:25
Sample MailMessage
<?php
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Mail Subject')
->greeting('Hi, User!')
->line('A line before the big button')
->action('Action Button', url('/'))
@woganmay
woganmay / sample-mailable.php
Created February 19, 2017 07:30
Send basic templated email with Mailable
<?php
public function build()
{
return $this
->subject('Mail Subject')
->view('vendor.notifications.email')->with([
"level" => "default",
"greeting" => "Hi, User!",
"introLines" => [