CrestRoad/laravel/app/Console/Commands/Refreshtoken.php

60 lines
1.5 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Http\Requests\LambdaRequest;
use Illuminate\Support\Facades\Http;
use Log;
use App\Models\User;
class Refreshtoken extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'token:refresh';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$users = DB::table('users')->select("user_id","email","refresh_token")->get();
foreach($users as $user) {
try {
$response = LambdaRequest::postrequest('ums', 'auth/reverify', ['refresh_token' => $user->refresh_token ], '' );
if($response->statusCode == 200) {
User::where('user_id', $user->user_id)->update(['hierarchy_id' => $response->data->user->hierarchy, 'access_token' => $response->data->access_token, 'permissions' => json_encode($response->data->permissions), 'updated_at' => date("Y-m-d H:i:s", strtotime("now") ) ]);
}
} catch (Exception $e) {
Log::error($e->getMessage());
}
}
}
}