Created
April 24, 2013 08:12
-
-
Save peterjaap/5450497 to your computer and use it in GitHub Desktop.
PHP script to create admin user for Magento
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 | |
error_reporting(E_ALL | E_STRICT); | |
require_once 'app/Mage.php'; | |
Mage::setIsDeveloperMode(true); | |
ini_set('display_errors', 1); | |
umask(0); | |
Mage::app(); | |
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID)); | |
$username = 'peterjaap';//desired username | |
$firstname = "Peter Jaap";//desired firstname | |
$lastname = "Blaakmeer";//desired lastname | |
$email = "[email protected]";//desired email | |
$pass = 'password_here';//desired password | |
$user = Mage::getModel('admin/user')->load($username, 'username'); | |
if ($user->getId()){ | |
echo "User {$username} already exists"; | |
exit; | |
} | |
$user->setUsername($username) | |
->setFirstname($firstname) | |
->setLastname($lastname) | |
->setEmail($email) | |
->setPassword($pass) | |
; | |
$result = $user->validate(); | |
if (is_array($result)){ | |
foreach ($result as $res){ | |
echo $res."\n"; | |
} | |
exit; | |
} | |
try{ | |
$user->setForceNewPassword(true); | |
$user->save(); | |
$user->setRoleIds(array(1))->saveRelations(); | |
echo "User {$username} was created"; | |
exit; | |
} catch (Exception $e){ | |
echo $e->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment