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 )
35[ ![ Opensource ByJG] ( https://img.shields.io/badge/opensource-byjg-success.svg )] ( http://opensource.byjg.com )
46[ ![ GitHub source] ( https://img.shields.io/badge/Github-source-informational?logo=github )] ( https://github.com/byjg/authuser/ )
57[ ![ GitHub license] ( https://img.shields.io/github/license/byjg/authuser.svg )] ( https://opensource.byjg.com/opensource/licensing.html )
68[ ![ GitHub release] ( https://img.shields.io/github/release/byjg/authuser.svg )] ( https://github.com/byjg/authuser/releases/ )
7- [ ![ SensioLabsInsight] ( https://insight.sensiolabs.com/projects/69f04d22-055d-40b5-8c8d-90598a5367b5/mini.png )] ( https://insight.sensiolabs.com/projects/69f04d22-055d-40b5-8c8d-90598a5367b5 )
8- [ ![ Scrutinizer Code Quality] ( https://scrutinizer-ci.com/g/byjg/authuser/badges/quality-score.png?b=master )] ( https://scrutinizer-ci.com/g/byjg/authuser/?branch=master )
9- [ ![ Build Status] ( https://travis-ci.com/byjg/authuser.svg?branch=master )] ( https://travis-ci.com/byjg/authuser )
109
1110
1211A simple and customizable class for enable user authentication inside your application. It is available on XML files, Relational Databases and Moodle.
@@ -139,23 +138,35 @@ If you do not know to create/manage that unique prefix **prefer to use the regul
139138
140139## Architecture
141140
141+ ``` text
142+ ┌───────────────────┐
143+ │ SessionContext │
144+ └───────────────────┘
145+ │
146+ ┌────────────────────────┐ ┌────────────────────────┐
147+ │ UserDefinition │─ ─ ┐ │ ─ ─ ┤ UserModel │
148+ └────────────────────────┘ ┌───────────────────┐ │ └────────────────────────┘
149+ ┌────────────────────────┐ └────│ UsersInterface │────┐ ┌────────────────────────┐
150+ │ UserPropertyDefinition │─ ─ ┘ └───────────────────┘ ─ ─ ┤ UserPropertyModel │
151+ └────────────────────────┘ ▲ └────────────────────────┘
152+ │
153+ ┌────────────────────────┼─────────────────────────┐
154+ │ │ │
155+ │ │ │
156+ │ │ │
157+ ┌───────────────────┐ ┌───────────────────┐ ┌────────────────────┐
158+ │ UsersAnyDataset │ │ UsersDBDataset │ │ UsersMoodleDataset │
159+ └───────────────────┘ └───────────────────┘ └────────────────────┘
142160```
143- +----------------+ +----------------+
144- | | | |
145- | UsersInterface |------------| SessionContext |
146- | | | |
147- +----------------+ +----------------+
148- ^
149- |
150- |
151- +-----------------------+--------------------------+
152- | | |
153- +-----------------+ +----------------+ +--------------------+
154- | | | | | |
155- | UsersAnyDataset | | UsersDBDataset | | UsersMoodleDataset |
156- | | | | | |
157- +-----------------+ +----------------+ +--------------------+
158- ```
161+
162+ - UserInterface contain the basic interface for the concrete implementation
163+ - UsersDBDataset is a concrete implementation to retrieve/save user in a Database
164+ - 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.
166+ - UserModel is the basic model get/set for the user
167+ - UserPropertyModel is the basic model get/set for extra user property
168+ - UserDefinition will map the model to the database
169+
159170
160171### Database
161172
@@ -213,13 +224,13 @@ $userDefinition = new \ByJG\Authenticate\Definition\UserDefinition(
213224 \ByJG\Authenticate\Model\UserModel::class, // Model class
214225 \ByJG\Authenticate\Definition\UserDefinition::LOGIN_IS_EMAIL,
215226 [
216- 'userid' => 'fieldname of userid',
217- 'name' => 'fieldname of name',
218- 'email' => 'fieldname of email',
219- 'username' => 'fieldname of username',
220- 'password' => 'fieldname of password',
221- 'created' => 'fieldname of created',
222- 'admin' => 'fieldname of admin'
227+ UserDefinition::FIELD_USERID => 'fieldname of userid',
228+ UserDefinition::FIELD_NAME => 'fieldname of name',
229+ UserDefinition::FIELD_EMAIL => 'fieldname of email',
230+ UserDefinition::FIELD_USERNAME => 'fieldname of username',
231+ UserDefinition::FIELD_PASSWORD => 'fieldname of password',
232+ UserDefinition::FIELD_CREATED => 'fieldname of created',
233+ UserDefinition::FIELD_ADMIN => 'fieldname of admin'
223234 ]
224235);
225236```
@@ -234,23 +245,23 @@ $userDefinition = new \ByJG\Authenticate\Definition\UserDefinition(
234245 \ByJG\Authenticate\Definition\UserDefinition::LOGIN_IS_EMAIL
235246);
236247
237- // Defines a custom function to be applied BEFORE update/insert the field 'password'
248+ // Defines a custom function to be applied BEFORE update/insert the field UserDefinition::FIELD_PASSWORD
238249// $value --> the current value to be updated
239250// $instance -> The array with all other fields;
240- $userDefinition->defineClosureForUpdate('password' , function ($value, $instance) {
251+ $userDefinition->defineClosureForUpdate(UserDefinition::FIELD_PASSWORD , function ($value, $instance) {
241252 return strtoupper(sha1($value));
242253});
243254
244- // Defines a custom function to be applied After the field 'created' is read but before
255+ // Defines a custom function to be applied After the field UserDefinition::FIELD_CREATED is read but before
245256// the user get the result
246257// $value --> the current value retrieved from database
247258// $instance -> The array with all other fields;
248- $userDefinition->defineClosureForSelect('created' , function ($value, $instance) {
259+ $userDefinition->defineClosureForSelect(UserDefinition::FIELD_CREATED , function ($value, $instance) {
249260 return date('Y', $value);
250261});
251262
252263// If you want make the field READONLY just do it:
253- $userDefinition->markPropertyAsReadOnly('created' );
264+ $userDefinition->markPropertyAsReadOnly(UserDefinition::FIELD_CREATED );
254265```
255266
256267
0 commit comments