Auto Registration ?
Imran Offline
Member
***
Posts: 204
Joined: Apr 2010
Post: #1
Question Auto Registration ?
Hello Zinga .

I want to know about Auto registrations after every predefined intervals. Means If I select 15 minutes , the task can run and an registration made automatically.

We can use a list of usernames (arranged in an array) to manipulate so that the Sheduler picks up the usernames from the array randomly and start to make registrations.

I search member.php file of MyBB, and get the following code that give an hint and an idea for this:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
if($mybb->input['action'] == "do_register" && $mybb->request_method == "post")
{
	if($mybb->settings['regtype'] == "randompass")
	{
		$mybb->input['password'] = random_str();
		$mybb->input['password2'] = $mybb->input['password'];
	}

	if($mybb->settings['regtype'] == "verify" || $mybb->settings['regtype'] == "admin" || $mybb->input['coppa'] == 1)
	{
		$usergroup = 5;
	}
	else
	{
		$usergroup = 2;
	}

	// Set up user handler.
	require_once MYBB_ROOT."inc/datahandlers/user.php";
	$userhandler = new UserDataHandler("insert");

	// Set the data for the new user.
	$user = array(
		"username" => $mybb->input['username'],
		"password" => $mybb->input['password'],
		"password2" => $mybb->input['password2'],
		"email" => $mybb->input['email'],
		"email2" => $mybb->input['email2'],
		"usergroup" => $usergroup,
		"referrer" => $mybb->input['referrername'],
		"timezone" => $mybb->input['timezoneoffset'],
		"language" => $mybb->input['language'],
		"profile_fields" => $mybb->input['profile_fields'],
		"regip" => $session->ipaddress,
		"longregip" => my_ip2long($session->ipaddress),
		"coppa_user" => intval($mybb->cookies['coppauser']),
	);
	
	if(isset($mybb->input['regcheck1']) && isset($mybb->input['regcheck2']))
	{
		$user['regcheck1'] = $mybb->input['regcheck1'];
		$user['regcheck2'] = $mybb->input['regcheck2'];
	}

	// Do we have a saved COPPA DOB?
	if($mybb->cookies['coppadob'])
	{
		list($dob_day, $dob_month, $dob_year) = explode("-", $mybb->cookies['coppadob']);
		$user['birthday'] = array(
			"day" => $dob_day,
			"month" => $dob_month,
			"year" => $dob_year
		);
	}

	$user['options'] = array(
		"allownotices" => $mybb->input['allownotices'],
		"hideemail" => $mybb->input['hideemail'],
		"subscriptionmethod" => $mybb->input['subscriptionmethod'],
		"receivepms" => $mybb->input['receivepms'],
		"pmnotice" => $mybb->input['pmnotice'],
		"emailpmnotify" => $mybb->input['emailpmnotify'],
		"invisible" => $mybb->input['invisible'],
		"dstcorrection" => $mybb->input['dstcorrection']
	);

	$userhandler->set_data($user);

	$errors = "";

	if(!$userhandler->validate_user())
	{
		$errors = $userhandler->get_friendly_errors();
	}


Can you help me, how to insert the values in db and how to make a fake user with this ? Zinga Eyes


[Image: logo.png]

[Image: twitter.png]
08-16-2010 06:30 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: Auto Registration ?
You're probably better off looking at the create user section in the AdminCP.

But otherwise, the above shouldn't be difficult to understand.  You create an array containing the info of the user to be created, then pass it to the userhandler which validates and inserts the user for you.

My Blog
08-16-2010 08:12 AM
Find all posts by this user Quote this message in a reply
Imran Offline
Member
***
Posts: 204
Joined: Apr 2010
Post: #3
RE: Auto Registration ?
Hmm .. Can you please re-code the above snippet Zinga ?

[Image: logo.png]

[Image: twitter.png]
08-17-2010 01:24 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: Auto Registration ?
Which part are you struggling with?

My Blog
08-17-2010 07:11 AM
Find all posts by this user Quote this message in a reply
Imran Offline
Member
***
Posts: 204
Joined: Apr 2010
Post: #5
RE: Auto Registration ?
I want to get username from a list of usernames in an array and pick them randomly. Then it process creating the user and insert it into the database. Moreover, there should be an option as to how many users should be created by picking the names of that array list.

Okay, one thing I found in admin/modules/user/users.php file

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
if($mybb->input['action'] == "add")
{
	$plugins->run_hooks("admin_user_users_add");
	
	if($mybb->request_method == "post")
	{
		// Determine the usergroup stuff
		if(is_array($mybb->input['additionalgroups']))
		{
			foreach($mybb->input['additionalgroups'] as $key => $gid)
			{
				if($gid == $mybb->input['usergroup'])
				{
					unset($mybb->input['additionalgroups'][$key]);
				}
			}
			$additionalgroups = implode(",", $mybb->input['additionalgroups']);
		}
		else
		{
			$additionalgroups = '';
		}

		// Set up user handler.
		require_once MYBB_ROOT."inc/datahandlers/user.php";
		$userhandler = new UserDataHandler('insert');

		// Set the data for the new user.
		$new_user = array(
			"uid" => $mybb->input['uid'],
			"username" => $mybb->input['username'],
			"password" => $mybb->input['password'],
			"password2" => $mybb->input['confirm_password'],
			"email" => $mybb->input['email'],
			"email2" => $mybb->input['email'],
			"usergroup" => $mybb->input['usergroup'],
			"additionalgroups" => $additionalgroups,
			"displaygroup" => $mybb->input['displaygroup'],
			"profile_fields" => $mybb->input['profile_fields'],
			"profile_fields_editable" => true,
		);

		// Set the data of the user in the datahandler.
		$userhandler->set_data($new_user);
		$errors = '';

		// Validate the user and get any errors that might have occurred.
		if(!$userhandler->validate_user())
		{
			$errors = $userhandler->get_friendly_errors();
		}
		else
		{
			$user_info = $userhandler->insert_user();
			
			$plugins->run_hooks("admin_user_users_add_commit");
			
			// Log admin action
			log_admin_action($user_info['uid'], $user_info['username']);

			flash_message($lang->success_user_created, 'success');
			admin_redirect("index.php?module=user-users&action=edit&uid={$user_info['uid']}");
		}
	}
}


This is hard for me to understand. Frown Help Yumi !


[Image: logo.png]

[Image: twitter.png]
08-17-2010 10:12 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #6
RE: Auto Registration ?
You've got to state what you're having trouble with.

There's a number of components in what you're trying to do:
  • randomly pick something from an array
  • creating the user (you don't need to insert it into the database)
  • the option you want

(08-17-2010 10:12 AM)Imran Wrote:  This is hard for me to understand. Frown Help Yumi !
Why?  If you understand PHP, it's just a matter of breaking things down.
It's fairly logical what the code does
  • if we're adding a user...
  • run plugin hooks
  • if we've come from a POST request
  • determine usergroup stuff
  • set up userhandler
  • set data for userhandler
  • validate
  • if validated, log action and redirect admin

My Blog
08-17-2010 01:45 PM
Find all posts by this user Quote this message in a reply
Imran Offline
Member
***
Posts: 204
Joined: Apr 2010
Post: #7
RE: Auto Registration ?
Imran Wrote:This is hard for me to understand. Frown Help Yumi !

I mean its hard for me to pick a username from an array randomly. I require you to edit the above snippet and add / edit the code so that the function runs. Ouch

[Image: logo.png]

[Image: twitter.png]
08-17-2010 05:25 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #8
RE: Auto Registration ?
You can't use the above code directly for what you're trying to do (unless you're trying to completely replicate the AdminCP interface or similar).  It's up to you to adapt it to your needs, I'm not going to do that for you.  I don't code plugin requests, neither do I code plugins or most of a plugin for someone.  I'm willing to give advice, explain concepts, or find faults, but I'm generally not going to actually do any coding work (beyond demonstrating principles).
If you're struggling to understand such a piece of code, I strongly suggest trying to understand PHP more thoroughly.  Otherwise, you're just going to keep having issues, and you're going to keep asking, and it's not going to be beneficial to anyone.


Randomly selecting a name is easy if you don't mind it being truly random (ie, possible for the same name to be picked more than once).

PHP Code:
$selected_element =& $my_array[mt_rand(0, count($my_array)-1)];

If you want random elements to be never be picked twice, across multiple calls, you'll need some persistence, such as storing the array somewhere and removing chosen elements when you pick them.

You could set up an array of arrays containing the user data you want, then your code will pick one of these arrays, and send it directly to the userhandler.  This is probably one of the easier aspects for MyBB as well...

Hope that helps.


My Blog
(This post was last modified: 08-17-2010 07:00 PM by ZiNgA BuRgA.)
08-17-2010 07:00 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: