Dealing with User Management

Jeremy

in memoriam 1991-2020
I am writing an add on that deals with user information. I want to lean on XenForo_DataWriter_User's _verifyUsername() function, but since it is protected, I cannot call XenForo_DataWriter_Users::_verifyUsername(); within my _verifyUsername() function, but I really don't want to rewrite / distribute the code 'as my own.' Should I extend this class, even though this is basically the only function I require from the XenForo_DataWriter_User class, so, best option here? My post, pre, and save functions are all separate, because it deals with my own table (well, ok, save will call XenForo_DataWriter_User to update the username eventually).
 
OK, I see that I can maybe use _publish() and _getPermissionModel() as my add on uses permissions and it'd be nice to maybe publish the results?
 
Does your method only need to be used by your modification? If so I'd extend the class and create a new method like "_myVerifyUsername()" which calls the parent and then your validation:

PHP:
protected function _myVerifyUsername($username)
{
	if (!parent::_verifyUsername($username))
	{
		return false;
	}

	// your checks here

	return true;
}
 
Does your method only need to be used by your modification? If so I'd extend the class and create a new method like "_myVerifyUsername()" which calls the parent and then your validation:

PHP:
protected function _myVerifyUsername($username)
{
	if (parent::_verifyUsername($username))
	{
		// do checks here
	}

	return true;
}

Basically, I just want to mimic that functionality. So, basically _myVerifyUsername = _verifyUsername. Hence the choice to extend that class. I think that might be the best choice, but not sure with this whole MVC thing.
 
I updated my previous post, I had some dumb code (didn't return false if the parent came back false). Extending then calling the parent seems like the best approach in my opinion :)

If you don't want to add anything to the method, you should still be able to call _verifyUsername() from your extended class as normal, no?
 
I should be able to, but I defined a _usernameRequestVerifyUsername($username) because I am using the array('$this', 'functionName') setup for verification, so... I just used that and...
PHP:
	/**
	* Verifies the username against administrator defined criteria.
	*
	* @return boolean
	*/
	protected function _usernameRequestVerifyUsername($username)
	{
		return parent::_verifyUsername($username);
	}
 
Yeah, I got those. :) I just am not sure how to use parent:: within this code:
PHP:
				'requested_name'
					=> array('type' => self::TYPE_STRING, 'required' => true, 'maxLength' => XenForo_Application::get('options')->usernameLengthMax, 'verification' => array('$this', '_usernameRequestVerifyUsername'), 'requiredError' => 'please_enter_valid_name'),

And I am not feeling like looking it up, so I made my own function in the $this class, to call the parent::.
 
Nope, I need my username verification, there's one or two more verifications I want to include... Solves that problem. :P Now, I just gotta figure out error messages. Does $this->errors[] work?
 
It's stored in the array _errors under the DataWriter class, you can access the array via: $class->getErrors() :)
 
Back
Top Bottom