This package is abandoned and no longer maintained. The author suggests using the resist/Auth3 package instead.

Simple authentication platform for Fatfree Framework powered apps

2.0.0 2020-01-21 09:20 UTC

This package is auto-updated.

Last update: 2020-03-07 16:42:38 UTC


README

https://github.com/r3sist/u3

This repository is not a library, it's for personal use only. Authentication platform for Fatfree Framework powered apps.

CodeFactor

Installation

Via composer: "resist/U3": "dev-master"

Required global constants

  • string U3INVITE for invite code (can be empty string)
  • string U3TABLE for user table

Required routes

  • GET @login: /login for login/landing page
  • GET @signup: /signup for signup page

Database

U3 uses one user table. Required columns (but can contain more):

  • uid (int)
  • uname (varchar)
  • upass (varchar)
  • uemail (varchar)
  • urole (int)
  • uapikey (varchar)
  • ucreated (int)
  • uts (int)

U3 uses F3's \DB\SQL $db singleton for connection.

Captcha font file

Copy CopyFontFileToF3UI/captcha.ttf; to your F3 application's UI folder

Usage

Important note:
U3 requires dependency injector container, which is not the default functioning of F3.

Quick setup in your bootstrap file:

$user = $f3->get('CONTAINER')('\resist\U3\U3');
// Above line is to achieve by dependency injector: $user = new \resist\U3\U3(\Base $f3, \DB\SQL $db);

U3 will handle session, create global user related variables and routes in F3 Hive

Defined F3 Hive variables

  • (int) $f3->uid for user ID
    • 0 for not logged in guests
    • >0 for logged in users

For logged in users:

  • (\resist\U3\User) $f3->u for User value object
  • (string) $f3->uname for user name
  • (int) $f3->urole for user role
  • (array) $f3->udata for all user data array (except upass password hash)
  • (bool) $f3->mobile is true if mobile device is detected

Defined routes

  • POST /login
  • GET @logout: /logout
  • POST /signup
  • GET @captcha: /captcha for captcha image

Defined cookies

  • csrf token

Requireed parameters

Signup page

POST data to /signup route:

  • POST uname
  • POST upass
  • POST upassconfirm
  • POST uemail
  • POST uinvite for invite code - can be empty string but required. If capctha image is present (<img href="/captcha" alt="captcha">), captcha code + invite code should be sent

Definition of signup view (GET route, controller, template, client side validation etc.) is not part of this library.

Login page

POST data to /login route:

  • POST uname
  • POST upass

Definition of login view (GET route, controller, template, client side validation etc.) is not part of this library.

Access handler

Quick reroute with flash message.

$access = $di->create('\resist\U3\U3');

$access->forceAdmin('/route', 'Error message'); // minimum role 30
$access->forceUser('/route', 'Error message'); // minimum role 10
$access->forceGuest('/route', 'Error message'); // `uid = 0`
$access->forceMinRole(10, '/route', 'Error message'); 

Loaded user map

$map = $di->create('\resist\U3\Map');
$loadedMap = $map->get();

User value object

Public methods: getUdata(), getUid(), getUname(), getUrole()

License

GNU GPLv3