Skip to content

Commit b7f762f

Browse files
authored
Merge pull request #9 from byjg/4.9
4.9
2 parents 8ce4222 + 1a3999e commit b7f762f

11 files changed

+134
-115
lines changed

.github/workflows/phpunit.yml

+9-11
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,22 @@ jobs:
1616
strategy:
1717
matrix:
1818
php-version:
19+
- "8.2"
1920
- "8.1"
2021
- "8.0"
2122
- "7.4"
22-
- "7.3"
23-
- "7.2"
24-
- "7.1"
2523

2624
steps:
27-
- uses: actions/checkout@v2
25+
- uses: actions/checkout@v4
2826
- run: composer install
2927
- run: ./vendor/bin/phpunit --stderr
3028

3129
Documentation:
32-
runs-on: 'ubuntu-latest'
33-
needs: Build
3430
if: github.ref == 'refs/heads/master'
35-
env:
36-
DOC_GITHUB_TOKEN: '${{ secrets.DOC_TOKEN }}'
37-
steps:
38-
- uses: actions/checkout@v2
39-
- run: curl https://opensource.byjg.com/add-doc.sh | bash /dev/stdin php authuser
31+
needs: Build
32+
uses: byjg/byjg.github.io/.github/workflows/add-doc.yaml@master
33+
with:
34+
folder: php
35+
project: ${{ github.event.repository.name }}
36+
secrets: inherit
37+

.vscode/launch.json

-38
This file was deleted.

README.md

+51-50
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
# Auth User PHP
22

