Added Super Admin role and WHMCS login
This commit is contained in:
parent
e5a74e7285
commit
7f6fc7770a
|
@ -7,13 +7,15 @@ $ccAcl = new Zend_Acl();
|
||||||
$ccAcl->addRole(new Zend_Acl_Role('G'))
|
$ccAcl->addRole(new Zend_Acl_Role('G'))
|
||||||
->addRole(new Zend_Acl_Role('H'), 'G')
|
->addRole(new Zend_Acl_Role('H'), 'G')
|
||||||
->addRole(new Zend_Acl_Role('P'), 'H')
|
->addRole(new Zend_Acl_Role('P'), 'H')
|
||||||
->addRole(new Zend_Acl_Role('A'), 'P');
|
->addRole(new Zend_Acl_Role('A'), 'P')
|
||||||
|
->addRole(new Zend_Acl_Role('S'), 'A');
|
||||||
|
|
||||||
$ccAcl->add(new Zend_Acl_Resource('library'))
|
$ccAcl->add(new Zend_Acl_Resource('library'))
|
||||||
->add(new Zend_Acl_Resource('index'))
|
->add(new Zend_Acl_Resource('index'))
|
||||||
->add(new Zend_Acl_Resource('user'))
|
->add(new Zend_Acl_Resource('user'))
|
||||||
->add(new Zend_Acl_Resource('error'))
|
->add(new Zend_Acl_Resource('error'))
|
||||||
->add(new Zend_Acl_Resource('login'))
|
->add(new Zend_Acl_Resource('login'))
|
||||||
|
->add(new Zend_Acl_Resource('whmcs-login'))
|
||||||
->add(new Zend_Acl_Resource('playlist'))
|
->add(new Zend_Acl_Resource('playlist'))
|
||||||
->add(new Zend_Acl_Resource('plupload'))
|
->add(new Zend_Acl_Resource('plupload'))
|
||||||
->add(new Zend_Acl_Resource('schedule'))
|
->add(new Zend_Acl_Resource('schedule'))
|
||||||
|
@ -34,6 +36,7 @@ $ccAcl->add(new Zend_Acl_Resource('library'))
|
||||||
/** Creating permissions */
|
/** Creating permissions */
|
||||||
$ccAcl->allow('G', 'index')
|
$ccAcl->allow('G', 'index')
|
||||||
->allow('G', 'login')
|
->allow('G', 'login')
|
||||||
|
->allow('G', 'whmcs-login')
|
||||||
->allow('G', 'error')
|
->allow('G', 'error')
|
||||||
->allow('G', 'user', 'edit-user')
|
->allow('G', 'user', 'edit-user')
|
||||||
->allow('G', 'showbuilder')
|
->allow('G', 'showbuilder')
|
||||||
|
|
|
@ -16,7 +16,6 @@ class LoginController extends Zend_Controller_Action
|
||||||
Application_Model_Locale::configureLocalization($request->getcookie('airtime_locale', 'en_CA'));
|
Application_Model_Locale::configureLocalization($request->getcookie('airtime_locale', 'en_CA'));
|
||||||
if (Zend_Auth::getInstance()->hasIdentity())
|
if (Zend_Auth::getInstance()->hasIdentity())
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->_redirect('Showbuilder');
|
$this->_redirect('Showbuilder');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,9 @@ class UserController extends Zend_Controller_Action
|
||||||
if ($formData['password'] != "xxxxxx") {
|
if ($formData['password'] != "xxxxxx") {
|
||||||
$user->setPassword($formData['password']);
|
$user->setPassword($formData['password']);
|
||||||
}
|
}
|
||||||
$user->setType($formData['type']);
|
if (array_key_exists('type', $formData)) {
|
||||||
|
$user->setType($formData['type']);
|
||||||
|
}
|
||||||
$user->setEmail($formData['email']);
|
$user->setEmail($formData['email']);
|
||||||
$user->setCellPhone($formData['cell_phone']);
|
$user->setCellPhone($formData['cell_phone']);
|
||||||
$user->setSkype($formData['skype']);
|
$user->setSkype($formData['skype']);
|
||||||
|
|
|
@ -0,0 +1,176 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
define("WHMCS_API_URL", "https://account.sourcefabric.com/includes/api.php");
|
||||||
|
|
||||||
|
class WhmcsLoginController extends Zend_Controller_Action
|
||||||
|
{
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function indexAction()
|
||||||
|
{
|
||||||
|
$CC_CONFIG = Config::getConfig();
|
||||||
|
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$this->view->layout()->disableLayout();
|
||||||
|
$this->_helper->viewRenderer->setNoRender(true);
|
||||||
|
|
||||||
|
$username = "admin";
|
||||||
|
$email = $_POST["email"];
|
||||||
|
$password = $_POST["password"];
|
||||||
|
|
||||||
|
Application_Model_Locale::configureLocalization($request->getcookie('airtime_locale', 'en_CA'));
|
||||||
|
if (Zend_Auth::getInstance()->hasIdentity())
|
||||||
|
{
|
||||||
|
$this->_redirect('Showbuilder');
|
||||||
|
}
|
||||||
|
|
||||||
|
$authAdapter = new WHMCS_Auth_Adapter($username, $email, $password);
|
||||||
|
|
||||||
|
$auth = Zend_Auth::getInstance();
|
||||||
|
$result = $auth->authenticate($authAdapter);
|
||||||
|
if ($result->isValid()) {
|
||||||
|
//all info about this user from the login table omit only the password
|
||||||
|
//$userInfo = $authAdapter->getResultRowObject(null, 'password');
|
||||||
|
|
||||||
|
//the default storage is a session with namespace Zend_Auth
|
||||||
|
/*
|
||||||
|
[id] => 1
|
||||||
|
[login] => admin
|
||||||
|
[pass] => hashed password
|
||||||
|
[type] => A
|
||||||
|
[first_name] =>
|
||||||
|
[last_name] =>
|
||||||
|
[lastlogin] =>
|
||||||
|
[lastfail] =>
|
||||||
|
[skype_contact] =>
|
||||||
|
[jabber_contact] =>
|
||||||
|
[email] => asdfasdf@asdasdf.com
|
||||||
|
[cell_phone] =>
|
||||||
|
[login_attempts] => 0
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Zend_Auth already does this for us, it's not needed:
|
||||||
|
//$authStorage = $auth->getStorage();
|
||||||
|
//$authStorage->write($result->getIdentity()); //$userInfo);
|
||||||
|
|
||||||
|
//set the user locale in case user changed it in when logging in
|
||||||
|
//$locale = $form->getValue('locale');
|
||||||
|
//Application_Model_Preference::SetUserLocale($locale);
|
||||||
|
|
||||||
|
$this->_redirect('Showbuilder');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo("Sorry, that username or password was incorrect.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class WHMCS_Auth_Adapter implements Zend_Auth_Adapter_Interface {
|
||||||
|
private $username;
|
||||||
|
private $password;
|
||||||
|
private $email;
|
||||||
|
|
||||||
|
function __construct($username, $email, $password) {
|
||||||
|
$this->username = $username;
|
||||||
|
$this->password = $password;
|
||||||
|
$this->email = $email;
|
||||||
|
$this->identity = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function authenticate() {
|
||||||
|
if (!$this->validateCredentialsWithWHMCS($this->email, $this->password))
|
||||||
|
{
|
||||||
|
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
$identity = array();
|
||||||
|
|
||||||
|
//TODO: Get identity of the first admin user!
|
||||||
|
|
||||||
|
/*
|
||||||
|
$identity["id"] = 1;
|
||||||
|
$identity["type"] = "S";
|
||||||
|
$identity["login"] = $this->username; //admin";
|
||||||
|
$identity["email"] = $this->email;*/
|
||||||
|
$identity = $this->getSuperAdminIdentity();
|
||||||
|
if (is_null($identity)) {
|
||||||
|
Logging::error("No super admin user found");
|
||||||
|
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null);
|
||||||
|
}
|
||||||
|
$identity = (object)$identity; //Convert the array into an stdClass object
|
||||||
|
|
||||||
|
try {
|
||||||
|
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// exception occured
|
||||||
|
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getSuperAdminIdentity()
|
||||||
|
{
|
||||||
|
$firstSuperAdminUser = CcSubjsQuery::create()
|
||||||
|
->filterByDbType('S')
|
||||||
|
->orderByDbId()
|
||||||
|
->findOne();
|
||||||
|
if (!$firstSuperAdminUser) {
|
||||||
|
//If there's no super admin users, get the first regular admin user!
|
||||||
|
$firstSuperAdminUser = CcSubjsQuery::create()
|
||||||
|
->filterByDbType('A')
|
||||||
|
->orderByDbId()
|
||||||
|
->findOne();
|
||||||
|
if (!$firstSuperAdminUser) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$identity["id"] = $firstSuperAdminUser->getDbId();
|
||||||
|
$identity["type"] = "S"; //Super Admin
|
||||||
|
$identity["login"] = $firstSuperAdminUser->getDbLogin();
|
||||||
|
$identity["email"] = $this->email;
|
||||||
|
return $identity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validateCredentialsWithWHMCS($email, $password)
|
||||||
|
{
|
||||||
|
$client_postfields = array();
|
||||||
|
$client_postfields["username"] = $_SERVER['WHMCS_USERNAME']; //WHMCS API username
|
||||||
|
$client_postfields["password"] = md5($_SERVER['WHMCS_PASSWORD']); //WHMCS API password
|
||||||
|
$client_postfields["action"] ="validatelogin";
|
||||||
|
$client_postfields["responsetype"] = "json";
|
||||||
|
|
||||||
|
$client_postfields["email"] = $email;
|
||||||
|
$client_postfields["password2"] = $password;
|
||||||
|
|
||||||
|
$query_string = "";
|
||||||
|
foreach ($client_postfields as $k => $v) $query_string .= "$k=".urlencode($v)."&";
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, WHMCS_API_URL);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||||
|
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||||
|
$jsondata = curl_exec($ch);
|
||||||
|
if (curl_error($ch)) {
|
||||||
|
die(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
|
||||||
|
//die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
|
||||||
|
}
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
$arr = json_decode($jsondata, true); # Decode JSON String
|
||||||
|
|
||||||
|
if ($arr["result"] != "success") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -117,8 +117,7 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($controller, array("api", "auth", "locale", "upgrade"))) {
|
if (in_array($controller, array("api", "auth", "locale", "upgrade", 'whmcs-login'))) {
|
||||||
|
|
||||||
$this->setRoleName("G");
|
$this->setRoleName("G");
|
||||||
} elseif (!Zend_Auth::getInstance()->hasIdentity()) {
|
} elseif (!Zend_Auth::getInstance()->hasIdentity()) {
|
||||||
|
|
||||||
|
|
|
@ -95,9 +95,9 @@ class Application_Form_AddUser extends Zend_Form
|
||||||
"G" => _("Guest"),
|
"G" => _("Guest"),
|
||||||
"H" => _("DJ"),
|
"H" => _("DJ"),
|
||||||
"P" => _("Program Manager"),
|
"P" => _("Program Manager"),
|
||||||
"A" => _("Admin")
|
"A" => _("Admin"),
|
||||||
));
|
));
|
||||||
$select->setRequired(true);
|
$select->setRequired(false);
|
||||||
$this->addElement($select);
|
$this->addElement($select);
|
||||||
|
|
||||||
$saveBtn = new Zend_Form_Element_Button('save_user');
|
$saveBtn = new Zend_Form_Element_Button('save_user');
|
||||||
|
|
|
@ -6,7 +6,7 @@ class Application_Model_Preference
|
||||||
{
|
{
|
||||||
|
|
||||||
private static function getUserId()
|
private static function getUserId()
|
||||||
{
|
{
|
||||||
//pass in true so the check is made with the autoloader
|
//pass in true so the check is made with the autoloader
|
||||||
//we need this check because saas calls this function from outside Zend
|
//we need this check because saas calls this function from outside Zend
|
||||||
if (!class_exists("Zend_Auth", true) || !Zend_Auth::getInstance()->hasIdentity()) {
|
if (!class_exists("Zend_Auth", true) || !Zend_Auth::getInstance()->hasIdentity()) {
|
||||||
|
|
|
@ -23,6 +23,12 @@ function populateForm(entries){
|
||||||
$('#password').val("");
|
$('#password').val("");
|
||||||
$('#passwordVerify').val("");
|
$('#passwordVerify').val("");
|
||||||
}
|
}
|
||||||
|
if (entries.login === 'admin')
|
||||||
|
{
|
||||||
|
$('#type').attr('disabled', '1');
|
||||||
|
} else {
|
||||||
|
$('#type').removeAttr('disabled');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function rowClickCallback(row_id){
|
function rowClickCallback(row_id){
|
||||||
|
@ -57,6 +63,9 @@ function rowCallback( nRow, aData, iDisplayIndex ){
|
||||||
} else if ( aData['type'] == "P" )
|
} else if ( aData['type'] == "P" )
|
||||||
{
|
{
|
||||||
$('td:eq(3)', nRow).html( $.i18n._('Program Manager') );
|
$('td:eq(3)', nRow).html( $.i18n._('Program Manager') );
|
||||||
|
} else if ( aData['type'] == "S" )
|
||||||
|
{
|
||||||
|
$('td:eq(3)', nRow).html( $.i18n._('Super Admin') );
|
||||||
}
|
}
|
||||||
|
|
||||||
return nRow;
|
return nRow;
|
||||||
|
@ -183,7 +192,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
var newUser = {login:"", first_name:"", last_name:"", type:"G", id:""};
|
var newUser = {login:"", first_name:"", last_name:"", type:"G", id:""};
|
||||||
|
|
||||||
$('#add_user_button').live('click', function(){populateForm(newUser)});
|
$('#add_user_button').live('click', function(){populateForm(newUser);});
|
||||||
|
|
||||||
$('#save_user').live('click', function(){
|
$('#save_user').live('click', function(){
|
||||||
var data = $('#user_form').serialize();
|
var data = $('#user_form').serialize();
|
||||||
|
|
Loading…
Reference in New Issue