Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cesargb/laravel-magiclink
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.20.0
Choose a base ref
...
head repository: cesargb/laravel-magiclink
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Nov 13, 2024

  1. add test to php84 (#118)

    cesargb authored Nov 13, 2024
    Copy the full SHA
    4337454 View commit details
  2. Copy the full SHA
    af081f6 View commit details

Commits on Dec 11, 2024

  1. Update composer.json (#119)

    asugai authored Dec 11, 2024
    Copy the full SHA
    2213eaa View commit details

Commits on Dec 25, 2024

  1. Copy the full SHA
    085877a View commit details

Commits on Jan 3, 2025

  1. Copy the full SHA
    b93bbdf View commit details

Commits on Jan 4, 2025

  1. Copy the full SHA
    4938e95 View commit details
  2. add merge config (#124)

    cesargb authored Jan 4, 2025
    Copy the full SHA
    6a529d5 View commit details
  3. Copy the full SHA
    cb0086e View commit details
  4. Copy the full SHA
    7054e37 View commit details
  5. refactor service provider

    cesargb committed Jan 4, 2025
    Copy the full SHA
    af53d51 View commit details
  6. Copy the full SHA
    7975387 View commit details
  7. Copy the full SHA
    347005d View commit details
  8. fix view response (#126)

    cesargb authored Jan 4, 2025
    Copy the full SHA
    8934183 View commit details
  9. fix cookie test (#127)

    cesargb authored Jan 4, 2025
    Copy the full SHA
    0aae828 View commit details
  10. Copy the full SHA
    603a7ce View commit details
  11. config sort

    cesargb committed Jan 4, 2025
    Copy the full SHA
    b9ebf27 View commit details
  12. Create release.yml

    cesargb authored Jan 4, 2025
    Copy the full SHA
    2f7c7a0 View commit details
  13. Copy the full SHA
    d035cf4 View commit details
  14. Create release.yml

    cesargb authored Jan 4, 2025
    Copy the full SHA
    330e0a1 View commit details
  15. Add rate limit (#128)

    * add rate limit
    
    * add none to disable rate limit
    
    * add env MAGICLINK_RATE_LIMIT
    
    * add docs
    cesargb authored Jan 4, 2025
    Copy the full SHA
    566eb98 View commit details
  16. Copy the full SHA
    a270d37 View commit details

Commits on Jan 8, 2025

  1. Copy the full SHA
    cb2da0a View commit details
  2. Copy the full SHA
    0d519df View commit details
  3. rate limit by default none

    cesargb committed Jan 8, 2025
    Copy the full SHA
    4511bb5 View commit details
  4. Update release.yml

    cesargb authored Jan 8, 2025
    Copy the full SHA
    407e689 View commit details

Commits on Feb 18, 2025

  1. Copy the full SHA
    e2ad461 View commit details
  2. change action

    cesargb committed Feb 18, 2025
    Copy the full SHA
    ba99883 View commit details

Commits on Feb 21, 2025

  1. fix issue #132 (#133)

    cesargb authored Feb 21, 2025
    Copy the full SHA
    2a62d50 View commit details
  2. fix phpstan in tests

    cesargb committed Feb 21, 2025
    Copy the full SHA
    864763e View commit details
  3. Copy the full SHA
    46ee75d View commit details
13 changes: 13 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# .github/release.yml

changelog:
categories:
- title: Fixed
labels:
- bug
- title: Added
labels:
- enhancement
- title: Changed
labels:
- "*"
27 changes: 12 additions & 15 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -2,9 +2,13 @@ name: phpstan

on:
push:
branches: [master]
paths:
- '**.php'
- 'phpstan.neon.dist'
pull_request:
branches: [master]
paths:
- '**.php'
- 'phpstan.neon.dist'

jobs:
phpstan:
@@ -17,22 +21,15 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.3

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install composer dependencies
uses: ramsey/composer-install@v3

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
- name: Install larastan
run: |
composer install
composer dump
composer require "larastan/larastan" --no-interaction --no-update
composer update --prefer-dist --no-interaction
- name: Run analyse phpstan
run: vendor/bin/phpstan analyse --error-format github
6 changes: 3 additions & 3 deletions .github/workflows/style-fix.yml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: 8.3
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, exif
coverage: xdebug

@@ -24,9 +24,9 @@ jobs:
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-8.1-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-php-8.3-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php--8.1
${{ runner.os }}-php--8.3
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
14 changes: 6 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -13,23 +13,21 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.3, 8.2, 8.1, 8.0]
laravel: ['9.*', '10.*', '11.*']
php: [8.4, 8.3, 8.2, 8.1]
laravel: ['10.*', '11.*', '12.*']
dependency-version: [prefer-stable]
include:
- laravel: 9.*
testbench: 7.*
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*
- laravel: 12.*
testbench: 10.*
exclude:
- laravel: 10.*
php: 8.0
- laravel: 11.*
php: 8.1
- laravel: 11.*
php: 8.0
- laravel: 12.*
php: 8.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

53 changes: 48 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -27,6 +27,10 @@ offer secure content and even log in to the application.
- [Lifetime](#lifetime)
- [Events](#events)
- [Customization](#customization)
- [Rate limiting](#rate-limiting)
- [Testing](#testing)
- [Contributing](#contributing)
- [Security](#security)

## Installation

@@ -310,14 +314,40 @@ $urlToSend = $magiclink->url;

## Events

MagicLink fires two events:
MagicLink can fires three events:

- `MagicLink\Events\MagicLinkWasCreated`
- `MagicLink\Events\MagicLinkWasVisited`
### MagicLinkWasCreated

Event `MagicLink\Events\MagicLinkWasCreated`

This event is fired when a magic link is created.

### MagicLinkWasVisited

Event `MagicLink\Events\MagicLinkWasVisited`

This event is fired when a magic link is visited.

### MagicLinkWasDeleted

Event `MagicLink\Events\MagicLinkWasDeleted`

This event is fired when you disable mass deletion. Add this line in your
`.env` file to disable mass deletion:

```.env
# Disable mass deletion for enable event MagicLinkWasDeleted
MAGICLINK_DELETE_MASSIVE=false
```

> [!WARNING]
> If you disable mass deletion, the cleanup will be performed one by one.
> If you have many records, this can be an issue.
## Customization

### Config

To custom this package you can publish the config file:

```bash
@@ -326,8 +356,8 @@ php artisan vendor:publish --provider="MagicLink\MagicLinkServiceProvider" --tag

And edit the file `config/magiclink.php`


### Migrations

To customize the migration files of this package you need to publish the migration files:

```bash
@@ -336,7 +366,6 @@ php artisan vendor:publish --provider="MagicLink\MagicLinkServiceProvider" --tag

You'll find the published files in `database/migrations/*`


### Custom response when magiclink is invalid

When the magicLink is invalid by default the http request return a status 403.
@@ -407,6 +436,20 @@ return a `view()`
],
```

## Rate limiting

You can limit the number of requests per minute for a magic link. To do this, you need to
set the `MAGICLINK_RATE_LIMIT` environment variable to the desired value.

By default, the rate limit is disable with value 'none', but you can set a value
to limit the requests. For example, to limit the requests to 100 per minute, set

```bash
# .env

MAGICLINK_RATE_LIMIT=100
```

## Testing

Run the tests with:
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -20,12 +20,13 @@
],
"license": "MIT",
"require": {
"php": "^8.0",
"illuminate/auth": "^9.0|^10.0|^11.0",
"illuminate/container": "^9.0|^10.0|^11.0",
"illuminate/contracts": "^9.0|^10.0|^11.0",
"illuminate/database": "^9.0|^10.0|^11.0",
"laravel/serializable-closure": "^1.0"
"php": "^8.1",
"illuminate/auth": "^10.0|^11.0|^12.0",
"illuminate/container": "^10.0|^11.0|^12.0",
"illuminate/contracts": "^10.0|^11.0|^12.0",
"illuminate/database": "^10.0|^11.0|^12.0",
"laravel/serializable-closure": "^1.0|^2.0",
"orchestra/testbench": "^8.0|^9.0|^10.0"
},
"autoload": {
"psr-4": {
@@ -48,10 +49,8 @@
}
},
"require-dev": {
"orchestra/testbench": "^7.0|^8.0|^9.0",
"phpunit/phpunit": "^9.0|^10.5",
"friendsofphp/php-cs-fixer": "^3.9",
"larastan/larastan": "^2.0"
"phpunit/phpunit": "^9.0|^10.5|^11.5",
"friendsofphp/php-cs-fixer": "^3.9"
},
"minimum-stability": "dev",
"prefer-stable": true
114 changes: 78 additions & 36 deletions config/magiclink.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
<?php


return [

'token' => [
'access_code' => [
/*
|--------------------------------------------------------------------------
| Token size
| Access Code View
|--------------------------------------------------------------------------
|
| Here you may specify the length of token to verify the identify.
| Max value is 255 characters, it will be used if bigger value is set.
| Here you may specify the view to ask for access code.
|
*/
'length' => 64,
'view' => 'magiclink::ask-for-access-code-form',
],

'url' => [
/*
|--------------------------------------------------------------------------
| Path to Validate Token and Auto Auth
|--------------------------------------------------------------------------
|
| Here you may specify the name of the path you'd like to use so that
| the verify token and auth in system.
|
*/
'validate_path' => 'magiclink',
/*
|--------------------------------------------------------------------------
| Path default to redirect
|--------------------------------------------------------------------------
|
| Here you may specify the name of the path you'd like to use so that
| the redirect when verify correct token.
|
*/
'redirect_default' => '/',
],
/*
|--------------------------------------------------------------------------
| Delete Magic Link Expired massive
|--------------------------------------------------------------------------
|
| Expired MagicLinks are automatically and massively deleted from the database.
| If you want to disable this option, change the value to false.
|
| If you disable this option, expired MagicLinks will be deleted one by one
| triggering the event MagicLink\Events\MagicLinkWasDeleted.
|
*/
'delete_massive' => env('MAGICLINK_DELETE_MASSIVE', true),

/*
|--------------------------------------------------------------------------
| Disable default route
|--------------------------------------------------------------------------
|
| If you wish use your custom controller, you can invalidate the
| default route of magic link, mark this configuration as true,
| and add your custom route with the middleware:
| MagicLink\Middlewares\MagiclinkMiddleware
|
*/
'disable_default_route' => false,

/*
|--------------------------------------------------------------------------
@@ -51,20 +55,58 @@
'class' => MagicLink\Responses\Response::class,
],

'middlewares' => [
'throttle:magiclink',
MagicLink\Middlewares\MagiclinkMiddleware::class,
'web',
],

/*
|--------------------------------------------------------------------------
| Disable default route
| Rate Limit
|--------------------------------------------------------------------------
|
| If you wish use your custom controller, you can invalidate the
| default route of magic link, mark this configuration as true,
| and add your custom route with the middleware:
| MagicLink\Middlewares\MagiclinkMiddleware
| Here you may specify the number of attempts to rate limit per minutes
|
| Default: none, if you want to enable rate limit, set as integer
*/
'disable_default_route' => false,
'rate_limit' => env('MAGICLINK_RATE_LIMIT', 'none'),

'token' => [
/*
|--------------------------------------------------------------------------
| Token size
|--------------------------------------------------------------------------
|
| Here you may specify the length of token to verify the identify.
| Max value is 255 characters, it will be used if bigger value is set.
|
*/
'length' => 64,
],

'url' => [
/*
|--------------------------------------------------------------------------
| Path default to redirect
|--------------------------------------------------------------------------
|
| Here you may specify the name of the path you'd like to use so that
| the redirect when verify correct token.
|
*/
'redirect_default' => '/',

/*
|--------------------------------------------------------------------------
| Path to Validate Token and Auto Auth
|--------------------------------------------------------------------------
|
| Here you may specify the name of the path you'd like to use so that
| the verify token and auth in system.
|
*/
'validate_path' => 'magiclink',
],

'access_code' => [
'view' => 'magiclink::ask-for-access-code-form',
]
];
Loading