定制 hardevine/laravel-session-tracker 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hardevine/laravel-session-tracker

Composer 安装命令:

composer require hardevine/laravel-session-tracker

包简介

This package provides session tracking functionalities, multisession management and user device management features for laravel applications.

README 文档

README

This package provides session tracking functionalities, multisession management and user device management features for laravel applications.

Features

  • Session Management
  • Session Log
  • Multiple session for users
  • Request Log
  • User Devices

Installation (Laravel 5.x)

In composer.json:

"require": {
    "hardevine/laravel-session-tracker" "1.0.0"
}

Run:

composer update

Note: For v 5.5 Auto-discovery takes care.

Add the service provider to config/app.php under providers:

'providers' => [
    Hamedmehryar\SessionTracker\SessionTrackerServiceProvider::class,
]

Add the SessionTracker alias to config/app.php under aliases:

    'aliases' => [
        'SessionTracker' => 'Hamedmehryar\SessionTracker\SessionTrackerFacade',
    ]

Update config file to reference your login and logout route names:

config/sessionTracker.php

Migrate your database:

php artisan migrate

Add the trait to your user model:

use Hamedmehryar\SessionTracker\Traits\SessionTrackerUserTrait;

class User extends Model {
	use SessionTrackerUserTrait;
}

Add the DeviceCheck middleware in your kernel.php file:

protected $middleware = [
		'Hamedmehryar\SessionTracker\Middleware\DeviceCheck',
	];

In Your routes.php file you should add 'session' middleware for routes which you want to keep track of:

Route::group(['middleware'=>'session'], function(){

    Route::get('your-route', 'YourController@yourAction');

});

Usage

From your user models:

$user->sessions(); //returns all the sessions of the user form the begining of usage of the package

$user->activeSessions(); //returns all currently active sessions for the user. (User may be logged in with same credentials from different devices)

$user->activeSessions(true); //return all active sessions for the user except the current session.

$user->getFreshestSession(); //Returns the most recent session of the user

$user->devices(); //Returns the collection of users saved trusted devices.

$user->devicesUids(); //Returns array of users saved trusted devices Ids.

From SessionTrackerFacade:

SessionTracker::startSession(); //Creates a new session for current user

SessionTracker::endSession(); //End the current session for the current user

SessionTracker::endSession(true); //End the current session for the current user and forgets the session

SessionTracker::renewSession(); //Restarts the ended session which is not forgotten for the current user. Usefull for restarting the session after locking it for inactivity

SessionTracker::refreshSession($request); //Keeps the session alive for each request. Useful in middleware

SessionTracker::logSession($request); //Logs the current request for the current session. (request logs stored in sessiontracker_session_requests table)

SessionTracker::isSessionInactive(); //Checks if the session is inactive. Determines the inactiveness by subtracting the **delay between last activity and current time** from the **inactivity_seconds** in sessionTracker config file.

SessionTracker::isSessionInactive($user); //Checks if the session for a specific user is inactive. Determines the inactiveness by subtracting the **delay between last activity and current time** from the **inactivity_seconds** in sessionTracker config file.

SessionTracker::blockSession($sessionId); //Blocks (ends and forgets) the current session for the user. (Useful if the user wants to controll all her sessions and block a specific session in a specific location)

SessionTracker::sessionRequests($sessionId); //Returns all requests done by a specific session

SessionTracker::isSessionBlocked(); //Checks if current user does not have an active session

SessionTracker::lockSessionByCode(); //Locks a session by a security code to be unlocked by that code and returns the code. (Usefull for two-step authentication implementation)

SessionTracker::securityCode(); //Returns the security code (hash) for the locked session.

SessionTracker::isSessionLocked(); //Checks if the current session is locked by a security code.

SessionTracker::unlockSessionByCode($code); //Unlocks the locked session by passing the security code. (returns -1 if the code is invalid, -2 if it's expired and 0 if success)

SessionTracker::isUserDevice(); //Returns true if the current device is trusted by the user

SessionTracker::deleteDevice($id); //Deletes a trusted device for the user

SessionTracker::addUserDevice(); //Add the current device as trusted by the user

SessionTracker::forgotSession(); //Checks if the session if forgotten

SessionTracker::sessionId(); //Returns the sessionId for the current session

SessionTracker::deleteSession(); //Deletes and forgets the current session

SessionTracker::refreshSecurityCode(); //Renews the security code by which the current session is locked

Author

hardevine/laravel-session-tracker 适用场景与选型建议

hardevine/laravel-session-tracker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.96k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2018 年 11 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 hardevine/laravel-session-tracker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hardevine/laravel-session-tracker 我们能提供哪些服务?
定制开发 / 二次开发

基于 hardevine/laravel-session-tracker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 11.96k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-24