Skip to content

Commit

Permalink
fix bugs add image quality manager & watermark fix routing system upd…
Browse files Browse the repository at this point in the history
…ate packages and use finder and filesystem project from symfony and more ...
  • Loading branch information
alishahidi committed May 1, 2022
1 parent f4a12e2 commit 027ee87
Show file tree
Hide file tree
Showing 30 changed files with 465 additions and 198 deletions.
10 changes: 5 additions & 5 deletions .env
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
TOKEN=geFromApp
CRYPT_TOKEN=genFromApp
TOKEN=generate_from_app_Security_class
CRYPT_TOKEN=generate_from_app_Security_class

# Database
DB_HOST=127.0.0.1
DB_PORT=3306
DB_NAME=app
DB_NAME=ex
DB_USERNAME=root
DB_PASSWORD=

MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=test@gmail.com
MAIL_PASSWORD=ex
MAIL_USERNAME=ex@gmail.com
MAIL_PASSWORD=ex
1 change: 0 additions & 1 deletion README.md

This file was deleted.

10 changes: 10 additions & 0 deletions app/Helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
function errorClass($name)
{
return errorExists($name) ? "is-invalid" : null;
}

function errorText($name)
{
return errorExists($name) ? "<div><small class=\"text-danger\">" . error($name) . "</small></div>" : null;
}
22 changes: 22 additions & 0 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\LoginRequest;
use App\Http\Services\Mail;
use System\Auth\Auth;
use System\Security\Security;

class LoginController extends Controller
{
public function login()
{
$request = new LoginRequest();
Auth::loginUsingEmail($request->email, $request->password, "user not fount.", "Password incorrect");
$user = Auth::userUsingEmail($request->email);
if ($user->permission == "root")
return redirect(route("admin.index"));
return redirect(route("home.index"));
}
}
15 changes: 15 additions & 0 deletions app/Http/Controllers/Auth/LogoutController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use System\Auth\Auth;

class LogoutController extends Controller
{
public function logout()
{
Auth::logout();
return back();
}
}
26 changes: 26 additions & 0 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\RegisterRequest;
use App\Http\Services\ImageUpload;
use App\Http\Services\Mail;
use App\Models\User;
use Ramsey\Uuid\Uuid;
use System\Auth\Auth;
use System\Security\Security;

class RegisterController extends Controller
{
public function register()
{
$request = new RegisterRequest();
$inputs = $request->all();
$inputs["avatar"] = ImageUpload::uploadAndFit("avatar", "user_avatar", 151, 119);
$inputs['permission'] = 'user';
Auth::storeUser($inputs, "password");
flash("user_activation_send", "Successfully registered.");
return redirect(route("auth.login"));
}
}
5 changes: 4 additions & 1 deletion app/Http/Controllers/Home/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace App\Http\Controllers\Home;

use App\Models\Category;
use App\Http\Controllers\Controller;
use App\Models\Post;

class HomeController extends Controller
{

public function index()
{
echo "aaa";
$message = "message from controller";
return view("app.index", compact("message"));
}
}
39 changes: 38 additions & 1 deletion app/Http/Helpers.php
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
<!-- cerate -->
<?php
function errorClass($name)
{
return errorExists($name) ? "is-invalid" : null;
}

function errorText($name)
{
return errorExists($name) ? "<div><small class=\"text-danger\">" . error($name) . "</small></div>" : null;
}

function sidebarActive($routeName, $contain = false)
{
return equalUrl(route($routeName), $contain) ? "active" : null;
}

function navActive($routeName)
{
return equalUrl(route($routeName)) ? "active" : null;
}

function sidebarAngle($routeName, $contain = true)
{
return equalUrl(route($routeName), $contain) ? "bi-chevron-down" : "bi-chevron-left";
}

function sidebarLinkActive($routeName)
{
return equalUrl(route($routeName)) ? "sidebar-link-active" : null;
}

function sidebarDropDownActive($routeNames, $contain = false)
{
foreach ($routeNames as $routeName)
if (equalUrl(route($routeName), $contain))
return "sidebar-group-link-active";
return null;
}
32 changes: 32 additions & 0 deletions app/Http/Requests/Admin/PostRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Http\Requests\Admin;

use System\Request\Request;