3-
4-
[![Build Status](https://github.com/byjg/authuser/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/byjg/authuser/actions/workflows/phpunit.yml)
3+
[![Build Status](https://github.com/byjg/php-authuser/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/byjg/php-authuser/actions/workflows/phpunit.yml)
54
[![Opensource ByJG](https://img.shields.io/badge/opensource-byjg-success.svg)](http://opensource.byjg.com)
6-
[![GitHub source](https://img.shields.io/badge/Github-source-informational?logo=github)](https://github.com/byjg/authuser/)
7-
[![GitHub license](https://img.shields.io/github/license/byjg/authuser.svg)](https://opensource.byjg.com/opensource/licensing.html)
8-
[![GitHub release](https://img.shields.io/github/release/byjg/authuser.svg)](https://github.com/byjg/authuser/releases/)
9-
5+
[![GitHub source](https://img.shields.io/badge/Github-source-informational?logo=github)](https://github.com/byjg/php-authuser/)
6+
[![GitHub license](https://img.shields.io/github/license/byjg/php-authuser.svg)](https://opensource.byjg.com/opensource/licensing.html)
7+
[![GitHub release](https://img.shields.io/github/release/byjg/php-authuser.svg)](https://github.com/byjg/php-authuser/releases/)
108

119
A simple and customizable class for enable user authentication inside your application. It is available on XML files, Relational Databases and Moodle.
1210

13-
The main purpose is just to handle all complexity of validate a user, add properties and create access token abstracting the database layer.
14-
This class can persist into session (or file, memcache, etc) the user data between requests.
11+
The main purpose is just to handle all complexity of validate a user, add properties and create access token abstracting the database layer.
12+
This class can persist into session (or file, memcache, etc) the user data between requests.
1513

1614
## Creating a Users handling class
1715

18-
19-
**Using the FileSystem (XML) as the user storage**
16+
Using the FileSystem (XML) as the user storage:
2017

2118
```php
2219
<?php
2320
$users = new UsersAnyDataset('/tmp/pass.anydata.xml');
2421
```
2522

26-
**Using the Database as the user storage**
23+
Using the Database as the user storage:
2724

2825
```php
2926
<?php
@@ -37,14 +34,13 @@ $users = new ByJG\Authenticate\UsersDBDataset(
3734
*Note*: See the [Anydataset project](https://github.com/byjg/anydataset#connection-based-on-uri) to see the
3835
database available and the connection strings as well.
3936

40-
**Using the Moodle as the user storage**
37+
Using the Moodle as the user storage:
4138

4239
```php
4340
<?php
4441
$users = new UsersMoodleDataset('connection');
4542
```
4643

47-
4844
## Authenticate a user with your username and password and persist into the session
4945

5046
```php
@@ -53,7 +49,7 @@ $user = $users->isValidUser('someuser', '12345');
5349
if (!is_null($user))
5450
{
5551
$userId = $user->getUserid();
56-
52+
5753
$sessionContext = new \ByJG\Authenticate\SessionContext(\ByJG\Cache\Factory::createSessionPool());
5854
$sessionContext->registerLogin($userId);
5955
}
@@ -67,7 +63,7 @@ $sessionContext = new \ByJG\Authenticate\SessionContext(\ByJG\Cache\Factory::cre
6763

6864
// Check if the user is authenticated
6965
if ($sessionContext->isAuthenticated()) {
70-
66+
7167
// Get the userId of the authenticated users
7268
$userId = $sessionContext->userInfo();
7369

@@ -77,20 +73,20 @@ if ($sessionContext->isAuthenticated()) {
7773
}
7874
```
7975

80-
## Saving extra info into the user session
76+
## Saving extra info into the user session
8177

8278
You can save data in the session data exists only during the user is logged in. Once the user logged off the
8379
data stored with the user session will be released.
8480

85-
**Store the data for the current user session**
81+
Store the data for the current user session:
8682

8783
```php
8884
<?php
8985
$sessionContext = new \ByJG\Authenticate\SessionContext(\ByJG\Cache\Factory::createSessionPool());
9086
$sessionContext->setSessionData('key', 'value');
9187
```
9288

93-
**Getting the data from the current user session**
89+
Getting the data from the current user session:
9490

9591
```php
9692
<?php
@@ -100,7 +96,7 @@ $value = $sessionContext->getSessionData('key');
10096

10197
Note: If the user is not logged an error will be throw
10298

103-
## Adding a custom property to the users;
99+
## Adding a custom property to the users
104100

105101
```php
106102
<?php
@@ -115,17 +111,18 @@ $users->save();
115111
<?php
116112
$sessionContext->registerLogout();
117113
```
118-
# Important note about SessionContext
119114

120-
`SessionContext` object will store the info about the current context.
115+
## Important note about SessionContext
116+
117+
`SessionContext` object will store the info about the current context.
121118
As SessionContext uses CachePool interface defined in PSR-6 you can set any storage
122-
to save your session context.
119+
to save your session context.
123120

124121
In our examples we are using a regular PHP Session for store the user context
125122
(`Factory::createSessionPool()`). But if you are using another store like MemCached
126123
you have to define a UNIQUE prefix for that session. Note if TWO users have the same
127124
prefix you probably have an unexpected result for the SessionContext.
128-
125+
129126
Example for memcached:
130127

131128
```php
@@ -135,39 +132,37 @@ $sessionContext = new \ByJG\Authenticate\SessionContext(\ByJG\Cache\Factory::cre
135132

136133
If you do not know to create/manage that unique prefix **prefer to use the regular Session object.**
137134

138-
139135
## Architecture
140136

141137
```text
142-
┌───────────────────┐
143-
│ SessionContext │
144-
└───────────────────┘
145-
138+
┌───────────────────┐
139+
│ SessionContext │
140+
└───────────────────┘
141+
146142
┌────────────────────────┐ ┌────────────────────────┐
147143
│ UserDefinition │─ ─ ┐ │ ─ ─ ┤ UserModel │
148144
└────────────────────────┘ ┌───────────────────┐ │ └────────────────────────┘
149145
┌────────────────────────┐ └────│ UsersInterface │────┐ ┌────────────────────────┐
150146
│ UserPropertyDefinition │─ ─ ┘ └───────────────────┘ ─ ─ ┤ UserPropertyModel │
151147
└────────────────────────┘ ▲ └────────────────────────┘
152-
153-
┌────────────────────────┼─────────────────────────┐
154-
│ │ │
155-
│ │ │
156-
│ │ │
157-
┌───────────────────┐ ┌───────────────────┐ ┌────────────────────┐
158-
│ UsersAnyDataset │ │ UsersDBDataset │ │ UsersMoodleDataset │
159-
└───────────────────┘ └───────────────────┘ └────────────────────┘
148+
149+
┌────────────────────────┼─────────────────────────┐
150+
│ │ │
151+
│ │ │
152+
│ │ │
153+
┌───────────────────┐ ┌───────────────────┐ ┌────────────────────┐
154+
│ UsersAnyDataset │ │ UsersDBDataset │ │ UsersMoodleDataset │
155+
└───────────────────┘ └───────────────────┘ └────────────────────┘
160156
```
161157

162158
- UserInterface contain the basic interface for the concrete implementation
163159
- UsersDBDataset is a concrete implementation to retrieve/save user in a Database
164160
- UserAnyDataset is a concrete implementation to retrieve/save user in a Xml file
165-
- UsersMoodleDatabase is a concrete implementation to retrieve users in a Moodle database structure.
161+
- UsersMoodleDatabase is a concrete implementation to retrieve users in a Moodle database structure.
166162
- UserModel is the basic model get/set for the user
167163
- UserPropertyModel is the basic model get/set for extra user property
168164
- UserDefinition will map the model to the database
169165

170-
171166
### Database
172167

173168
The default structure adopted for store the user data in the database through the
@@ -184,7 +179,7 @@ create table users
184179
created datetime,
185180
admin enum('Y','N'),
186181

187-
constraint pk_users primary key (userid)
182+
constraint pk_users primary key (userid)
188183
)
189184
ENGINE=InnoDB;
190185

@@ -264,12 +259,11 @@ $userDefinition->defineClosureForSelect(UserDefinition::FIELD_CREATED, function
264259
$userDefinition->markPropertyAsReadOnly(UserDefinition::FIELD_CREATED);
265260
```
266261

267-
268262
## Extending UserModel
269263

270-
It is possible extending the UserModel table, since you create a new class extending from UserModel to add the new fields.
264+
It is possible extending the UserModel table, since you create a new class extending from UserModel to add the new fields.
271265

272-
For example, imagine your table has one field called "otherfield".
266+
For example, imagine your table has one field called "otherfield".
273267

274268
You'll have to extend like this:
275269

@@ -278,7 +272,7 @@ You'll have to extend like this:
278272
/**
279273
* This class is your model
280274
* This need to support the basic field plus your new fields
281-
* already set in your definition class
275+
* already set in your definition class
282276
*/
283277
class MyUserModel extends UserModel
284278
{
@@ -317,22 +311,29 @@ $users = new ByJG\Authenticate\UsersDBDataset(
317311
);
318312
```
319313

320-
321-
322314
## Install
323315

324-
Just type:
316+
Just type:
325317

326-
```
327-
composer require "byjg/authuser=4.3.*"
318+
```bash
319+
composer require "byjg/authuser"
328320
```
329321

330322
## Running Tests
331323

332324
Because this project uses PHP Session you need to run the unit test the following manner:
333-
325+
326+
```bash
327+
./vendor/bin/phpunit --stderr
334328
```
335-
phpunit --stderr
329+
330+
## Dependencies
331+
332+
```mermaid
333+
flowchart TD
334+
byjg/authuser --> byjg/micro-orm
335+
byjg/authuser --> byjg/cache-engine
336+
byjg/authuser --> byjg/jwt-wrapper
336337
```
337338

338339

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"minimum-stability": "dev",
1010
"prefer-stable": true,
1111
"require": {
12-
"php": ">=5.6.0",
12+
"php": ">=7.4",
1313
"byjg/micro-orm": "4.9.*",
1414
"byjg/cache-engine": "4.9.*",
1515
"byjg/jwt-wrapper": "4.9.*"

phpunit.xml.dist

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and open the template in the editor.
1313
convertNoticesToExceptions="true"
1414
convertWarningsToExceptions="true"
1515
convertDeprecationsToExceptions="true"
16+
stderr="true"
1617
stopOnFailure="false">
1718

1819
<php>
@@ -26,11 +27,11 @@ and open the template in the editor.
2627
<directory>./src</directory>
2728
</whitelist>
2829
</filter>
29-
30+
3031
<testsuites>
3132
<testsuite name="Test Suite">
3233
<directory>./tests/</directory>
3334
</testsuite>
3435
</testsuites>
35-
36+
3637
</phpunit>

0 commit comments

Comments
 (0)