Skip to content

Commit 38c3596

Browse files
committed
Added Facades
1 parent 25aef70 commit 38c3596

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

src/AuthyFacadeAccessor.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace Srmklive\Authy;
4+
5+
use Srmklive\Authy\Contracts\Auth\TwoFactor\Authenticatable as TwoFactorAuthenticatable;
6+
7+
class AuthyFacadeAccessor
8+
{
9+
protected $authy;
10+
11+
public function __construct()
12+
{
13+
$this->authy = new Authy();
14+
}
15+
16+
/**
17+
* Determine if the given user has two-factor authentication enabled.
18+
*
19+
* @param \Srmklive\Authy\Contracts\Auth\TwoFactor\Authenticatable $user
20+
* @return bool
21+
*/
22+
public static function isEnabled(TwoFactorAuthenticatable $user)
23+
{
24+
return isset(self::$authy->getTwoFactorAuthProviderOptions()['id']);
25+
}
26+
27+
/**
28+
* Register the given user with the provider.
29+
*
30+
* @param \Srmklive\Authy\Contracts\Auth\TwoFactor\Authenticatable $user
31+
* @return void
32+
*/
33+
public static function register(TwoFactorAuthenticatable $user)
34+
{
35+
return self::$authy->register($user);
36+
}
37+
38+
/**
39+
* Send the given user authentication token
40+
*
41+
* @param \Srmklive\Authy\Contracts\Auth\TwoFactor\Authenticatable $user
42+
* @return bool
43+
*/
44+
public function sendSms(TwoFactorAuthenticatable $user)
45+
{
46+
return self::$authy->sendSms($user);
47+
}
48+
49+
/**
50+
* Determine if the given token is valid for the given user.
51+
*
52+
* @param \Srmklive\Authy\Contracts\Auth\TwoFactor\Authenticatable $user
53+
* @param string $token
54+
* @return bool
55+
*/
56+
public function tokenIsValid(TwoFactorAuthenticatable $user, $token)
57+
{
58+
return self::$authy->tokenIsValid($user, $token);
59+
}
60+
61+
/**
62+
* Delete the given user from the provider.
63+
*
64+
* @param \Srmklive\Authy\Contracts\Auth\TwoFactor\Authenticatable $user
65+
* @return bool
66+
*/
67+
public function delete(TwoFactorAuthenticatable $user)
68+
{
69+
return self::$authy->delete($user);
70+
}
71+
}

src/Facades/Authy.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Srmklive\Authy\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
class Authy extends Facade
8+
{
9+
/**
10+
* Get the registered name of the component.
11+
*
12+
* @return string
13+
*/
14+
protected static function getFacadeAccessor()
15+
{
16+
return 'Srmklive\Authy\AuthyFacadeAccessor';
17+
}
18+
}

0 commit comments

Comments
 (0)