class PostRequest extends Request
{
public function rules()
{
if (methodField() == "put") // for update
return [
"rules" => [
"title" => "required|max:210",
"description" => "required|max:380",
"body" => "required",
"cat_id" => "required|exists:categories,id",
"image" => "file|mimes:jpeg,jpg,png,gif",
],
];

return [
"rules" => [
"title" => "required|max:210",
"description" => "required|max:380",
"body" => "required",
"cat_id" => "required|exists:categories,id",
"image" => "required|file|mimes:jpeg,jpg,png,gif",
],
];
}
}
21 changes: 21 additions & 0 deletions app/Http/Requests/Auth/LoginRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Requests\Auth;

use System\Request\Request;

class LoginRequest extends Request
{
public function rules()
{
return [
"rules" => [
"email" => "required|email",
"password" => "required",
],
"errors" => [
"email" => "required!some custom error|email!some custom error",
]
];
}
}
24 changes: 24 additions & 0 deletions app/Http/Requests/Auth/RegisterRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Http\Requests\Auth;

use System\Request\Request;

class RegisterRequest extends Request
{
public function rules()
{
return [
"rules" => [
"name" => "required|max:210",
"email" => "required|max:90|email|unique:users,email",
"avatar" => "required|file|mimes:jpeg,jpg,png,gif|max:2048",
"password" => "required|min:8|confirmed",
"bio" => "required|max:380"
],
"errors" => [
"email" => "required!some custom error|email!some custom error",
]
];
}
}
9 changes: 7 additions & 2 deletions app/Http/Services/ImageUpload.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,32 @@
namespace App\Http\Services;

use Ramsey\Uuid\Uuid;
use System\Config\Config;
use System\Request\Request;

class ImageUpload
{
public static function dateFormatUploadAndFit($fileName, $dir, $width, $height)
public static function dateFormatUploadAndFit($fileName, $dir, $width, $height, $watermark = null)
{
$request = new Request();
$dirSep = DIRECTORY_SEPARATOR;
$path = "images{$dirSep}{$dir}{$dirSep}" . date("Y{$dirSep}M{$dirSep}d");
$uuid = Uuid::uuid4()->toString();
$name = date("Y_m_d_M_i_s_") . $uuid;
if ($watermark)
return $request->uploadImage($fileName, $path, $name, [$width, $height], $watermark);
return $request->uploadImage($fileName, $path, $name, [$width, $height]);
}

public static function uploadAndFit($fileName, $dir, $width, $height)
public static function uploadAndFit($fileName, $dir, $width, $height, $watermark = null)
{
$request = new Request();
$dirSep = DIRECTORY_SEPARATOR;
$path = "images{$dirSep}{$dir}{$dirSep}";
$uuid = Uuid::uuid4()->toString();
$name = date("Y_m_d_M_i_s_") . $uuid;
if ($watermark)
return $request->uploadImage($fileName, $path, $name, [$width, $height], $watermark);
return $request->uploadImage($fileName, $path, $name, [$width, $height]);
}

Expand Down
13 changes: 13 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Models;

use System\Database\ORM\Model;
use System\Database\Traits\HasSoftDelete;

class User extends Model{
use HasSoftDelete;
protected $table = "users";
protected $fillable = ["name", "email", "password", "avatar", "permission", "bio"];

}
18 changes: 10 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
}
},
"require": {
"symfony/var-dumper": "^5.3",
"ramsey/uuid": "^4.2",
"intervention/image": "^2.6",
"firebase/php-jwt": "^5.4",
"vlucas/phpdotenv": "^5.3",
"symfony/var-dumper": "^6.0",
"ramsey/uuid": "^4.3",
"intervention/image": "^2.7",
"firebase/php-jwt": "^6.1",
"vlucas/phpdotenv": "^5.4",
"defuse/php-encryption": "^2.3",
"symfony/polyfill": "^1.23",
"phpmailer/phpmailer": "^6.5",
"symfony/polyfill": "^1.25",
"phpmailer/phpmailer": "^6.6",
"gregwar/captcha": "^1.1",
"morilog/jalali": "^3.2"
"morilog/jalali": "^3.3",
"symfony/finder": "^6.0",
"symfony/filesystem": "^6.0"
}
}
Loading

0 comments on commit 027ee87

Please sign in to comment.