1 | <?php namespace Distilleries\Expendable\Helpers; |
||
6 | class UserUtils |
||
7 | { |
||
8 | |||
9 | |||
10 | 300 | public static function isBackendRole() |
|
11 | { |
||
12 | 300 | $user = Auth::user(); |
|
13 | |||
14 | 300 | if (empty($user)) return false; |
|
15 | |||
16 | 236 | return Auth::user()->role->initials == '@sa' || Auth::user()->role->initials == '@a'; |
|
17 | } |
||
18 | |||
19 | public static function frontendInitialRole() |
||
20 | { |
||
21 | return [ |
||
22 | '@g', //guest |
||
23 | ]; |
||
24 | } |
||
25 | |||
26 | public static function isFrontendRole() |
||
27 | { |
||
28 | $user = Auth::user(); |
||
29 | |||
30 | if (empty($user)) return false; |
||
31 | |||
32 | return in_array(Auth::user()->role->initials, self::frontendInitialRole()); |
||
33 | } |
||
34 | |||
35 | |||
36 | |||
37 | 4 | public static function get() |
|
41 | |||
42 | 76 | public static function getEmail() |
|
43 | { |
||
44 | 76 | return Auth::user()->getEmailForPasswordReset(); |
|
45 | } |
||
46 | |||
47 | 76 | public static function getDisplayName() |
|
48 | { |
||
49 | 76 | return Auth::user()->getEmailForPasswordReset(); |
|
50 | } |
||
51 | |||
52 | 12 | public static function isNotSuperAdmin() |
|
53 | { |
||
54 | 12 | return Auth::user()->role->initials != '@sa'; |
|
55 | } |
||
56 | |||
57 | |||
58 | 24 | public static function setArea($area) |
|
62 | |||
63 | 12 | public static function getArea() |
|
67 | |||
68 | 16 | public static function forgotArea() |
|
72 | |||
73 | 8 | public static function hasAccess($key) |
|
81 | |||
82 | 300 | public static function hasDisplayAllStatus() |
|
83 | { |
||
84 | 300 | return Session::get('display_all_status', false); |
|
85 | } |
||
86 | |||
87 | 108 | public static function forgotDisplayAllStatus() |
|
91 | |||
92 | 220 | public static function setDisplayAllStatus() |
|
93 | { |
||
94 | 220 | Session::put('display_all_status', true); |
|
95 | } |
||
96 | |||
97 | 16 | public static function setIsLoggedIn() |
|
|
|||
98 | { |
||
99 | 16 | if (session_id() == '') |
|
107 | |||
108 | 16 | public static function forgotIsLoggedIn() |
|
118 | |||
119 | 8 | public static function securityCheckLockEnabled() |
|
123 | } |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: