Author: Miles Johnson - www.milesj.me
Inheritance: extends ForumAppModel
 public function __construct()
 {
     parent::__construct('authorize_new_users');
     if ($this->loginError) {
         return;
     }
     $this->loadHttpVars(true, true);
     $this->users = pdUserList::getNotVerified($this->db);
     echo '<h2>Users Requiring Authentication</h2>';
     if ($this->users == null || count($this->users) == 0) {
         echo 'All users authorized.';
         return;
     }
     $form = new HTML_QuickForm('authorizeUsers', 'post');
     foreach ($this->users as $user) {
         $form->addGroup(array(HTML_QuickForm::createElement('advcheckbox', "submit[auth][{$user->login}]", null, null, null, array('no', 'yes')), HTML_QuickForm::createElement('select', "submit[access][{$user->login}]", null, AccessLevel::getAccessLevels()), HTML_QuickForm::createElement('static', null, null, $user->login), HTML_QuickForm::createElement('static', null, null, $user->name), HTML_QuickForm::createElement('static', null, null, $user->email)), 'all', null, '</td><td class="stats_odd">', false);
     }
     $form->addElement('submit', null, 'Submit');
     $this->form =& $form;
     if ($form->validate()) {
         $this->processForm();
     } else {
         $this->renderForm();
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //
     $shop_id = $this->argument('shop');
     if (!$shop_id) {
         return $this->error('You must provide a shop ID.');
     }
     $shop = Shop::where('id', $shop_id)->first();
     if (!$shop) {
         return $this->error('The shop ID you provided is invalid.');
     }
     $access_title = $this->argument('access_title');
     if (!$access_title) {
         $access_title = 'Free';
     }
     $accessLevel = AccessLevel::where('title', $access_title)->first();
     if (!$accessLevel) {
         return $this->error('The access level you provided is invalid.');
     }
     $apiKey = new ApiKey();
     $apiKey->shop_id = $shop_id;
     $apiKey->public_key = Hash::make($shop_id . 'REMEDY');
     $apiKey->access_level_id = $accessLevel->id;
     $apiKey->save();
     $this->info('The generated API key is:');
     return $this->info($apiKey->public_key);
 }
Example #3
0
 public function run()
 {
     $seedData = [['title' => 'Administrator', 'level' => 1337, 'request_limit' => 9999999, 'interval_type' => 'second', 'interval_value' => 1], ['title' => 'Free', 'level' => 1, 'request_limit' => 1000, 'interval_type' => 'hour', 'interval_value' => 1], ['title' => 'Free Plus', 'level' => 2, 'request_limit' => 5000, 'interval_type' => 'hour', 'interval_value' => 1], ['title' => 'Bronze', 'level' => 3, 'request_limit' => 10000, 'interval_type' => 'hour', 'interval_value' => 1], ['title' => 'Gold', 'level' => 4, 'request_limit' => 5000, 'interval_type' => 'minute', 'interval_value' => 1], ['title' => 'Platinum', 'level' => 5, 'request_limit' => 10000, 'interval_type' => 'minute', 'interval_value' => 1], ['title' => 'Enterprise', 'level' => 5, 'request_limit' => 500, 'interval_type' => 'second', 'interval_value' => 1], ['title' => 'Enterprise Plus', 'level' => 5, 'request_limit' => 5000, 'interval_type' => 'second', 'interval_value' => 1]];
     $count = AccessLevel::all()->count();
     if (!$count) {
         DB::table('api_access_levels')->delete();
         foreach ($seedData as $access) {
             $accessLevel = new AccessLevel();
             $accessLevel->level = $access['level'];
             $accessLevel->title = $access['title'];
             $accessLevel->request_limit = $access['request_limit'];
             $accessLevel->interval_type = $access['interval_type'];
             $accessLevel->interval_value = $access['interval_value'];
             $accessLevel->save();
         }
     }
 }
 /**
  * Main Controller Method for Shopify Authorization
  */
 public function installOrAuthenticate()
 {
     if (Input::get('code')) {
         // New install
         Log::info('New Install: ' . Input::get('shop'));
         $sh = App::make('ShopifyAPI', ['API_KEY' => Config::get('shopify.APP_API_KEY'), 'API_SECRET' => Config::get('shopify.APP_API_SECRET'), 'SHOP_DOMAIN' => Input::get('shop')]);
         // Get Access Token
         try {
             $accessToken = $sh->getAccessToken(Input::get('code'));
         } catch (Exception $e) {
             Log::error($e->getMessage());
             die('<pre>Error: ' . $e->getMessage() . '</pre>');
         }
         $shop = Shop::where('domain', Input::get('shop'))->first();
         if (!$shop) {
             //Log::info(__LINE__ . ': New Shop');
             $shop = new Shop();
         }
         $shop->setDomain(Input::get('shop'));
         $shop->setAccessToken($accessToken);
         $shop->save();
         $this->updateShopInfo($shop);
         /**
          * Create the shop's first api key automatically, on install
          */
         $apiKey = new ApiKey();
         $apiKey->shop_id = $shop->id;
         $apiKey->public_key = Hash::make($shop->id . 'REMEDY');
         $apiKey->access_level_id = AccessLevel::where('title', 'Free Plus')->first()->id;
         $apiKey->save();
         /**
          * Create webhook for uninstall
          */
         $hookData = array('webhook' => array('topic' => 'app/uninstalled', 'address' => 'https://' . $_ENV['HOST'] . '/uninstall-hook', 'format' => 'json'));
         try {
             $sh->setup(['ACCESS_TOKEN' => $shop->getAccessToken()]);
             $sh->call(['URL' => 'webhooks.json', 'METHOD' => 'POST', 'DATA' => $hookData]);
         } catch (Exception $e) {
             Log::error('Issue creating uninstall webhook - ' . $shop->domain . ' : ' . $e->getMessage());
         }
         Session::put('shop', $shop->domain);
         return Redirect::to('/');
     } else {
         // Accessing app from apps screen
         $shop = Shop::where('domain', Input::get('shop'))->first();
         if ($shop) {
             Log::info('Shop found after Auth: ' . Input::get('shop'));
             $this->updateShopInfo($shop);
             Session::put('shop', Input::get('shop'));
             return Redirect::to('/');
         } else {
             Log::warning('Shop redirecting to install: ' . Input::get('shop'));
             $sh = App::make('ShopifyAPI', ['API_KEY' => Config::get('shopify.APP_API_KEY'), 'SHOP_DOMAIN' => Input::get('shop')]);
             return Redirect::to($sh->installURL(['permissions' => Config::get('shopify.APP_API_SCOPE'), 'redirect' => 'https://' . $_ENV['HOST'] . '/auth']));
         }
     }
 }
Example #5
0
 public function __construct()
 {
     parent::__construct('auth_success', 'Authorization Success', 'Admin/auth_success.php');
     if ($this->loginError) {
         return;
     }
     echo "<h2>Authorization Successful</h2>" . "\n<p>The following users have been granted access.</p>";
     $table = new HTML_Table(array('class' => 'stats'));
     $table->addRow(array('Access Level', 'Login', 'Name', 'Conf. Email'));
     $table->setRowType(0, 'th');
     foreach ($_SESSION['auth_success'] as $auth) {
         $table->addRow(array(AccessLevel::getAccessLevelStr($auth['user']->access_level), $auth['user']->login, $auth['user']->name, $auth['email']), array('class' => 'stats_odd'));
     }
     echo $table->toHtml();
 }
Example #6
0
 public function __construct()
 {
     parent::__construct('auth_error', 'Authorization Error', 'Admin/auth_error.php');
     if ($this->loginError) {
         return;
     }
     echo "<h2>Invalid Access Level</h2>" . "\n<p>The following users have incorrect access level.</p>";
     $table = new HTML_Table(array('class' => 'stats'));
     $table->addRow(array('Access Level', 'Login', 'Name'));
     $table->setRowType(0, 'th');
     foreach ($_SESSION['auth_errors'] as $auth_err) {
         $table->addRow(array(AccessLevel::getAccessLevelStr($auth_err['access']), $auth_err['user']->login, $auth_err['user']->name), array('class' => 'stats_odd'));
     }
     echo $table->toHtml();
     echo '<p><a href="authorize_new_users.php">Authorize new users</a></p>';
 }
 /**
  * Create user
  * @param string $login
  * @param $email
  * @param string $password
  * @return bool
  */
 public function createUser($login, $email, $password)
 {
     $result = $this->proxy->createAccountEx($login, $password, AccessLevel::User(), AccountStatus::Active(), $email, null);
     return $result->isOk();
 }
$salt = "ThisIsMySalt";
$result = $proxy->registerOperatorAlgorithm($operatorTag, $salt, $md5AlgoId);
if ($result->isOk()) {
    echo "Operator's algorithm registered\n";
} else {
    echo "Failed to register operator's algorithm\n";
    var_export($result);
    exit;
}
// !!!
// next operations can be used after we've registered algorithm for operator
// !!!
$userName = '******';
$pwd = 'Gamblor';
$hash = md5($salt . $pwd);
$result = $proxy->createAccountWithHash($userName, $hash, $operatorTag, AccessLevel::User(), AccountStatus::Active());
if ($result->isOk()) {
    echo "Account created: {$userName}\n";
} else {
    echo "Failed to create account {$userName}, suppose it's already exist\n";
    $result = $proxy->modifyAccountHash($userName, $hash, $operatorTag);
    if ($result->isOk()) {
        echo "Hash changed for account {$userName}\n";
    } else {
        echo "Failed to change hash for account {$userName}\n";
        var_export($result);
    }
}
// check user password against incorrect
$result = $proxy->checkPassword($userName, $pwd . 'garbage');
if (!$result->isOk()) {