Skip to content

Commit cce6595

Browse files
author
Mohammed Osama
committed
V2.1.3
1 parent 29022c1 commit cce6595

File tree

114 files changed

+129
-225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+129
-225
lines changed

README.md

100644100755
File mode changed.

composer.json

100644100755
File mode changed.

license

100644100755
File mode changed.

src/Activation/ActivationException.php

100644100755
File mode changed.

src/Activation/ActivationRepository.php

100644100755
Lines changed: 5 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -2,111 +2,20 @@
22

33
namespace SecTheater\Jarvis\Activation;
44

5+
use SecTheater\Jarvis\Interfaces\TokenInterface;
56
use SecTheater\Jarvis\Interfaces\RestrictionInterface;
67
use SecTheater\Jarvis\Repositories\Repository;
8+
use SecTheater\Jarvis\Traits\IssueTokens;
79

8-
class ActivationRepository extends Repository implements ActivationInterface
10+
class ActivationRepository extends Repository implements TokenInterface
911
{
12+
use IssueTokens;
1013
protected $model;
11-
14+
protected $process = 'activation';
1215
public function __construct(EloquentActivation $model)
1316
{
1417
$this->model = $model;
1518
}
1619

17-
public function tokenExists(RestrictionInterface $user, bool $create = false)
18-
{
19-
if ($create) {
20-
if (!$this->model->where('user_id', $user->id)->exists()) {
21-
return $this->generateToken($user);
22-
}
23-
}
24-
25-
return ($this->model->where('user_id', $user->id)->exists()) ? $this->model->where('user_id', $user->id)->first() : false;
26-
}
27-
28-
public function completed(RestrictionInterface $user)
29-
{
30-
if ($activation = $this->tokenExists($user)) {
31-
return $activation->completed;
32-
}
33-
34-
return false;
35-
}
36-
37-
public function complete(RestrictionInterface $user)
38-
{
39-
$activation = $this->tokenExists($user);
40-
if ($activation && $activation->token !== null) {
41-
return (bool) $activation->update([
42-
'token' => null,
43-
'user_id' => $user->id,
44-
'completed' => true,
45-
'completed_at' => date('Y-m-d H:i:s'),
46-
]);
47-
} elseif ($activation && $activation->completed === true) {
48-
return true;
49-
}
50-
51-
return false;
52-
}
53-
54-
public function clear(bool $completed = false):bool
55-
{
56-
return (bool) $this->model->where('completed', $completed)->delete();
57-
}
58-
59-
public function clearFor(RestrictionInterface $user, bool $completed = false, bool $any = false):bool
60-
{
61-
if ($any) {
62-
return (bool) $this->model->where(['user_id' => $user->id])->delete();
63-
}
64-
65-
return (bool) $this->model->where(['user_id' => $user->id, 'completed' => $completed])->delete();
66-
}
67-
68-
public function generateToken(RestrictionInterface $user)
69-
{
70-
if ($activation = $this->tokenExists($user)) {
71-
return $activation;
72-
}
73-
74-
return $this->create([
75-
'token' => str_random(32),
76-
'user_id' => $user->id,
77-
'completed' => false,
78-
'created_at' => date('Y-m-d H:i:s'),
79-
'updated_at' => null,
80-
]);
81-
}
8220

83-
public function regenerateToken(RestrictionInterface $user, bool $create = false)
84-
{
85-
if ($activation = $this->tokenExists($user)) {
86-
$activation->update([
87-
'token' => str_random(32),
88-
'completed' => false,
89-
'completed_at' => null,
90-
'updated_at' => date('Y-m-d H:i:s'),
91-
]);
92-
93-
return $activation;
94-
}
95-
if ($create) {
96-
return $this->create([
97-
'token' => str_random(32),
98-
'user_id' => $user->id,
99-
'completed' => false,
100-
'created_at' => date('Y-m-d H:i:s'),
101-
'updated_at' => null,
102-
]);
103-
}
104-
105-
return false;
106-
}
107-
108-
public function removeExpired()
109-
{
110-
return (bool) $this->model->where(['completed' => false, ['created_at', '>=', \Carbon\Carbon::now()->subDays(config('jarvis.activations.expiration'))->format('Y-m-d H:i:s')]])->delete();
111-
}
11221
}

src/Activation/EloquentActivation.php

100644100755
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class EloquentActivation extends EloquentModel
1010
protected $casts = [
1111
'completed' => 'boolean',
1212
];
13-
1413
public function user()
1514
{
1615
return $this->belongsTo($this->userModel, 'user_id', 'id');

src/Commands/AssignUserCommand.php

100644100755
File mode changed.

src/Commands/AuthCommand.php

100644100755
File mode changed.

src/Commands/ControllersCommand.php

100644100755
File mode changed.

src/Commands/CustomValidationCommand.php

100644100755
File mode changed.

0 commit comments

Comments
 (0)