This commit is contained in:
2021-06-28 23:15:13 -04:00
parent 0061a3d920
commit f4a8db56ff
93 changed files with 2422 additions and 0 deletions

View File

@ -0,0 +1,49 @@
<?php
namespace ProVM\Crypto\Common\Service;
use Carbon\Carbon;
use ProVM\Common\Factory\Model as ModelFactory;
use ProVM\Crypt\User;
use ProVM\Crypt\Login;
class Auth {
protected $login_time;
public function __construct(int $login_time) {
$this->login_time = $login_time;
}
protected $factory;
public function setFactory(ModelFactory $factory) {
$this->factory = $factory;
}
protected function createToken() {
return password_hash(random_bytes(100), \PASSWORD_BCRYPT);
}
public function login(string $username, string $password) {
$user = $this->factory->find(User::class)->where([['name', $username]])->one();
if (!$user) {
return false;
}
if (!password_verify($password, $user->password)) {
return false;
}
$now = Carbon::now();
$login = $this->factory->find(Login::class)->where([['user_id', $user->id], ['date_time', $now->copy()->subSeconds($this->login_time), '>=']])->one();
if (!$login) {
$token = $this->createToken();
$data = [
'user_id' => $user->id,
'token' => $token,
'date_time' => $now->format('Y-m-d H:i:s')
];
$login = $this->factory->create(Login::class, $data);
} else {
$login->date($now);
}
$login->save();
return $token;
}
public function isLoggedIn($token) {
$login = $this->factory->find(Login::class)->where([['token', $token]])->one();
return $login->user();
}
}

View File

@ -0,0 +1,60 @@
<?php
namespace ProVM\Crypto\Common\Service;
use Carbon\Carbon;
use ProVM\Common\Factory\Model as Factory;
use ProVM\Crypto\Coin;
class Update {
protected $factory;
protected $execs;
public function __construct(Factory $factory, array $executables) {
$this->factory = $factory;
$this->execs = $executables;
$this->load();
}
public function load() {
$this->coins = [[], []];
$results = \ORM::for_table('coin_registers')->find_many();
foreach ($results as $result) {
$this->coins[$result->type] []= $result->coin_id;
}
}
protected $coins;
public function register(int $coin_id, int $type = 0) {
/*if (array_search($coin_id, $this->coins[$type]) !== false) {
return;
}*/
$this->coins[$type] []= $coin_id;
$this->getHistorical($coin_id, $type);
$check = \ORM::for_table('coin_registers')->where('coin_id', $coin_id)->find_one();
if (!$check) {
\ORM::raw_execute("INSERT INTO coin_registers (coin_id, type) VALUES (?, ?)", [$coin_id, $type]);
}
return true;
}
protected function getHistorical(int $coin_id, int $type) {
$coin = $this->factory->find(Coin::class)->one($coin_id);
$f = Carbon::now();
$exe = [$this->execs[$type]];
switch ($type) {
case 0:
$exe []= '-i ' . $coin->identifier;
$exe []= '-c usd,clp';
$exe []= 'hist -hi';
$exe []= '-f ' . $f->copy()->subYears(10)->timestamp;
$exe []= '-t ' . $f->timestamp();
break;
case 1:
$exe []= '-i ' . $coin->identifier;
$exe []= 'hist -hi';
$exe []= '-s ' . $f->copy()->subYears(10)->year;
break;
}
!d(implode(' ', $exe));
$output = shell_exec(implode(' ', $exe));
!d($output);
}
public function run() {
}
}