Skip to content

Commit

Permalink
preparing structure for user feature
Browse files Browse the repository at this point in the history
  • Loading branch information
puleeno committed Oct 15, 2023
1 parent dca8242 commit 926e4e1
Show file tree
Hide file tree
Showing 22 changed files with 531 additions and 52 deletions.
56 changes: 51 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
# puleeno-cms
Yet another PHP CMS by Puleeno Nguyen
Puleeno CMS
=====

Puleeno CMS is a free and open-source content management system (CMS) that is built on the PHP framework Laravel. Puleeno CMS is easy to use and flexible, making it a great choice for creating a wide variety of websites and digital content, such as blogs, wikis, and e-commerce websites.

# Server settings
# Features

## NGINX
## Puleeno CMS includes a variety of features, such as:

A user-friendly interface that makes it easy to create and manage content without having to know how to code.
A variety of built-in templates, themes, and plugins that make it easy to customize your website.
Support for multiple languages.
A variety of features to help improve the SEO of your website.
Support for user roles and permissions.
A variety of security features.
Benefits of using Puleeno CMS

## There are many benefits to using Puleeno CMS, including:

Ease of use: Puleeno CMS is easy to use, even for users who have no prior experience with web development.
Flexibility: Puleeno CMS is flexible and can be used to create a wide variety of websites and digital content.
Features: Puleeno CMS includes a variety of features that make it easy to create, manage, and publish digital content.
Security: Puleeno CMS can help to improve the security of your website by providing features such as user roles and permissions, and security patches and updates.
Support: Puleeno CMS has a large community of users and developers who can provide support and help with troubleshooting.
Getting started with Puleeno CMS

## To get started with Puleeno CMS, you can follow these steps:

Download the Puleeno CMS installation package from the Puleeno CMS website.
Install the Puleeno CMS installation package on your web server.
Create a database for Puleeno CMS.
Configure Puleeno CMS.
Start using Puleeno CMS to create and manage your website or digital content.
Support

If you need help with Puleeno CMS, you can visit the Puleeno CMS website or join the Puleeno CMS community forum.

## Webserver Configs

### NGINX

```
server {
Expand All @@ -23,4 +56,17 @@ server {
}
}
```
```

# License

Puleeno CMS is licensed under the MIT license.

# Contributors

Puleeno CMS is developed and maintained by a community of volunteers.

# Credits

Puleeno CMS uses a variety of open-source software libraries and components.

7 changes: 7 additions & 0 deletions app/Console/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace App\Console;
use Slim\Console\App;

class Application extends App {
}
1 change: 1 addition & 0 deletions app/Core/Auth/AuthManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
71 changes: 71 additions & 0 deletions app/Facades/AuthFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace App\Facades;

use App\Http\Middleware\AuthGuard;
use Psr\Container\ContainerInterface;

class AuthFacade extends Facade
{
protected static function getFacadeAccessor()
{
return 'auth';
}

public function __construct(ContainerInterface $container)
{
parent::__construct($container);
}

/**
* Tạo guard mới.
*
* @return AuthGuard
*/
public static function factory(): AuthGuard
{
return new AuthGuard();
}

/**
* Lấy guard hiện tại.
*
* @return AuthGuard
*/
public static function get(): AuthGuard
{
return app(AuthGuard::class);
}

/**
* Xác thực người dùng.
*
* @param string $email
* @param string $password
* @return bool
*/
public static function attempt(string $email, string $password): bool
{
return self::get()->attempt($email, $password);
}

/**
* Kiểm tra xem người dùng đã đăng nhập hay chưa.
*
* @return bool
*/
public static function check(): bool
{
return self::get()->check();
}

/**
* Đăng xuất người dùng.
*
* @return void
*/
public static function logout(): void
{
self::get()->logout();
}
}
31 changes: 31 additions & 0 deletions app/Facades/Facade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Facades;

use Psr\Container\ContainerInterface;

abstract class Facade
{
protected static $container;

public static function setContainer(ContainerInterface $container)
{
static::$container = $container;
}

public static function getFacadeAccessor()
{
throw new \RuntimeException('Facade does not have a facade accessor.');
}

public static function __callStatic($method, $args)
{
$instance = static::$container->get(static::getFacadeAccessor());

if (! method_exists($instance, $method)) {
throw new \BadMethodCallException(sprintf('Method %s does not exist on facade %s.', $method, get_class($instance)));
}

return $instance->$method(...$args);
}
}
21 changes: 21 additions & 0 deletions app/Facades/UserServiceFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Facades;
use Psr\Container\ContainerInterface;

class UserServiceFacade extends Facade
{
const FACADE_ACCESSOR = 'user_service';

protected $container;

public function __construct(ContainerInterface $container)
{
$this->container = $container;
}

public function __get($name)
{
return $this->container->get(self::FACADE_ACCESSOR);
}
}
54 changes: 54 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace App\Http;

use App\Http\Middleware\AuthGuard;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\App;
use Slim\Middleware\ErrorMiddleware;
use Slim\Routing\RouteCollector;

class Kernel
{
/**
* @var App
*/
private $app;

/**
* Constructor.
*
* @param App $app
*/
public function __construct(App $app)
{
$this->app = $app;
}

/**
* Configure the application.
*/
public function configure()
{
$this->app->addRoutingMiddleware();
$this->app->addErrorMiddleware(true, true, true);

// Add your middleware here
$this->app->add(new AuthGuard($this->app->getContainer()->get('user_repository')));

// Add your routes here
$this->mapRoutes();
}

/**
* Map the routes.
*/
private function mapRoutes()
{
$this->app->get('/', function (ServerRequestInterface $request, ResponseInterface $response) {
return $response->withJson(['message' => 'Hello, world!']);
});
}
}

54 changes: 54 additions & 0 deletions app/Http/Middleware/AuthGuard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace App\Http\Middleware;

use App\Models\User;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Middleware\JwtAuthentication;

class AuthGuard
{
/**
* The user model.
*
* @var \App\Models\User
*/
protected $user;

/**
* Create a new auth guard instance.
*
* @param \App\Models\User $user
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}

/**
* Handle an incoming request.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable $next
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
$account = $request->get('account');
$password = $request->get('password');

$user = $this->userService->findUserByAccountAndPassword($account, $password);

if (!$user) {
abort(401);
}

// Set the user in the request attributes
$request = $request->withAttribute('user', $user);

return $next($request, $response);
}
}
Loading

0 comments on commit 926e4e1

Please sign in to comment.