Jump to content

Approve Account Creation


Makke_
Go to solution Solved by Makke_,

Recommended Posts

Hi everyone!
 

What I am going to ask is for me a wery big thing.
I have tried for weeks to get this thing working, but I have no PHP coding skills so I can´t fix this myself.

I´m trying to decline login to our MediaWiki if an admin not approved the account.
What I was thing was that I created a new column in user table in the database called approved_account.
I configured the field so that when a new user is created they will get value "0".

I then want to in login process check if that field for that user contains a "0" (zero), if it do they should not be allowed to logg in.
IF (approved_account = '0') then deny logg in.

 

Is there someone out there that knows how to create this kind of extension?
I have looked for already existing extensions like ConfirmAccount but they require email functionallity which our Wiki doesn´t support.

Would appreciate If someone would lika to be kind to help me with this request.

Link to comment
Share on other sites

I don´t have any coding skills to preform the task.
I created the column and named it approved_account.

I don´t know how to get the username from the session and then verify if the approved_Account value is "0" or not.
I copy pasted some information from different extensions givenn me below code snipp.
It doesn´t work but this is how my mind thinks, don´t know if this is on the way or not?

 

include("$IP/includes/SpecialUserlogout.php"); 
 
function Auth_remote_user_hook() 
{ 
global $wgUser; 
 
$wgUser = User::loadFromSession(); 
$username = strtolower($wgUser->getName()); 
$dbr = wfGetDB( DB_SLAVE ); 
$res = $dbr->select(user_name, approved_account FROM user WHERE user_name = $wgUser); 
if( approved_account = '0' ) { 
       wfSpecialUserLogout(); 
} 
}
Link to comment
Share on other sites

The only thing I can say is:

 

if( approved_account = '0' ) {
 

 

 

needs a dollar sign at the variable and two equal signs for comparing. so

 

 

if( $approved_account == '0' ) {

 

ONE equal sign is for SETTING a variable

TWO equal signs are for comparing

THREE are also for comparing, but more strict than 2.

 

Other than that, I have no experience with the PHP class you are using to handle SQL queries so I really couldnt tell.

Edited by DaveyK
Link to comment
Share on other sites

I have tried to read about extensions and hooks.
I´ve created below (as an extension I think).
Allthough it´s not working, giving me a blank page when implementing it to my MediaWiki.
Anyone famillier with MediaWiki Extension coding?
 

<?php

   $wgExtensionCredits['validextensionclass'][] = array(
       'path' => __FILE__,
       'name' => 'Approve Account',
       'author' =>'Markus', 
       'url' => 'https://www.mediawiki.org/wiki/Extension:Approve_Account', 
       'description' => 'This extension require admin to allow recently registered users to login',
       'version'  => 0.1,
       );

	   $wgHooks['AddNewAccount'][] = 'approve_accountHooks::onAddNewAccount';

		$user = User::loadFromSession();
		$dbr = wfGetDB( DB_SLAVE );
		$res = $dbr->select(user_name, approved_account FROM user WHERE user_name = $user);
		if( approved_account == '0' {
			
		}	
	}
Link to comment
Share on other sites

I´m currently working on below code.
Would appreciate feedback and help.
I don´t know if it fetches the values from the database.
I am not able to print it.

 

<?php
/** 
 * Prevent a user from accessing this file directly and provide a helpful 
 * message explaining how to install this extension.
 */
if ( !defined( 'MEDIAWIKI' ) ) {
    	echo <<<EOT
To install the Test extension, put the following line in your 
LocalSettings.php file: 
require_once( "\$IP/extensions/Test.php" );
EOT;
    	exit( 1 );
}

// Extension credits that will show up on Special:Version
$wgExtensionCredits[ 'other' ][] = array(
	'path' => __FILE__,
	'name' => 'Test',
	'author' =>'Your Name Here', 
	'url' => 'https://www.mediawiki.org/wiki/Extension:Test', 
	'description' => 'This extension is an Test extension',
	'version'  => 1.0,
);

// Find the full directory path of this extension
$current_dir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;

// Tell MediaWiki about the special page
$wgSpecialPages[ 'Test' ] = 'SpecialTest';

global $wgRequest;

class SpecialTest extends SpecialPage {
	
	function __construct() {
		parent::__construct( 'Test' );
	}
	
	/**
	 * Make your magic happen!
	 */	 
 
	function execute( $par ) {
		global $wgOut, $wgUser;

		$wgUser->getName();
		
		$dbr = wfGetDB( DB_SLAVE );
		$res = $dbr->select(
		'user',										// $table
		array( 'user_name', 'approved_account' ),	// $vars (columns of the table)
		'user_name = ".$wgUser."',					// $conds
		__METHOD__,									// $fname = 'Database::select',
		array( 'ORDER BY' => 'user_name ASC' )		// $options = array()
		);
		
		$output = '';
		foreach( $res as $row ) {
        $output .= 'Catgeory ' . $row->user_name . ' contains ' . $row->approved_account . " entries.\n";
		}

		$wgOut->addHTML('Hej '.$wgUser.'.');	

	}
}
Link to comment
Share on other sites

  • Solution

Seems like following part of the code isn´t working.

'user_name = ".$wgUser."',

If a write a specific user like 'user_name = "admin". It will fetch the information for Admin user.
How should above code be written? i now $wgUser conatines value. I managed to print that information before.
$wgOut->addHTML(''.$wgUser.'.');

I can then write it by using below code :

 

<?php
/** 
 * Prevent a user from accessing this file directly and provide a helpful
 * message explaining how to install this extension.
 */
if ( !defined( 'MEDIAWIKI' ) ) {
    	echo <<<EOT
To install the Test extension, put the following line in your
LocalSettings.php file: 
require_once( "\$IP/extensions/Test.php" );
EOT;
    	exit( 1 );
}
// Extension credits that will show up on Special:Version
$wgExtensionCredits[ 'other' ][] = array(
	'path' => __FILE__,
	'name' => 'Test',
	'author' =>'Your Name Here',
	'url' => 'https://www.mediawiki.org/wiki/Extension:Test',
	'description' => 'This extension is an Test extension',
	'version'  => 1.0,
);
// Find the full directory path of this extension
$current_dir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
// Tell MediaWiki about the special page
$wgSpecialPages[ 'Test' ] = 'SpecialTest';
global $wgRequest;
class SpecialTest extends SpecialPage {	
	function __construct() {
		parent::__construct( 'Test' );
	}	
	/**
	 * Make your magic happen!
	 */
	function execute( $par ) {
		global $wgOut, $wgUser;
		$wgUser->getName();		
		$dbr = wfGetDB( DB_SLAVE );
		$res = $dbr->select(
		'user',						// $table
		array( 'user_name', 'approved_account' ),	// $vars (columns of the table)
		'user_name = ".$wgUser."',			// $conds
		__METHOD__,					// $fname = 'Database::select',
		array( 'ORDER BY' => 'user_name ASC' )		// $options = array()
		);
	
		$output = '';
		foreach( $res as $row ) {
		$output .= 'Catgeory ' . $row->user_name . ' contains ' . $row->approved_account . " entries.\n";
		}
		$wgOut->addHTML(''.$output.'.');
	}
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.