News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Registration API

Started by BrianE, September 14, 2024, 12:26:20 PM

Previous topic - Next topic

BrianE

As MemSec for a society I have to do registrations for the Forum as only members of the Society are allowed to use our forum. It's a bit of a pain doing the registrations and an API would make life a lot easier. I use APIs for Woedpress and GoCardless already and one for the forum seems to be sadly missing. Any thoughts?

Kindred

Be more specific?

What would you expect this API to do?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

BrianE

To be specific:

The registration requires Username, Email address, Password, and a couple of booleans. Sending those to a URL with a POST or PUT, authentication as required, using a JSON payload would be very helpful. A similar API for changing passwords would also be welcome. Of course, once you start creating an API there's no end to what it could do!

Arantor

What exactly do the booleans mean? They may not have a direct analogue to anything currently in SMF.
Holder of controversial views, all of which my own.

BrianE

The booleans are just the two checkboxes:

Email new password to user
Require user to activate the account

BrianE

OK, so nobody has anything to add. Well, I have found a way round it: by injecting some js scripts. It's a bit of a pain but there is a good side. I have had to learn how to load web pages into a home-grown browser window and how to use javascript. Still a shame there's no API, though.

Arantor

Some of us have been working 12 hour shifts for the last few weeks and may not always have time to respond with anything in great technical detail.
Holder of controversial views, all of which my own.

vbgamer45

You can also write your own script to include SSI.php

Then call Sources/Subs-Members.php registermember function
https://support.simplemachines.org/function_db/index.php?action=view_function;id=594


Also, have some mods that deal with this in wordpress.
SMF2WPBridge
https://custom.simplemachines.org/index.php?mod=4256
WP2SMFBridge
https://github.com/xchwarze/WP2SMFBridge/blob/master/bridge.php
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

BrianE

vbgamer45, thank you for your response. I have looked at the stuff you have pointed to and although I can appreciate the structure and intention I'm afraid that implementing it all is going to be too much for my aging brain. If there were some way of using Postman to send the required data I'd love to know how  because I can create POSTs myself and structure data however it is required. I will certainly admit to ignorance regarding how to use those various functions so I guess I'd better find a tutorial - once I've worked out what to look for.

vbgamer45

There is currently no builtin restful api.  But you could build a ssi simple page  then take in the parameters via POST/GET and call the register function
Create a php script like the following (untested) save in root of your smf install. SMF 2.1.x
global $ssi_guest_access;
$ssi_guest_access = 1;
// Check if access allowed
/*
if ($_POST['somethinghere'] !== 'accesskey')
die("no access");
*/
require(dirname(__FILE__) . '/SSI.php');
require_once($sourcedir . '/Subs-Members.php');
$regOptions = array(
'interface' => 'guest',
'username' => !empty($_POST['user']) ? $_POST['user'] : '',
'email' => !empty($_POST['email']) ? $_POST['email'] : '',
'password' => !empty($_POST['passwrd1']) ? $_POST['passwrd1'] : '',
'password_check' => !empty($_POST['passwrd2']) ? $_POST['passwrd2'] : '',
'check_reserved_name' => true,
'check_password_strength' => true,
'check_email_ban' => true,
'send_welcome_email' => !empty($modSettings['send_welcomeEmail']),
'require' => !empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa']) ? 'coppa' : (empty($modSettings['registration_method']) ? 'nothing' : ($modSettings['registration_method'] == 1 ? 'activation' : 'approval')),
'extra_register_vars' => array(),
'theme_vars' => array(),
);

$memberID = registerMember($regOptions, true);

// Code to autologin/create cookie
// setLoginCookie(60 * $modSettings['cookieTime'], $memberID, hash_salt($regOptions['register_vars']['passwd'], $regOptions['register_vars']['password_salt']));



There was one made a community for SMF 2.0.x but requires some updates.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

BrianE

Cripes, PHP! C for servers, sort of. OK, w3schools here I come. Thanks again.

Advertisement: