serverfireteam /
panel
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | namespace Serverfireteam\Panel; |
||
| 3 | |||
| 4 | use Illuminate\Auth\Authenticatable; |
||
| 5 | use Illuminate\Database\Eloquent\Model; |
||
| 6 | use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
||
| 7 | use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; |
||
| 8 | use Illuminate\Support\Facades\Input; |
||
| 9 | use Illuminate\Notifications\Notifiable; |
||
| 10 | |||
| 11 | class Admin extends Model implements AuthenticatableContract, CanResetPasswordContract { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 12 | |||
| 13 | use Authenticatable, AdminCanResetPassword; |
||
| 14 | use HasRoles; |
||
| 15 | use Notifiable; |
||
| 16 | /** |
||
| 17 | * The database table used by the model. |
||
| 18 | * |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | protected $table = 'admins'; |
||
| 22 | protected $remember_token_name = 'remember_token'; |
||
| 23 | |||
| 24 | |||
| 25 | public function getAuthIdentifier() |
||
| 26 | { |
||
| 27 | return $this->getKey(); |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Get the password for the user. |
||
| 32 | * |
||
| 33 | * @return string |
||
| 34 | */ |
||
| 35 | public function getAuthPassword() |
||
| 36 | { |
||
| 37 | return $this->password; |
||
| 38 | } |
||
| 39 | |||
| 40 | public function getRememberToken(){ |
||
| 41 | return $this->remember_token; |
||
| 42 | } |
||
| 43 | |||
| 44 | public function setRememberToken($value){ |
||
| 45 | $this->remember_token = $value; |
||
| 46 | } |
||
| 47 | |||
| 48 | public function getReminderEmail(){ |
||
| 49 | $email = Input::only('email'); |
||
| 50 | return $email['email']; |
||
| 51 | } |
||
| 52 | |||
| 53 | |||
| 54 | public function getRememberTokenName(){ |
||
| 55 | return $this->remember_token_name; |
||
| 56 | } |
||
| 57 | |||
| 58 | |||
| 59 | /** |
||
| 60 | * To get all Admins that has $key and $value on extradata field |
||
| 61 | * @param $key |
||
| 62 | * @param $value |
||
| 63 | * @return mixed |
||
| 64 | */ |
||
| 65 | public function getAllExtraData($key, $value){ |
||
| 66 | //defined by local scope |
||
| 67 | return Admin::getExtraData($key, $value)->get(); |
||
| 68 | //return Admin::where('extradata->' + $key, $value)->get(); |
||
| 69 | //JSON_CONTAINS() function accepts the JSON field being searched and another to compare against. |
||
| 70 | // It returns 1 when a match is found, e.g. |
||
| 71 | //return Admin::whereRaw('JSON_CONTAINS(extradata->"$.' + $key + '", \'["' + $value + '"]\')')->get(); |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Get all the Admins who has $query in $key on extradata field |
||
| 76 | * @param $key |
||
| 77 | * @param $query |
||
| 78 | * @return mixed |
||
| 79 | */ |
||
| 80 | public function getSearchInExtraData($key, $query){ |
||
| 81 | //defined by local scope |
||
| 82 | return Admin::searchInExtraData($key, $query)->get(); |
||
| 83 | //return Admin::where('extradata->' + $key, 'like', '%'+ $query + '%')->get(); |
||
| 84 | //JSON_SEARCH() function returns the path to the given match or NULL when there’s no match. |
||
| 85 | // It is passed the JSON document being searched, 'one' to find the first match or 'all' to find all matches, and a search string, e.g. |
||
| 86 | //return Admin::whereRaw('JSON_SEARCH(extradata->"$.' + $key + '", "one", "%'+ $query + '%") IS NOT NULL')->get(); |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * add or update admin's picture. |
||
| 91 | * @param $path_or_pic_base64_encoded |
||
| 92 | */ |
||
| 93 | public function updateAdminPicture($path_or_pic_base64_encoded){ |
||
| 94 | //use forceFill() which will bypass the mass assignment check to perform update on any JSON path, |
||
| 95 | // if path is not there, it will be created and if it’s present it will be updated accordingly. |
||
| 96 | $this->forceFill(['extradata->picture' => $path_or_pic_base64_encoded]); |
||
| 97 | |||
| 98 | # Save the changes |
||
| 99 | $this->update(); |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * get admin picture from extradata column |
||
| 104 | * @return mixed |
||
| 105 | */ |
||
| 106 | public function getAdminPicture(){ |
||
| 107 | $extdata = $this->getExtraDataObj(); |
||
| 108 | if (is_null($extdata)) return null; |
||
| 109 | return $extdata->picture; |
||
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * find admin by primary key id |
||
| 114 | * @param $admin_id |
||
| 115 | * @return mixed |
||
| 116 | */ |
||
| 117 | public function findById($admin_id){ |
||
| 118 | // Retrieve a model by its primary key... |
||
| 119 | $admin = Admin::find($admin_id); |
||
| 120 | // Retrieve the first model matching the query constraints... |
||
| 121 | //$admin = Admin::where('id', $admin_id)->first(); |
||
| 122 | return $admin; |
||
| 123 | } |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Scope a query to get admin by id. |
||
| 127 | * @param $query |
||
| 128 | * @param $admin_id |
||
| 129 | * @return mixed |
||
| 130 | */ |
||
| 131 | public function scopeFindById($query, $admin_id){ |
||
| 132 | return $query->where('id', $admin_id); |
||
| 133 | } |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Scope a query to get admin by a $key and $value in extradata. |
||
| 137 | * @param $query |
||
| 138 | * @param $key |
||
| 139 | * @param $value |
||
| 140 | * @return mixed |
||
| 141 | */ |
||
| 142 | public function scopeGetExtraData($query, $key, $value){ |
||
| 143 | //JSON_CONTAINS() function accepts the JSON field being searched and another to compare against. |
||
| 144 | // It returns 1 when a match is found, e.g. |
||
| 145 | return $query->whereRaw('JSON_CONTAINS(extradata->"$.' + $key + '", \'["' + $value + '"]\')'); |
||
| 146 | //return $query->where('extradata->' + $key, $value); |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * get extradata as json object |
||
| 151 | * @return mixed |
||
| 152 | */ |
||
| 153 | public function getExtraDataObj(){ |
||
| 154 | return json_decode($this->extradata); |
||
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Scope a query to get admin by a $key and search in $value. |
||
| 159 | * @param $query |
||
| 160 | * @param $key |
||
| 161 | * @param $query_value |
||
| 162 | * @return mixed |
||
| 163 | */ |
||
| 164 | public function scopeSearchInExtraData($query, $key, $query_value){ |
||
| 165 | //JSON_SEARCH() function returns the path to the given match or NULL when there’s no match. |
||
| 166 | // It is passed the JSON document being searched, 'one' to find the first match or 'all' to find all matches, and a search string, e.g. |
||
| 167 | return $query->whereRaw('JSON_SEARCH(extradata->"$.' + $key + '", "one", "%'+ $query_value + '%") IS NOT NULL'); |
||
| 168 | //return $query->where('extradata->' + $key, 'like', '%'+ $query_value + '%'); |
||
| 169 | } |
||
| 170 | |||
| 171 | |||
| 172 | protected $fillable = array('first_name', 'last_name', 'email', 'password', 'extradata'); |
||
| 173 | /** |
||
| 174 | * The attributes excluded from the model's JSON form. |
||
| 175 | * |
||
| 176 | * @var array |
||
| 177 | */ |
||
| 178 | protected $hidden = array('password', 'remember_token'); |
||
| 179 | |||
| 180 | |||
| 181 | |||
| 182 | |||
| 183 | } |