Created
June 4, 2015 16:57
-
-
Save litzinger/48be5876d6bba1509323 to your computer and use it in GitHub Desktop.
Create a Magento user via PHP script to get into admin area.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define( 'USERNAME', 'new.user' ); | |
define( 'PASSWORD', 'password' ); | |
define( 'FIRSTNAME', 'Excited' ); | |
define( 'LASTNAME', 'Croc' ); | |
define( 'EMAIL', '[email protected]' ); | |
include_once( 'app/Mage.php' ); | |
Mage::app( 'admin' ); | |
try { | |
$adminUserModel = Mage::getModel( 'admin/user' ); | |
$adminUserModel->setUsername( USERNAME ) | |
->setFirstname( FIRSTNAME ) | |
->setLastname( LASTNAME ) | |
->setEmail( EMAIL ) | |
->setNewPassword( PASSWORD ) | |
->setPasswordConfirmation( PASSWORD ) | |
->setIsActive( true ) | |
->save(); | |
$adminUserModel->setRoleIds( array( 1 ) ) | |
->setRoleUserId( $adminUserModel->getUserId() ) | |
->saveRelations(); | |
echo 'User created.'; | |
} catch( Exception $e ) { | |
echo $e->getMessage(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
php -f create-magento-user.php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment