This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccount/app/Models/App.php
2019-06-06 15:44:45 +02:00

72 lines
2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Auth\Authenticatable;
use Laravel\Lumen\Auth\Authorizable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
class App extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'description', 'url', 'apiKey', 'apiSecret', 'auto_accept', 'testing_warning', 'untrusted_warning', 'user_id', 'direct_url'
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'',
];
static function createApp($name, $description, $url, User $user) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randstring = '';
for ($i = 0; $i < 20; $i++) {
$randstring .= $characters[rand(0, strlen($characters)-1)];
}
$apiKey = hash("sha512", $randstring);
$randstring = '';
for ($i = 0; $i < 20; $i++) {
$randstring .= $characters[rand(0, strlen($characters)-1)];
}
$apiSecret = hash("sha512", $randstring);
$app = new App();
$app->name = $name;
$app->description = $description;
$app->url = $url;
$app->apiKey = $apiKey;
$app->apiSecret = $apiSecret;
$app->auto_accept = false;
$app->testing_warning = true;
$app->untrusted_warning = false;
$app->user_id = $user->id;
$app->saveOrFail();
return $app;
}
public function regenerateApiSecret() {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randstring = '';
for ($i = 0; $i < 20; $i++) {
$randstring .= $characters[rand(0, strlen($characters)-1)];
}
$apiSecret = hash("sha512", $randstring);
$this->apiSecret = $apiSecret;
}
}