-
-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathMethod.php
More file actions
97 lines (86 loc) · 1.88 KB
/
Copy pathMethod.php
File metadata and controls
97 lines (86 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace Kirby\Auth;
use Kirby\Cms\User;
use Kirby\Panel\Ui\Component;
use Kirby\Toolkit\HasI18n;
use Kirby\Toolkit\Str;
use SensitiveParameter;
/**
* Base class for authentication methods
*
* Each method either logs the user in or returns a
* pending status that expects a follow-up challenge
*
* @copyright Bastian Allgeier
* @license https://getkirby.com/license
* @since 6.0.0
*/
abstract class Method
{
use HasI18n;
public function __construct(
protected Auth $auth,
protected array $options = []
) {
}
/**
* Attempts to authenticate the given user credentials
*
* Implementations should either return a logged-in user,
* a pending status if a challenge is required.
*/
abstract public function authenticate(
string|null $email,
#[SensitiveParameter]
string|null $password = null,
bool $long = false
): User|Status;
/**
* Returns the form component definition for this method's login step
* @codeCoverageIgnore
*/
public function form(): Component|array
{
return [];
}
/**
* Returns an icon name used to represent
* the method, e.g. on the login view
*/
public static function icon(): string
{
return 'key';
}
/**
* Checks if this method can be used in the current context
*/
public static function isEnabled(
Auth $auth,
array $options = []
): bool {
return true;
}
/**
* Returns the config options for this method
*/
public function options(): array
{
return $this->options;
}
/**
* Returns an array of buttons that will be
* used as entries in the user security settings drawer
* @codeCoverageIgnore
*/
public static function settings(User $user): array
{
return [];
}
/**
* Returns the identifier of the method (e.g. 'password')
*/
public static function type(): string
{
return Str::camelToKebab(lcfirst(basename(str_replace(['\\', 'Method'], ['/', ''], static::class))));
}
}