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

73 lines
2 KiB
PHP
Raw Normal View History

2019-04-24 18:46:41 +00:00
<?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'
];
/**
* 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++) {
2019-05-02 13:22:37 +00:00
$randstring .= $characters[rand(0, strlen($characters)-1)];
2019-04-24 18:46:41 +00:00
}
$apiKey = hash("sha512", $randstring);
$randstring = '';
for ($i = 0; $i < 20; $i++) {
2019-05-02 13:22:37 +00:00
$randstring .= $characters[rand(0, strlen($characters)-1)];
2019-04-24 18:46:41 +00:00
}
$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;
}
2019-05-02 13:22:37 +00:00
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;
}
2019-04-24 18:46:41 +00:00
}