Giter Site home page Giter Site logo

cmsrs / laracms Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 64.53 MB

Installation cmsRS

Home Page: https://www.cmsrs.pl/

License: MIT License

PHP 51.20% HTML 0.27% JavaScript 41.58% Shell 0.14% Blade 6.29% CSS 0.52%
cms gallery-images laravel laravel-package shop

laracms's Introduction

INSTALLATION

composer require cmsrs/laracms

php artisan vendor:publish --provider="Cmsrs\Laracms\Providers\LaracmsProvider" --force

php artisan migrate

php artisan db:seed

Remove lines from file: ./routes/web.php:

//Route::get('/', function () {
//    return view('welcome');
//});

Configure jwtAuth (in nutshell):

php artisan vendor:publish --provider="PHPOpenSourceSaver\JWTAuth\Providers\LaravelServiceProvider"

php artisan jwt:secret

in config/auth.php change to:

    'defaults' => [
        'guard' => 'api',
        'passwords' => 'users',
    ],

    'guards' => [
        'api' =>  [
            'driver' =>  'jwt', //'token',
            'provider' => 'users',
            'hash' => false
        ],
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],
    ],

add User.php file in: app/Models:

<?php
namespace App\Models;


use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Auth;
use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject;

class User extends Authenticatable implements JWTSubject
{
    use Notifiable;


    public static $role = [
        'admin' => 'admin',
        'client' => 'client'
    ];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password' , 'role'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }
    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }

    public function setPasswordAttribute($password)
    {
        if (!empty($password)) {
            $this->attributes['password'] = Hash::make($password);

        }
    }

    static public function getTokenForClient()
    {
        $user = Auth::user();
        if( empty($user) ){
            throw new \Exception("User not auth");
        }

        return $user->getTokenClient();
    }

    public function getTokenClient()
    {
        $appKey = env('APP_KEY');
        if( empty($appKey) ){
            throw new \Exception("empty APP_KEY in config file");
        }
                
        return sha1($this->email."_".$this->id."_".$appKey);
    }

    public function checkClientByToken($token)
    {
        $expectedToken = $this->getTokenClient();
        if($expectedToken ==  $token){
            return true;
        }
        return false;
    }

    static public function  checkApiClientByToken($token)
    {
        $user = Auth::user();
        if( empty($user) ){
            throw new \Exception("User not auth - for check");
        }
        if( !$user->checkClientByToken($token) ){
            throw new \Exception("User not valid - check");
        }
        return true;
    }

}
php artisan serve

MANAGMENT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.