Skip to content

Commit

Permalink
Merge pull request #1107 from proditis/backend-fixes
Browse files Browse the repository at this point in the history
Backend fixes
  • Loading branch information
proditis authored Feb 19, 2024
2 parents 0112a9e + a57865c commit 568023b
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 7 deletions.
11 changes: 7 additions & 4 deletions backend/commands/CronController.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,16 @@ public function actionInstances($pfonly=false)
$dc->pull();
$dc->spin();
}
if(($val->team_allowed===true && $val->player->teamPlayer && $val->player->teamPlayer->approved===1) || \Yii::$app->sys->team_visible_instances===true)
if(($val->team_allowed===true || \Yii::$app->sys->team_visible_instances===true) && $val->player->teamPlayer )
{
foreach($val->player->teamPlayer->team->teamPlayers as $teamPlayer)
if($val->player->teamPlayer->approved===1)
{
if($teamPlayer->player->last->vpn_local_address!==null && $teamPlayer->approved===1)
foreach($val->player->teamPlayer->team->teamPlayers as $teamPlayer)
{
$ips[]=long2ip($teamPlayer->player->last->vpn_local_address);
if($teamPlayer->player->last->vpn_local_address!==null && $teamPlayer->approved===1)
{
$ips[]=long2ip($teamPlayer->player->last->vpn_local_address);
}
}
}
}
Expand Down
61 changes: 61 additions & 0 deletions backend/commands/PlayerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,65 @@ private function getErrorRows($model)
return $errorows;
}

/**
* Fetch identification files from frontend
* @param string $filter Filter players by all, active and inactive
* @param string $scheme Default scheme to use
*/
public function actionFetchIdentification($filter='inactive',$scheme='https')
{
$filters=['all', 'active', 'inactive'];
if(!in_array($filter, $filters))
{
throw new ConsoleException(Yii::t('app', 'Filter accepts values: {values}', ['values' => implode(',', $filters)]));
}

$players=Player::find();
switch($filter) {
case 'active':
$players->where(['active' => 1]);
break;

case 'inactive':
$players->where(['active' => 0]);
break;

}
$formats=['.pdf','.png','.jpg','.jpeg','.docx'];
foreach ($players->all() as $player){
$baseDir=\Yii::getAlias('@app/web/identificationFiles/');
echo "processing ",$player->username;
$format=null;

foreach ($formats as $f)
{
$format=null;
$skip=false;
if(file_exists($baseDir.$player->profile->id.$f))
{
echo " found local file,";
$skip=true;
break;
}
$ch = curl_init("$scheme://".Yii::$app->sys->offense_domain.'/identificationFiles/'.$player->profile->id.$f);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_HEADER, true);

curl_exec($ch);
$status = curl_getinfo($ch,CURLINFO_HTTP_CODE);
if ($status===200)
{
$format=$f;
break;
}
}
if($format!==null && $skip!==true) {
echo " => grabbing ",$baseDir .$player->profile->id.$format,"\n";
file_put_contents($baseDir .$player->profile->id.$format, fopen("$scheme://".Yii::$app->sys->offense_domain.'/identificationFiles/'.$player->profile->id.$format, 'r'));
}
else if ($skip===true) { echo " skipping\n";}
else{ echo " no identification found\n";}
}
}
}
2 changes: 1 addition & 1 deletion backend/modules/frontend/models/PlayerAR.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function rules()
[['auth_key'], 'string', 'max' => 32],
[['type'], 'default', 'value' => 'offense'],
[['status'], 'default', 'value' => self::STATUS_ACTIVE],
[['activkey'], 'default', 'value' => Yii::$app->security->generateRandomString().'-'.time(), 'on' => 'create'],
[['activkey'], 'default', 'value' => '', 'on' => 'create'],
[['verification_token'], 'default', 'value' => str_replace('_','-',Yii::$app->security->generateRandomString().'-'.time()), 'on' => 'create'],
[['username', 'fullname', 'email', 'new_password', 'activkey'], 'string', 'max' => 255],
[['username'], 'unique'],
Expand Down
23 changes: 23 additions & 0 deletions backend/modules/frontend/views/player/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@
}
],
['class' => 'app\components\columns\ProfileColumn', 'idkey' => 'profile.id', 'attribute' => 'username', 'field' => 'username'],
[
'attribute'=>'affiliation',
'visible' => Yii::$app->sys->players_require_approval,
'format'=>'html',
'value'=>function($model){
if($model->active==1) return Html::encode($model->affiliation);
$formats=['.pdf','.png','.jpg','.jpeg','.docx'];
$format=null;
$baseDir=\Yii::getAlias('@app/web/identificationFiles/');
foreach ($formats as $f)
{
if(file_exists($baseDir.$model->profile->id.$f))
{
$format=$f;
break;
}
}
if($format!==null)
return Html::a($model->affiliation,'/identificationFiles/'.$model->profile->id.$format,['width' => '50px']);
else
return Html::encode($model->affiliation);
},
],
'email:email',
[
'attribute' => 'vpn_local_address',
Expand Down
4 changes: 2 additions & 2 deletions backend/widgets/BooleanTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BooleanTransform
* @param mixed $val
* @return string
*/
function toCheck($val)
public static function toCheck($val)
{
if($val===true || $val===1 || $val==='1')
{
Expand All @@ -25,7 +25,7 @@ function toCheck($val)
* @param mixed $val
* @return string
*/
function toOnOff($val)
public static function toOnOff($val)
{
if($val===true || $val===1 || $val==='1')
{
Expand Down

0 comments on commit 568023b

Please sign in to comment.