- Timestamp:
- 09/27/21 23:25:43 (3 years ago)
- Branches:
- develop, master
- Children:
- 582789f
- Parents:
- 2fc88ec
- Location:
- app
- Files:
-
- 16 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
app/Http/Kernel.php
r2fc88ec r7304c7f 22 22 \App\Http\Middleware\TrimStrings::class, 23 23 \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, 24 \App\Http\Middleware\CheckForMaintenanceMode::class, 24 25 ]; 25 26 … … 64 65 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 65 66 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, 67 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 68 'createPassword' => \App\Http\Middleware\CheckCreatePassword::class, 69 'checkVerifyNewEmail' => \App\Http\Middleware\CheckVerifyNewEmail::class, 70 'permission' => \App\Http\Middleware\CheckPermission::class, 71 'checkIsActive' => \App\Http\Middleware\CheckIsActive::class, 66 72 ]; 67 73 } -
app/Http/Middleware/Authenticate.php
r2fc88ec r7304c7f 16 16 { 17 17 if (! $request->expectsJson()) { 18 return route(' login');18 return route('auth.loginShow'); 19 19 } 20 20 } -
app/Http/Middleware/TrimStrings.php
r2fc88ec r7304c7f 13 13 */ 14 14 protected $except = [ 15 'current_password',16 15 'password', 17 16 'password_confirmation', -
app/Http/Middleware/TrustHosts.php
r2fc88ec r7304c7f 4 4 5 5 use Illuminate\Http\Middleware\TrustHosts as Middleware; 6 use Illuminate\Http\Request; 6 7 7 8 class TrustHosts extends Middleware -
app/Http/Middleware/VerifyCsrfToken.php
r2fc88ec r7304c7f 8 8 { 9 9 /** 10 * Indicates whether the XSRF-TOKEN cookie should be set on the response. 11 * 12 * @var bool 13 */ 14 protected $addHttpCookie = true; 15 16 /** 10 17 * The URIs that should be excluded from CSRF verification. 11 18 * -
app/Models/User.php
r2fc88ec r7304c7f 3 3 namespace App\Models; 4 4 5 use Illuminate\ Contracts\Auth\MustVerifyEmail;6 use Illuminate\ Database\Eloquent\Factories\HasFactory;5 use Illuminate\Support\Str; 6 use Illuminate\Notifications\Notifiable; 7 7 use Illuminate\Foundation\Auth\User as Authenticatable; 8 use Illuminate\Notifications\Notifiable;9 use Laravel\Sanctum\HasApiTokens;10 8 11 9 class User extends Authenticatable 12 10 { 13 use HasApiTokens, HasFactory, Notifiable; 11 use Notifiable; 12 13 protected $table = "users"; 14 14 15 15 /** 16 16 * The attributes that are mass assignable. 17 17 * 18 * @var string[]18 * @var array 19 19 */ 20 20 protected $fillable = [ 21 'name', 22 'email', 23 'password', 21 "name", 22 "surname", 23 "username", 24 "password", 25 "email", 26 "country_code", 27 "mobile_number", 28 "role_id" 24 29 ]; 25 30 26 31 /** 27 * The attributes that should be hidden for serialization.32 * The attributes that should be hidden for arrays. 28 33 * 29 34 * @var array 30 35 */ 31 36 protected $hidden = [ 32 'password', 33 'remember_token', 37 "password", 38 "remember_token", 39 "is_active" 34 40 ]; 35 41 36 42 /** 37 * The attributes that should be cast .43 * The attributes that should be cast to native types. 38 44 * 39 45 * @var array 40 46 */ 41 protected $casts = [ 42 'email_verified_at' => 'datetime', 43 ]; 47 protected $casts = []; 48 49 50 public function role() { 51 return $this->belongsTo(Role::class); 52 } 53 54 public function post() { 55 return $this->hasMany(Post::class); 56 } 57 58 public function comments() 59 { 60 return $this->hasManyThrough(Comment::class, Post::class); 61 } 62 63 public function hasPermission($permission, $id = null, $any = false) { 64 65 $userPermissions = null; 66 $flag = null; 67 68 if($id != null) $userPermissions = User::find($id)->role->permission->pluck("name"); 69 else $userPermissions = $this->role->permission->pluck("name"); 70 71 if($any) { 72 foreach($permission as $p) { 73 if($this->hasPermission($p)) { 74 return true; 75 } 76 } 77 return false; 78 } 79 80 if(is_string($permission)) { 81 return $userPermissions->contains($permission); 82 } 83 84 if(is_array($permission)) { 85 foreach($permission as $p) { 86 if($this->hasPermission($p)) { 87 $flag = true; 88 } else { 89 $flag = false; break; 90 } 91 } 92 } 93 94 return $flag; 95 } 96 97 public function hasAllPermissions(array $permissions = array(), $id = null, $any = false) { 98 return $this->hasPermission($permissions, $id, $any); 99 } 100 101 public function hasAnyPermission(array $permissions = array(), $id = null, $any = true) { 102 return $this->hasPermission($permissions, $id, $any); 103 } 104 105 public function hasRole($role) { 106 return $role === $this->role->name; 107 } 108 109 public function isAdmin() { 110 return $this->hasRole("admin"); 111 } 112 113 public function isAdminOrEditor() { 114 return $this->hasRole("admin") || $this->hasRole("editor"); 115 } 116 117 public function getFullName($id = null) { 118 119 if($id != null) { 120 $user = User::find($id); 121 return $user->name . " " . $user->surname; 122 } 123 124 return $this->name . " " . $this->surname; 125 } 126 127 public function getPostsCount($id) { 128 return Post::where("user_id", $id)->count(); 129 } 130 131 public function generateTemporaryPassword($length = 20) { 132 return bcrypt(Str::random($length)); 133 } 134 135 public function generateSecurityCode($min = 10000, $max = 99999) { 136 return rand($min, $max); 137 } 138 139 public function generateVerifyToken($length = 32) { 140 return Str::random($length); 141 } 44 142 } -
app/Providers/AuthServiceProvider.php
r2fc88ec r7304c7f 14 14 */ 15 15 protected $policies = [ 16 //'App\Models\Model' => 'App\Policies\ModelPolicy',16 'App\Models\Model' => 'App\Policies\ModelPolicy', 17 17 ]; 18 18 -
app/Providers/RouteServiceProvider.php
r2fc88ec r7304c7f 27 27 * @var string|null 28 28 */ 29 //protected $namespace = 'App\\Http\\Controllers';29 protected $namespace = 'App\\Http\\Controllers'; 30 30 31 31 /**
Note:
See TracChangeset
for help on using the changeset viewer.