Skip to content

Commit

Permalink
Merge pull request #38 from oc-shopaholic/develop
Browse files Browse the repository at this point in the history
Release version 1.8.0
  • Loading branch information
kharanenka authored Oct 18, 2019
2 parents 303137f + 9aa0468 commit a856476
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 31 deletions.
7 changes: 7 additions & 0 deletions classes/AuthHelperManager.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Lovata\Buddies\Classes;

use Lang;
use Event;
use Cookie;
use Session;
use Kharanenka\Helper\Result;
Expand Down Expand Up @@ -110,9 +111,15 @@ public function login(Authenticatable $obUser, $bRemember = false)
*/
public function logout()
{
$obUser = $this->user;

$this->requireActivation = false;
parent::logout();
$this->requireActivation = true;

if (!empty($obUser)) {
Event::fire(User::EVENT_LOGOUT, [$obUser]);
}
}

/**
Expand Down
83 changes: 53 additions & 30 deletions models/User.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Lovata\Buddies\Models;

use Event;
use October\Rain\Database\Traits\SoftDelete;

use Kharanenka\Scope\NameField;
Expand All @@ -12,40 +13,40 @@
/**
* Class User
* @package Lovata\Buddies\Models
* @author Andrey Kharanenka, [email protected], LOVATA Group
* @author Andrey Kharanenka, [email protected], LOVATA Group
*
* @mixin \October\Rain\Database\Builder
* @mixin \Eloquent
*
* @property int $id
* @property bool $is_activated
* @property string $email
* @property string $password
* @property bool $password_change
* @property string $password_confirmation
* @property string $name
* @property string $last_name
* @property string $middle_name
* @property string $phone
* @property string $phone_short
* @property array $phone_list
* @property string $activation_code
* @property string $persist_code
* @property string $reset_password_code
* @property string $permissions
* @property \October\Rain\Argon\Argon $activated_at
* @property \October\Rain\Argon\Argon $last_login
* @property bool $is_superuser
* @property array $property
* @property \October\Rain\Argon\Argon $created_at
* @property \October\Rain\Argon\Argon $updated_at
* @property \October\Rain\Argon\Argon $deleted_at
* @property int $id
* @property bool $is_activated
* @property string $email
* @property string $password
* @property bool $password_change
* @property string $password_confirmation
* @property string $name
* @property string $last_name
* @property string $middle_name
* @property string $phone
* @property string $phone_short
* @property array $phone_list
* @property string $activation_code
* @property string $persist_code
* @property string $reset_password_code
* @property string $permissions
* @property \October\Rain\Argon\Argon $activated_at
* @property \October\Rain\Argon\Argon $last_login
* @property bool $is_superuser
* @property array $property
* @property \October\Rain\Argon\Argon $created_at
* @property \October\Rain\Argon\Argon $updated_at
* @property \October\Rain\Argon\Argon $deleted_at
*
* @property \System\Models\File $avatar
* @property \System\Models\File $avatar
*
* @property \October\Rain\Database\Collection|Group[] $groups
* @property \October\Rain\Database\Collection|Group[] $groups
*
* @property \October\Rain\Database\Collection|SocialiteToken[] $socialite_token
* @property \October\Rain\Database\Collection|SocialiteToken[] $socialite_token
* @method static \October\Rain\Database\Relations\HasMany|SocialiteToken socialite_token()
*
* @method static $this active()
Expand All @@ -54,10 +55,10 @@
* @method static $this getByEmail(string $sEmail)
*
* Orders for Shopaholic plugin
* @property \Lovata\OrdersShopaholic\Models\Order[]|\October\Rain\Database\Collection $order
* @property \Lovata\OrdersShopaholic\Models\Order[]|\October\Rain\Database\Collection $order
* @method static \October\Rain\Database\Relations\HasMany|\Lovata\OrdersShopaholic\Models\Order order()
* @property \Lovata\OrdersShopaholic\Classes\Collection\OrderCollection|\Lovata\OrdersShopaholic\Classes\Item\OrderItem[] $order_list
* @property \Lovata\OrdersShopaholic\Models\UserAddress[]|\October\Rain\Database\Collection $address
* @property \Lovata\OrdersShopaholic\Classes\Collection\OrderCollection|\Lovata\OrdersShopaholic\Classes\Item\OrderItem[] $order_list
* @property \Lovata\OrdersShopaholic\Models\UserAddress[]|\October\Rain\Database\Collection $address
* @method static \October\Rain\Database\Relations\HasMany|\Lovata\OrdersShopaholic\Models\UserAddress address()
* @property \Lovata\OrdersShopaholic\Classes\Collection\UserAddressCollection|\Lovata\OrdersShopaholic\Classes\Item\UserAddressItem[] $address_list
*/
Expand All @@ -69,6 +70,10 @@ class User extends UserModel
use TraitCached;
use SetPropertyAttributeTrait;

const EVENT_BEFORE_LOGIN = 'lovata.buddies.before.login';
const EVENT_AFTER_LOGIN = 'lovata.buddies.after.login';
const EVENT_LOGOUT = 'lovata.buddies.logout';

public $table = 'lovata_buddies_users';

public $rules = [
Expand Down Expand Up @@ -122,6 +127,24 @@ class User extends UserModel
'socialite_token' => [SocialiteToken::class],
];

/**
* Fire before login event
*/
public function beforeLogin()
{
Event::fire(self::EVENT_BEFORE_LOGIN, [$this]);
}

/**
* Fire after login event
*/
public function afterLogin()
{
parent::afterLogin();

Event::fire(self::EVENT_AFTER_LOGIN, [$this]);
}

/**
* Before delete model method
*/
Expand Down
4 changes: 3 additions & 1 deletion updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@
1.7.1:
- 'Added SoftDelete trait to User model.'
1.7.2:
- 'Fixed login method, after updating OctoberCMS v1.0.455'
- 'Fixed login method, after updating OctoberCMS v1.0.455'
1.8.0:
- 'Added lovata.buddies.before.login, lovata.buddies.after.login, lovata.buddies.logout events'

0 comments on commit a856476

Please sign in to comment.