|
1
|
|
|
<?php namespace App\LaravelRestCms\User; |
|
2
|
|
|
|
|
3
|
|
|
use App\LaravelRestCms\BaseModel; |
|
4
|
|
|
|
|
5
|
|
|
class User extends BaseModel { |
|
6
|
|
|
|
|
7
|
|
|
public static $searchCols = ['first_name', 'last_name', 'email', 'username']; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* The database table used by the model. |
|
11
|
|
|
* |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $table = 'users'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The attributes that are mass assignable. |
|
18
|
|
|
* |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $fillable = ['first_name', 'last_name', 'email', 'username']; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The attributes excluded from the model's JSON form. |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $hidden = []; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Rules to validate when creating a model |
|
32
|
|
|
* |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
protected static $createRules = [ |
|
36
|
|
|
'first_name' => 'required', |
|
37
|
|
|
'last_name' => 'required', |
|
38
|
|
|
'email' => 'required|email|unique:users', |
|
39
|
|
|
'username' => 'required|unique:users', |
|
40
|
|
|
'password' => 'required', |
|
41
|
|
|
//'created_by' => 'integer', |
|
|
|
|
|
|
42
|
|
|
//'updated_by' => 'integer', |
|
|
|
|
|
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Valiadate a user's login |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $username |
|
49
|
|
|
* @param string $password |
|
50
|
|
|
* @return \App\LaravelRestCms\BaseModel |
|
51
|
|
|
*/ |
|
52
|
|
|
public function authenticate($username, $password) |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->where('username', $username)->where('password', $password)->get(); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Relationship to the api_key table |
|
59
|
|
|
* |
|
60
|
|
|
* @codeCoverageIgnore |
|
61
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne |
|
62
|
|
|
*/ |
|
63
|
|
|
public function apiKey() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->hasOne(\App\LaravelRestCms\ApiKey\ApiKey::class, 'user_id'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.