Skip to content

Commit 4ba1647

Browse files
committed
wip
1 parent f89aec4 commit 4ba1647

31 files changed

+695
-41
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@
4141
"psr-4": {
4242
"Backstage\\UserManagement\\": "src/",
4343
"Backstage\\UserManagement\\Database\\Factories\\": "database/factories/"
44-
}
44+
},
45+
"files": [
46+
"helpers.php"
47+
]
4548
},
4649
"autoload-dev": {
4750
"psr-4": {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
// config for Backstage/UserManagement
4+
5+
use Backstage\UserManagement\Models\UserLogin;
6+
7+
return [
8+
'eloquent' => [
9+
'users' => [
10+
'model' => \App\Models\User::class,
11+
],
12+
13+
'user_logins' => [
14+
'model' => UserLogin::class,
15+
'table' => 'user_logins',
16+
'primary_key' => 'id',
17+
],
18+
],
19+
20+
'record' => [
21+
'user_logins' => true,
22+
'user_traffic' => true,
23+
]
24+
];

config/user-management.php

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('user_logins', function (Blueprint $table) {
15+
$table->id();
16+
$table->unsignedBigInteger('user_id')->nullable();
17+
18+
$table->string('type')->nullable();
19+
$table->string('url')->nullable();
20+
$table->string('referrer')->nullable();
21+
$table->text('inputs')->nullable();
22+
$table->string('user_agent')->nullable();
23+
$table->string('ip_address')->nullable();
24+
$table->string('hostname')->nullable();
25+
26+
$table->timestamps();
27+
});
28+
}
29+
30+
/**
31+
* Reverse the migrations.
32+
*/
33+
public function down(): void
34+
{
35+
Schema::dropIfExists('user_logins');
36+
}
37+
};

database/migrations/create_user_management_table.php.stub

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('user_traffic', function (Blueprint $table) {
15+
$table->id();
16+
$table->unsignedBigInteger('user_id')->nullable();
17+
$table->string('method', 10);
18+
$table->string('path');
19+
$table->text('full_url');
20+
$table->ipAddress('ip')->nullable();
21+
$table->text('user_agent')->nullable();
22+
$table->text('referer')->nullable();
23+
$table->string('route_name')->nullable();
24+
$table->string('route_action')->nullable();
25+
$table->json('route_parameters')->nullable();
26+
$table->timestamps();
27+
});
28+
}
29+
30+
/**
31+
* Reverse the migrations.
32+
*/
33+
public function down(): void
34+
{
35+
Schema::dropIfExists('user_traffic');
36+
}
37+
};

helpers.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
if (! function_exists('geo')) {
4+
function geo($attribute = '')
5+
{
6+
if (! session('geo')) {
7+
$geo = json_decode(@file_get_contents('https://pro.ip-api.com/json/'.request()->ip().'?key='.config('services.ip-api.key')));
8+
9+
session()->put('geo', $geo);
10+
} else {
11+
$geo = session('geo');
12+
}
13+
14+
return $attribute && isset($geo->{$attribute}) ? $geo->{$attribute} : null;
15+
}
16+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Backstage\UserManagement\Concerns\Conditionals;
4+
5+
trait HasConditionals
6+
{
7+
use UserIsVerified;
8+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Backstage\UserManagement\Concerns\Conditionals;
4+
5+
/**
6+
* @property-read \Illuminate\Database\Eloquent\Collection|\Backstage\UserManagement\Models\UserLogin[] $logins
7+
* @property-read int|null $logins_count
8+
*
9+
* @mixin \Backstage\UserManagement\Models\User
10+
*/
11+
trait UserIsVerified
12+
{
13+
public function isVerified(): bool
14+
{
15+
return $this->email_verified_at !== null;
16+
}
17+
18+
public function isNotVerified(): bool
19+
{
20+
return !$this->isVerified();
21+
}
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Backstage\UserManagement\Concerns;
4+
5+
use Backstage\UserManagement\Concerns;
6+
7+
trait HasBackstageManagement
8+
{
9+
use Concerns\Conditionals\HasConditionals;
10+
use Concerns\Relations\HasRelations;
11+
use Concerns\Scopes\HasScopes;
12+
13+
}

0 commit comments

Comments
 (0)