Skip to content

Commit

Permalink
Merge pull request #5 from mohamadreza1388/main
Browse files Browse the repository at this point in the history
admin
  • Loading branch information
BaseMax authored Sep 16, 2024
2 parents a8b636b + 15f206b commit 2290544
Show file tree
Hide file tree
Showing 14 changed files with 850 additions and 14 deletions.
3 changes: 2 additions & 1 deletion app/DataTables/User/CodeDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function dataTable(QueryBuilder $query): EloquentDataTable

public function query(Code $model): QueryBuilder
{
return $model->newQuery()->where('user_id', auth()->user()->first()->id);
return $model->newQuery()->where('user_id', auth()->user()->id);
}

public function html(): HtmlBuilder
Expand All @@ -61,6 +61,7 @@ public function getColumns(): array
return [
Column::make('id')->title('ایدی'),
Column::make('title')->title('عنوان'),
Column::make('user_id')->title('user'),
Column::make('code')->title('کد'),
Column::make('created_at')->title('ایجاد شده در'),
Column::make('action')->title('کاربردی'),
Expand Down
30 changes: 27 additions & 3 deletions app/Http/Controllers/Admin/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Code;
use App\Models\CodesVisit;
use App\Models\Email;
use App\Models\User;
use App\Models\Visit;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;

class DashboardController extends Controller
{
public function index()
{
function getUsers($day)
function GetTables($day, $model)
{
$data = User::where('created_at', '>=', Carbon::now()->subDays($day))
$data = $model::where('created_at', '>=', Carbon::now()->subDays($day))
->selectRaw('DATE(created_at) as date, COUNT(*) as total')
->groupBy('date')
->orderBy('date', 'ASC')
Expand All @@ -27,10 +32,29 @@ function getUsers($day)
];
}

$users_history = getUsers(10);
$users_history = GetTables(10, User::class);
$codes_history = GetTables(10, Code::class);
$codes_visits_history = GetTables(10, CodesVisit::class);
$emails_history = GetTables(10, Email::class);

$best_code_visit = DB::table('codes_visits')
->select('code_id', DB::raw('COUNT(*) as count'))
->groupBy('code_id')
->orderBy('count', 'DESC')
->limit(10)
->get();

$best_code_results = Code::whereIn('id', $best_code_visit->pluck('code_id')->toArray())->get();

$visits_history = GetTables(30, Visit::class);

return view('admin.dashboard', [
'users_history' => $users_history,
'codes_history' => $codes_history,
'codes_visits_history' => $codes_visits_history,
'emails_history' => $emails_history,
'best_code_results' => $best_code_results,
'visits_history' => $visits_history,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Models\Email;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Webklex\IMAP\Facades\Client;

class EmailVerificationNotificationController extends Controller
{
Expand All @@ -19,6 +21,26 @@ public function store(Request $request): RedirectResponse

$request->user()->sendEmailVerificationNotification();

Email::create([
'to' => $request->user()->email,
'title' => 'forgot_password',
]);

$client = Client::account('default');
$client->connect();

$inbox = $client->getFolder('INBOX');
$messages = $inbox->messages()->all()->get();

if ($messages->count() > 0) {
$message = $messages->last();
if ($message = 'Mail delivery failed: returning message to sender') {
return back()->with('status', 'verification-link-fail');
}
} else {
return back()->with('status', 'verification-link-fail');
}

return back()->with('status', 'verification-link-sent');
}
}
17 changes: 17 additions & 0 deletions app/Http/Controllers/VisitController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Http\Controllers;

use App\Models\Visit;
use Illuminate\Http\Request;

class VisitController extends Controller
{
public function store(Request $request)
{
Visit::create([
'user_ip' => $request->ip(),
'user_agent' => $request->userAgent(),
]);
}
}
10 changes: 10 additions & 0 deletions app/Models/Email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Email extends Model
{
protected $fillable = ['title', 'to'];
}
10 changes: 10 additions & 0 deletions app/Models/Visit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Visit extends Model
{
protected $fillable = ['user_ip', 'user_agent'];
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"laravel/sanctum": "^4.0",
"laravel/tinker": "^2.9",
"morilog/jalali": "^3.4",
"webklex/laravel-imap": "^4.1",
"yajra/laravel-datatables": "^11.0",
"yajra/laravel-datatables-oracle": "11.0"
},
Expand Down
160 changes: 159 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2290544

Please sign in to comment.