Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-paul committed Jun 13, 2023
0 parents commit 3893d52
Show file tree
Hide file tree
Showing 14 changed files with 460 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Ignore all test and documentation for archive
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/docs export-ignore
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms

github: [klimov-paul]
patreon: klimov_paul
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
### What steps will reproduce the problem?

### What is the expected result?

### What do you get instead?

### Additional info

| Q | A
|-----------------------| ---
| This Package Version | 1.?.?
| Yii Framework Version | 1.1.?
| PHP version |
| Operating system |
7 changes: 7 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
| Q | A
| ------------- | ---
| Is bugfix? | ✔️/❌
| New feature? | ✔️/❌
| Breaks BC? | ✔️/❌
| Tests pass? | ✔️/❌
| Fixed issues | comma-separated list of tickets # fixed by the PR, if any
31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: build

on: [push, pull_request]

jobs:
phpunit:
name: PHP ${{ matrix.php }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, pdo, sqlite, pdo_sqlite
tools: composer:v2
coverage: none

- name: Install dependencies
run: |
composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
- name: Run unit tests
run: vendor/bin/phpunit --colors=always
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# phpstorm project files
.idea

# netbeans project files
nbproject

# zend studio for eclipse project files
.buildpath
.project
.settings

# windows thumbnail cache
Thumbs.db

# composer vendor dir
/vendor

/composer.lock

# composer itself is not needed
composer.phar

# Mac DS_Store Files
.DS_Store

# phpunit itself is not needed
phpunit.phar
# local phpunit config
/phpunit.xml
# phpunit cache
.phpunit.result.cache

# test runtime files
/.phpunit.cache
/tests/runtime
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Yii1 Advanced Web User extension
================================

1.0.0 Under Development
-----------------------

- Initial release.
32 changes: 32 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
This is free software. It is released under the terms of the
following BSD License.

Copyright © 2023 by Yii1Tech (https://github.com/yii1tech)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Yii1Tech nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<p align="center">
<a href="https://github.com/yii1tech" target="_blank">
<img src="https://avatars.githubusercontent.com/u/134691944" height="100px">
</a>
<h1 align="center">Advanced web user component for Yii 1</h1>
<br>
</p>

This extension provides advanced web user component for Yii 1.

For license information check the [LICENSE](LICENSE.md)-file.

[![Latest Stable Version](https://img.shields.io/packagist/v/yii1tech/web-user.svg)](https://packagist.org/packages/yii1tech/web-user)
[![Total Downloads](https://img.shields.io/packagist/dt/yii1tech/web-user.svg)](https://packagist.org/packages/yii1tech/web-user)
[![Build Status](https://github.com/yii1tech/web-user/workflows/build/badge.svg)](https://github.com/yii1tech/web-user/actions)


Installation
------------

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist yii1tech/web-user
```

or add

```json
"yii1tech/web-user": "*"
```

to the "require" section of your composer.json.


Usage
-----

This extension
40 changes: 40 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "yii1tech/web-user",
"description": "Provides advanced web user component for Yii1",
"keywords": ["yii1", "web", "user", "auth", "event", "model"],
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yii1tech/web-user/issues",
"wiki": "https://github.com/yii1tech/web-user/wiki",
"source": "https://github.com/yii1tech/web-user"
},
"authors": [
{
"name": "Paul Klimov",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.1",
"yiisoft/yii": "~1.1.3"
},
"require-dev": {
"phpunit/phpunit": "^6.0 || ^7.0 || ^8.0 || ^9.3 || ^10.0.7",
"yii1tech/session-dummy": "^1.0.0"
},
"autoload": {
"psr-4": {
"yii1tech\\web\\user\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"yii1tech\\web\\user\\test\\": "tests"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
}
15 changes: 15 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit bootstrap="./tests/bootstrap.php"
colors="true"
backupGlobals="false"
backupStaticProperties="false"
processIsolation="false"
cacheDirectory=".phpunit.cache"
stopOnError="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Yii1tech Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
148 changes: 148 additions & 0 deletions src/WebUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php

namespace yii1tech\web\user;

use CEvent;
use CWebUser;

/**
* WebUser extends the standard Yii class {@see \CWebUser}, providing handlers for the following events:
*
* - {@see onAfterRestore} - raises after user data restoration;
* - {@see onBeforeLogin} - raises before user logs in;
* - {@see onAfterLogin} - raises after user successfully logged in;
* - {@see onBeforeLogout} - raises before user logs out;
* - {@see onAfterLogout} - raises after user successfully logged out;
*
* @author Paul Klimov <[email protected]>
* @since 1.0
*/
class WebUser extends CWebUser
{
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();

$this->afterRestore();
}

/**
* This method is invoked after a user data has been restored from any source:
* session, autologin cookies etc.
* The default implementation raises the {@see onAfterRestore} event.
* You may override this method to do postprocessing after component initialization.
* Make sure you call the parent implementation so that the event is raised properly.
*/
protected function afterRestore(): void
{
if ($this->hasEventHandler('onAfterRestore')) {
$this->onAfterRestore(new CEvent($this));
}
}

/**
* This event is raised after the user data has been restored from any source:
* session, autologin cookies etc.
* @param \CEvent $event the event parameter
*/
public function onAfterRestore($event): void
{
$this->raiseEvent('onAfterRestore', $event);
}

/**
* {@inheritdoc}
*/
protected function beforeLogin($id, $states, $fromCookie)
{
$allowLogin = true;

if ($this->hasEventHandler('onBeforeLogin')) {
$this->onBeforeLogin(new CEvent($this, [
'allowLogin' => &$allowLogin,
'id' => $id,
'states' => $states,
'fromCookie' => $fromCookie,
]));
}

return $allowLogin;
}

/**
* This event is raised before logging in a user.
* @param \CEvent $event the event parameter
*/
public function onBeforeLogin($event): void
{
$this->raiseEvent('onBeforeLogin', $event);
}

/**
* {@inheritdoc}
*/
protected function afterLogin($fromCookie)
{
if ($this->hasEventHandler('onAfterLogin')) {
$this->onAfterLogin(new CEvent($this, [
'fromCookie' => $fromCookie,
]));
}
}

/**
* This event is raised after the user is successfully logged in.
* @param \CEvent $event the event parameter
*/
public function onAfterLogin($event): void
{
$this->raiseEvent('onAfterLogin', $event);
}

/**
* {@inheritdoc}
*/
protected function beforeLogout()
{
$allowLogout = true;

if ($this->hasEventHandler('onBeforeLogout')) {
$this->onBeforeLogout(new CEvent($this, [
'allowLogout' => &$allowLogout,
]));
}

return $allowLogout;
}

/**
* This event is raised before logging out a user.
* @param \CEvent $event the event parameter
*/
public function onBeforeLogout($event): void
{
$this->raiseEvent('onBeforeLogout', $event);
}

/**
* {@inheritdoc}
*/
protected function afterLogout()
{
if ($this->hasEventHandler('onAfterLogout')) {
$this->onAfterLogout(new CEvent($this));
}
}

/**
* This event is raised after a user is logged out.
* @param \CEvent $event the event parameter
*/
public function onAfterLogout($event): void
{
$this->raiseEvent('onAfterLogout', $event);
}
}
Loading

0 comments on commit 3893d52

Please sign in to comment.