|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace plunner\Http\Controllers\Companies\Auth; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use plunner\Company; |
|
7
|
|
|
use Validator; |
|
8
|
|
|
use plunner\Http\Controllers\Controller; |
|
9
|
|
|
use Tymon\JWTAuth\Support\auth\AuthenticatesAndRegistersUsers; |
|
10
|
|
|
use Tymon\JWTAuth\Support\auth\ThrottlesLogins; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class AuthController |
|
14
|
|
|
* @package plunner\Http\Controllers\Companies\Auth |
|
15
|
|
|
* @author Claudio Cardinale <[email protected]> |
|
16
|
|
|
* @copyright 2015 Claudio Cardinale |
|
17
|
|
|
* @version 1.0.0 |
|
18
|
|
|
*/ |
|
19
|
|
|
class AuthController extends Controller |
|
20
|
|
|
{ |
|
21
|
|
|
/* |
|
22
|
|
|
|-------------------------------------------------------------------------- |
|
23
|
|
|
| Registration & Login Controller |
|
24
|
|
|
|-------------------------------------------------------------------------- |
|
25
|
|
|
| |
|
26
|
|
|
| This controller handles the registration of new users, as well as the |
|
27
|
|
|
| authentication of existing users. By default, this controller uses |
|
28
|
|
|
| a simple trait to add these behaviors. Why don't you explore it? |
|
29
|
|
|
| |
|
30
|
|
|
*/ |
|
31
|
|
|
|
|
32
|
|
|
use AuthenticatesAndRegistersUsers{ |
|
33
|
|
|
postLogin as postLoginOriginal; |
|
34
|
|
|
} |
|
35
|
|
|
use ThrottlesLogins; |
|
36
|
|
|
|
|
37
|
|
|
protected $redirectPath = "/"; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* cn = company normal |
|
41
|
|
|
* @var array |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $custom = ['mode'=>'cn']; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Create a new authentication controller instance. |
|
47
|
|
|
* |
|
48
|
|
|
*/ |
|
49
|
14 |
|
public function __construct() |
|
50
|
|
|
{ |
|
51
|
14 |
|
config(['auth.model' => \plunner\Company::class]); |
|
52
|
14 |
|
config(['jwt.user' => \plunner\Company::class]); |
|
53
|
14 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get a validator for an incoming registration request. |
|
57
|
|
|
* |
|
58
|
|
|
* @param array $data |
|
59
|
|
|
* @return \Illuminate\Contracts\Validation\Validator |
|
60
|
|
|
*/ |
|
61
|
4 |
|
protected function validator(array $data) |
|
62
|
|
|
{ |
|
63
|
4 |
|
return Validator::make($data, [ |
|
64
|
4 |
|
'name' => 'required|max:255|unique:companies', |
|
65
|
4 |
|
'email' => 'required|email|max:255|unique:companies', |
|
66
|
4 |
|
'password' => 'required|confirmed|min:6', |
|
67
|
4 |
|
]); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Create a new user instance after a valid registration. |
|
72
|
|
|
* |
|
73
|
|
|
* @param array $data |
|
74
|
|
|
* @return Company |
|
75
|
|
|
*/ |
|
76
|
2 |
|
protected function create(array $data) |
|
77
|
|
|
{ |
|
78
|
2 |
|
return Company::create([ |
|
79
|
2 |
|
'name' => $data['name'], |
|
80
|
2 |
|
'email' => $data['email'], |
|
81
|
2 |
|
'password' => bcrypt($data['password']), |
|
82
|
2 |
|
]); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
10 |
|
public function postLogin(Request $request) |
|
86
|
|
|
{ |
|
87
|
|
|
//remember me |
|
88
|
10 |
|
$this->validate($request, ['remember' => 'boolean']);//TODO insert required |
|
89
|
10 |
|
if($request->input('remember', false)) |
|
|
|
|
|
|
90
|
10 |
|
{ |
|
91
|
|
|
config(['jwt.ttl' =>'43200']); //30 days |
|
92
|
|
|
$this->custom = array_merge($this->custom, ['remember'=>'true']); |
|
93
|
|
|
}else |
|
94
|
10 |
|
$this->custom = array_merge($this->custom, ['remember'=>'false']); |
|
95
|
10 |
|
return $this->postLoginOriginal($request); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: