Skip to content

Commit

Permalink
Use static variable instead of class constant for USER_ROLES for 5.5.…
Browse files Browse the repository at this point in the history
…9 compat, fix #264
  • Loading branch information
cydrobolt committed Dec 9, 2016
1 parent 44bb4ef commit c95c964
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion app/Factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
use App\Helpers\UserHelper;

class UserFactory {
public static function createUser($username, $email, $password, $active=0, $ip='127.0.0.1', $api_key=false, $api_active=0, $role=UserHelper::USER_ROLES['default']) {
public static function createUser($username, $email, $password, $active=0, $ip='127.0.0.1', $api_key=false, $api_active=0, $role=false) {
if (!$role) {
$role = UserHelper::$USER_ROLES['default'];
}

$hashed_password = Hash::make($password);
$recovery_key = CryptoHelper::generateRandomHex(50);

Expand Down
2 changes: 1 addition & 1 deletion app/Helpers/UserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Hash;

class UserHelper {
const USER_ROLES = [
public static $USER_ROLES = [
'admin' => 'admin',
'default' => '',
];
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function displayAdminPage(Request $request) {

return view('admin', [
'role' => $role,
'admin_role' => UserHelper::USER_ROLES['admin'],
'user_roles' => UserHelper::USER_ROLES,
'admin_role' => UserHelper::$USER_ROLES['admin'],
'user_roles' => UserHelper::$USER_ROLES,
'api_key' => $user->api_key,
'api_active' => $user->api_active,
'api_quota' => $user->api_quota,
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/AdminPaginationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class="form-control"';
}
$select_role .= '>';

foreach (UserHelper::USER_ROLES as $role_text => $role_val) {
foreach (UserHelper::$USER_ROLES as $role_text => $role_val) {
// Iterate over each available role and output option
$select_role .= '<option value="' . e($role_val) . '"';

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/SetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static function performSetup(Request $request) {
$acct_username = $request->input('acct:username');
$acct_email = $request->input('acct:email');
$acct_password = $request->input('acct:password');
$acct_group = UserHelper::USER_ROLES['admin'];
$acct_group = UserHelper::$USER_ROLES['admin'];

// if true, only logged in users can shorten
$st_shorten_permission = $request->input('setting:shorten_permission');
Expand Down Expand Up @@ -215,7 +215,7 @@ public static function finishSetup(Request $request) {
return redirect(route('setup'))->with('error', 'Could not create database. Perhaps some credentials were incorrect?');
}

$user = UserFactory::createUser($setup_finish_args->acct_username, $setup_finish_args->acct_email, $setup_finish_args->acct_password, 1, $request->ip(), false, 0, UserHelper::USER_ROLES['admin']);
$user = UserFactory::createUser($setup_finish_args->acct_username, $setup_finish_args->acct_email, $setup_finish_args->acct_password, 1, $request->ip(), false, 0, UserHelper::$USER_ROLES['admin']);

return view('setup_thanks')->with('success', 'Set up completed! Thanks for using Polr!');
}
Expand Down

0 comments on commit c95c964

Please sign in to comment.