1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace plunner\Http\Controllers\Companies\Auth; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use plunner\Company; |
7
|
|
|
use plunner\Http\Controllers\Controller; |
8
|
|
|
use Tymon\JWTAuth\Support\auth\AuthenticatesAndRegistersUsers; |
9
|
|
|
use Tymon\JWTAuth\Support\auth\ThrottlesLogins; |
10
|
|
|
use Validator; |
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
|
21 |
|
public function __construct() |
50
|
|
|
{ |
51
|
21 |
|
config(['auth.model' => \plunner\Company::class]); |
52
|
21 |
|
config(['jwt.user' => \plunner\Company::class]); |
53
|
21 |
|
} |
54
|
|
|
|
55
|
15 |
|
public function postLogin(Request $request) |
56
|
|
|
{ |
57
|
|
|
//remember me |
58
|
15 |
|
$this->validate($request, ['remember' => 'required|boolean']); |
59
|
15 |
|
$this->validate($request, ['token' => 'sometimes|required|max:255']); |
60
|
15 |
|
if ($request->input('remember', false)) { |
|
|
|
|
61
|
|
|
config(['jwt.ttl' => '43200']); //30 days |
62
|
|
|
$this->custom = array_merge($this->custom, ['remember' => 'true']); |
63
|
|
|
} else |
64
|
15 |
|
$this->custom = array_merge($this->custom, ['remember' => 'false']); |
65
|
15 |
|
$ret = $this->postLoginOriginal($request); |
66
|
15 |
|
if($ret->getStatusCode() == 200) |
67
|
10 |
|
;//TODO store the token |
68
|
15 |
|
return $ret; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get a validator for an incoming registration request. |
73
|
|
|
* |
74
|
|
|
* @param array $data |
75
|
|
|
* @return \Illuminate\Contracts\Validation\Validator |
76
|
|
|
*/ |
77
|
6 |
|
protected function validator(array $data) |
78
|
|
|
{ |
79
|
6 |
|
return Validator::make($data, [ |
80
|
6 |
|
'name' => 'required|min:1|max:255|unique:companies', |
81
|
4 |
|
'email' => 'required|email|max:255|unique:companies', |
82
|
4 |
|
'password' => 'required|confirmed|min:6', |
83
|
4 |
|
'token' => 'sometimes|filled|max:255', |
84
|
4 |
|
]); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Create a new user instance after a valid registration. |
89
|
|
|
* |
90
|
|
|
* @param array $data |
91
|
|
|
* @return Company |
92
|
|
|
*/ |
93
|
3 |
|
protected function create(array $data) |
94
|
|
|
{ |
95
|
3 |
|
return Company::create([ |
96
|
3 |
|
'name' => $data['name'], |
97
|
3 |
|
'email' => $data['email'], |
98
|
3 |
|
'password' => bcrypt($data['password']), |
99
|
2 |
|
]); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
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: