Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #381 Add hash ids instead of actual ID for model routes [WIP] #777

Merged
merged 122 commits into from
Apr 8, 2018
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
e7ed9a7
add DB_PREFIX
turtles2 Dec 26, 2017
30c44c5
Update database.php
turtles2 Dec 26, 2017
6f8aae1
Merge pull request #1 from monicahq/master
turtles2 Dec 27, 2017
19039e6
Clean Up Commit
turtles2 Dec 27, 2017
c780dd7
Merge pull request #2 from monicahq/master
turtles2 Dec 28, 2017
7081fbe
Fixes #350
turtles2 Dec 28, 2017
d04ee9a
Merge branch 'master' into master
djaiss Jan 2, 2018
08077a4
Bump version to 1.5.0 (#737)
djaiss Jan 2, 2018
32a2a04
Change link to repository in the documentation (#728)
hexnet Jan 2, 2018
8a803e7
Fix URL::forceSchema to forceScheme (#730)
mwalling Jan 2, 2018
0d842ec
Fix an issue where February shows up as March in the date picker (#731)
mwalling Jan 2, 2018
ab76894
Allow searching by phone number (or contact fields in general) (#735)
turtles2 Jan 2, 2018
1c266d4
Merge pull request #4 from monicahq/master
turtles2 Jan 2, 2018
74d3251
Merge pull request #5 from monicahq/master
turtles2 Jan 4, 2018
68cb57e
Merge pull request #6 from monicahq/master
turtles2 Jan 8, 2018
6710767
Proof of Concept
turtles2 Jan 8, 2018
efaf6db
Support for URLs that don't use HashIDs
turtles2 Jan 8, 2018
dd6c55f
Merge branch 'master' into 381
turtles2 Jan 9, 2018
b223e31
Composer Fix
turtles2 Jan 9, 2018
1a7a590
Allow setting of salt
turtles2 Jan 9, 2018
2ce2a03
Test
turtles2 Jan 9, 2018
1ea2a03
Kid Fix
turtles2 Jan 9, 2018
ea9220a
Merge branch 'master' into 381
turtles2 Jan 10, 2018
c876f0d
Fix Kid Issue
turtles2 Jan 10, 2018
f214e74
Add tests
turtles2 Jan 10, 2018
cebbb37
Style Fix
turtles2 Jan 10, 2018
9c3615f
Style Fix 2
turtles2 Jan 10, 2018
519e655
Style Fix 3
turtles2 Jan 10, 2018
fec6ac4
POC of id hashing
turtles2 Jan 10, 2018
7c5c77c
Add more tests
turtles2 Jan 10, 2018
c6bb801
Hash IDs on Dashboard
turtles2 Jan 10, 2018
eaec0c6
Hash URLs for profile
turtles2 Jan 10, 2018
ba7e58b
Merge branch 'master' into 381
turtles2 Jan 11, 2018
9d367ba
Merge branch 'master' into 381
turtles2 Jan 14, 2018
3883879
Merge branch 'master' into 381
turtles2 Jan 15, 2018
248557d
Merge branch 'master' into 381
turtles2 Jan 19, 2018
b422563
Update ModelFactory.php
turtles2 Jan 19, 2018
e75133b
Update ModelFactory.php
turtles2 Jan 19, 2018
9d7fb9c
Merge branch 'master' into 381
turtles2 Jan 21, 2018
2367249
Merge branch 'master' into 381
turtles2 Jan 22, 2018
935fc61
Update ModelFactory.php
turtles2 Jan 22, 2018
1a0f526
Update ModelFactory.php
turtles2 Jan 22, 2018
581b64e
Merge branch 'master' into 381
turtles2 Jan 23, 2018
c5d7148
Merge branch 'master' into 381
turtles2 Jan 23, 2018
5e7fa20
Merge branch 'master' into 381
turtles2 Jan 24, 2018
3e61bba
Merge branch 'master' into 381
turtles2 Jan 25, 2018
3e41094
Merge branch 'master' into 381
djaiss Jan 28, 2018
f8cbf01
Merge branch 'master' into 381
turtles2 Jan 29, 2018
5afc84c
Update .env.example
turtles2 Jan 29, 2018
ea52800
Update contribute.md
turtles2 Jan 29, 2018
60b51aa
PSR (#11)
turtles2 Jan 29, 2018
4178078
Merge branch 'master' into 381
turtles2 Feb 2, 2018
1a6a6d7
Merge branch 'master' into 381
turtles2 Feb 11, 2018
71bed8c
Merge branch 'master' into 381
turtles2 Feb 23, 2018
77d7d3c
Delete contribute.md
turtles2 Mar 12, 2018
5f0e6ff
Merge branch 'master' into 381
turtles2 Mar 12, 2018
c71f096
Update RouteServiceProvider.php
turtles2 Mar 12, 2018
0aac673
Update composer.json
turtles2 Mar 12, 2018
69edef4
Add to emails
turtles2 Mar 12, 2018
aa7464f
Add HashIDs to more pages and routes
turtles2 Mar 12, 2018
b2d68d9
Test bug Fix
turtles2 Mar 12, 2018
17da9e1
Add to update and saves
turtles2 Mar 13, 2018
7c1cc7a
Test fix
turtles2 Mar 13, 2018
f803a54
Add to edit button
turtles2 Mar 13, 2018
e94f871
Add to add
turtles2 Mar 13, 2018
3d95f4f
Add hash to search
turtles2 Mar 13, 2018
f685331
Update ContactsController.php
turtles2 Mar 13, 2018
902a108
Delete app.css
turtles2 Mar 18, 2018
163efa5
Delete mix-manifest.json
turtles2 Mar 18, 2018
29a27b3
Delete stripe.js
turtles2 Mar 18, 2018
95f8e93
Delete app.js
turtles2 Mar 18, 2018
527161e
Revert "Update ContactsController.php"
turtles2 Mar 18, 2018
3431015
Revert "Delete app.js"
turtles2 Mar 18, 2018
154acfb
Revert "Delete stripe.js"
turtles2 Mar 18, 2018
555d30a
Revert "Revert "Delete stripe.js""
turtles2 Mar 18, 2018
4013774
Revert
turtles2 Mar 18, 2018
d0f5793
Update JS
turtles2 Mar 18, 2018
6524bb7
Add files via upload
turtles2 Mar 22, 2018
f7453c0
Update stripe.js
turtles2 Mar 22, 2018
b6262d4
Add files via upload
turtles2 Mar 22, 2018
cedb357
Add files via upload
turtles2 Mar 22, 2018
e893407
Merge branch 'master' into 381
turtles2 Mar 22, 2018
4fe72b2
Complie Assets
turtles2 Mar 23, 2018
f510302
Merge branch 'master' into 381
turtles2 Mar 25, 2018
25ffb7a
Changes
turtles2 Mar 25, 2018
ff4ef6c
Merge branch 'master' into 381
asbiin Mar 25, 2018
74fa565
Add bcmath dependency
asbiin Mar 25, 2018
4a6fd91
Merge remote-tracking branch 'origin/master' into 381
asbiin Mar 29, 2018
7ed87de
Add to more views
turtles2 Apr 1, 2018
58f8060
Add more
turtles2 Apr 1, 2018
f6c7613
More hashs
turtles2 Apr 1, 2018
45176d8
Remove id from modal
turtles2 Apr 1, 2018
a84d0ce
Add a default prefix configuration
asbiin Apr 1, 2018
692e42b
Use default_prefix
asbiin Apr 1, 2018
1f4ac37
Add a ServiceProvider
asbiin Apr 1, 2018
563368d
Fix
turtles2 Apr 1, 2018
9574f3a
Merge branch '381' of https://github.com/turtles2/monica into 381
turtles2 Apr 1, 2018
84d1fbd
Fix StyleCI
asbiin Apr 1, 2018
4b5f5cd
Merge branch '381' of https://github.com/turtles2/monica into 381
turtles2 Apr 1, 2018
5b05f70
Fix 2
turtles2 Apr 1, 2018
0df3854
Bug fix and more hashs
turtles2 Apr 1, 2018
b6832d3
Remove unneeded id tag
turtles2 Apr 1, 2018
7856cbe
Add files via upload
turtles2 Apr 1, 2018
28aa481
Merge branch 'master' into 381
turtles2 Apr 1, 2018
32dd34d
Assets
turtles2 Apr 1, 2018
b8a66a0
Update composer.json
turtles2 Apr 1, 2018
f6636f0
Prep for merge
turtles2 Apr 2, 2018
d59e272
Delete KidsController.php
turtles2 Apr 2, 2018
1b297e5
Add files via upload
turtles2 Apr 2, 2018
07c0563
Merge branch 'master' into 381
turtles2 Apr 2, 2018
df44ede
Update RelationshipsController.php
turtles2 Apr 2, 2018
99deded
Update RelationshipsController.php
turtles2 Apr 2, 2018
8e16ff8
Update RelationshipsController.php
turtles2 Apr 2, 2018
0beea0f
Add HashID back
turtles2 Apr 2, 2018
f806bbf
Assets
turtles2 Apr 2, 2018
a01af38
Merge branch 'master' into 381
turtles2 Apr 2, 2018
a4eb62d
Fixes
turtles2 Apr 2, 2018
6f037eb
Merge branch '381' of https://github.com/turtles2/monica into 381
turtles2 Apr 2, 2018
a5c65c7
Merge remote-tracking branch 'origin/master' into 381
asbiin Apr 4, 2018
f311fe3
Update IdHasher.php
turtles2 Apr 5, 2018
975dd79
Merge remote-tracking branch 'origin/master' into 381
asbiin Apr 7, 2018
8aadf00
Merge branch 'master' into 381
turtles2 Apr 7, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App;

use App\Traits\Hasher;
use App\Traits\Searchable;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -19,6 +20,8 @@ class Contact extends Model
{
use Searchable;

use Hasher;

protected $dates = [
'last_talked_to',
'last_consulted_at',
Expand Down
20 changes: 20 additions & 0 deletions app/Helpers/ID_hasher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Helpers;

use Vinkla\Hashids\Facades\Hashids;

class ID_hasher
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Rename class "ID_hasher" to match the regular expression ^[A-Z][a-zA-Z0-9]*$. rule

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name ID_hasher is not PSR1 compliant.

Please change it everywhere with idHasher.

{

public function encode_id($id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encode_idencodeId for PSR1 compliance.

{
return Hashids::encode($id);
}

public function decode_id($hash)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decode_iddecodeId

{
return Hashids::decode($hash);
}

}
6 changes: 5 additions & 1 deletion app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Offspring;
use App\ContactField;
use App\Relationship;
use App\Helpers\ID_hasher;
use Illuminate\Routing\Router;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
Expand All @@ -39,8 +40,11 @@ public function boot()
{
parent::boot();

Route::bind('contact', function ($value) {
$ID_hasher = new ID_hasher();

Route::bind('contact', function ($value) use ($ID_hasher){
try {
$value = $ID_hasher->decode_id($value);
return Contact::where('account_id', auth()->user()->account_id)
->where('id', $value)
->firstOrFail();
Expand Down
16 changes: 16 additions & 0 deletions app/Traits/Hasher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Traits;

use App\Helpers\ID_hasher;

trait Hasher
{

public function getRouteKey()
{
$ID_hasher = new ID_hasher();

return $ID_hasher->encode_id(parent::getRouteKey());
}
}
25 changes: 13 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@
"type": "project",
"require": {
"php": ">=7.0.0",
"laravel/framework": "5.5.*",
"barryvdh/laravel-debugbar": "^2.2",
"jenssegers/date": "^3.2",
"ext-intl": "*",
"predis/predis": "^1.1",
"guzzlehttp/guzzle": "^6.2",
"fzaninotto/faker": "^1.6",
"barryvdh/laravel-debugbar": "^2.2",
"doctrine/dbal": "^2.5",
"laravel/socialite": "^3.0",
"intervention/image": "^2.3",
"sabre/vobject": "^4.1",
"erusev/parsedown": "~1.6",
"fzaninotto/faker": "^1.6",
"guzzlehttp/guzzle": "^6.2",
"intervention/image": "^2.3",
"jenssegers/date": "^3.2",
"laravel/cashier": "~7.0",
"roave/security-advisories": "dev-master",
"laravel/dusk": "^1.1",
"sentry/sentry-laravel": "^0.7.0",
"laravel/framework": "5.5.*",
"laravel/passport": "^4.0",
"laravel/socialite": "^3.0",
"league/flysystem-aws-s3-v3": "~1.0",
"laravel/passport": "^4.0"
"predis/predis": "^1.1",
"roave/security-advisories": "dev-master",
"sabre/vobject": "^4.1",
"sentry/sentry-laravel": "^0.7.0",
"vinkla/hashids": "^3.3"
},
"require-dev": {
"mockery/mockery": "0.9.*",
Expand Down
201 changes: 200 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions config/hashids.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/*
* This file is part of Laravel Hashids.
*
* (c) Vincent Klaiber <hello@vinkla.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

return [

/*
|--------------------------------------------------------------------------
| Default Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the connections below you wish to use as
| your default connection for all work. Of course, you may use many
| connections at once using the manager class.
|
*/

'default' => 'main',

/*
|--------------------------------------------------------------------------
| Hashids Connections
|--------------------------------------------------------------------------
|
| Here are each of the connections setup for your application. Example
| configuration has been included, but you may add as many connections as
| you would like.
|
*/

'connections' => [

'main' => [
'salt' => 'your-salt-string',
'length' => '18',
],

'alternative' => [
'salt' => 'your-salt-string',
'length' => 'your-length-integer',
],

],

];