Commit 9b97ec59 authored by Waterfox's avatar Waterfox
Browse files

Merge branch 'LoginForm'

parents 93c515a0 b44e9be6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -15,3 +15,4 @@ yarn-error.log
/.vscode
server.php
index.php
resources/view/test.blade.php

app/Models/Role.php

0 → 100644
+16 −0
Original line number Diff line number Diff line
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Role extends Model
{
    use HasFactory;

    protected $table = 'CAR_ROLE';

    protected $primaryKey = 'ROL_CODE';

}
+12 −0
Original line number Diff line number Diff line
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class RoleAttribution extends Model
{
    protected $table = 'CAR_ROLE_ATTRIBUTION';
    public $timestamps = false;
}
+36 −21
Original line number Diff line number Diff line
@@ -7,38 +7,53 @@
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Illuminate\Database\Eloquent\Model;

class User extends Authenticatable
class User extends Model
{
    use HasApiTokens, HasFactory, Notifiable;
    use HasFactory, Notifiable, HasApiTokens;

    protected $table = 'CAR_USER';

    protected $primaryKey = 'US_ID';

    /**
     * The attributes that are mass assignable.
     * Check if a given password matches the stored password.
     *
     * @var array<int, string>
     * @param string $password the password to try
     * @return bool true if the password matches, false otherwise
     */
    protected $fillable = [
        'name',
        'email',
        'password',
    ];
    public function checkPassword($password)
    {
        if($password == $this->US_PASSWORD)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     * Get the roles attributed to the user.
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    public function roles()
    {
        return $this->belongsToMany(Role::class, RoleAttribution::class, 'US_ID', 'ROL_CODE');
    }

    /**
     * The attributes that should be cast.
     * Check if the user has a given role.
     *
     * @var array<string, string>
     * @param string $roleCode the code of the role to check
     * @return bool true if the user has the role, false otherwise
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
    public function hasRole($roleCode)
    {
        return $this->roles->contains('ROL_CODE', $roleCode);
    }
}

?>
+348 KiB
Loading image diff...
Loading