1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace jeremykenedy\laravel2step\App\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
|
7
|
|
|
class TwoStepAuth extends Model |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* The table associated with the model. |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
protected $table; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The connection name for the model. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $connection; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Indicates if the model should be timestamped. |
25
|
|
|
* |
26
|
|
|
* @var bool |
27
|
|
|
*/ |
28
|
|
|
public $timestamps = true; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The attributes that are not mass assignable. |
32
|
|
|
* |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
protected $guarded = [ |
36
|
|
|
'id', |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The attributes that should be mutated to dates. |
41
|
|
|
* |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
protected $dates = [ |
45
|
|
|
'created_at', |
46
|
|
|
'updated_at', |
47
|
|
|
'requestDate', |
48
|
|
|
'authDate', |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Fillable fields for a Profile. |
53
|
|
|
* |
54
|
|
|
* @var array |
55
|
|
|
*/ |
56
|
|
|
protected $fillable = [ |
57
|
|
|
'userId', |
58
|
|
|
'authCode', |
59
|
|
|
'authCount', |
60
|
|
|
'authStatus', |
61
|
|
|
'requestDate', |
62
|
|
|
'authDate', |
63
|
|
|
]; |
64
|
|
|
|
65
|
|
|
protected $casts = [ |
66
|
|
|
'userId' => 'integer', |
67
|
|
|
'authCode' => 'string', |
68
|
|
|
'authCount' => 'integer', |
69
|
|
|
'authStatus' => 'boolean', |
70
|
|
|
]; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Create a new instance to set the table and connection. |
74
|
|
|
* |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
public function __construct($attributes = []) |
78
|
|
|
{ |
79
|
|
|
parent::__construct($attributes); |
80
|
|
|
$this->table = config('laravel2step.laravel2stepDatabaseTable'); |
81
|
|
|
$this->connection = config('laravel2step.laravel2stepDatabaseConnection'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get the database connection. |
86
|
|
|
*/ |
87
|
|
|
public function getConnectionName() |
88
|
|
|
{ |
89
|
|
|
return $this->connection; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Get the database connection. |
94
|
|
|
*/ |
95
|
|
|
public function getTableName() |
96
|
|
|
{ |
97
|
|
|
return $this->table; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* An activity has a user. |
102
|
|
|
* |
103
|
|
|
* @var array |
104
|
|
|
*/ |
105
|
|
|
public function user() |
106
|
|
|
{ |
107
|
|
|
return $this->hasOne(config('laravel2step.defaultUserModel')); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get a validator for an incoming Request. |
112
|
|
|
* |
113
|
|
|
* @param array $merge (rules to optionally merge) |
114
|
|
|
* |
115
|
|
|
* @return array |
116
|
|
|
*/ |
117
|
|
|
public static function rules($merge = []) |
118
|
|
|
{ |
119
|
|
|
return array_merge( |
120
|
|
|
[ |
121
|
|
|
'userId' => 'required|integer', |
122
|
|
|
'authCode' => 'required|string|max:4|min:4', |
123
|
|
|
'authCount' => 'required|integer', |
124
|
|
|
'authStatus' => 'required|boolean', |
125
|
|
|
], |
126
|
|
|
$merge |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|