2626
2727use Hash ;
2828use Google2FA ;
29+ use Sofa \Eloquence \Eloquence ;
30+ use Sofa \Eloquence \Validable ;
2931use Illuminate \Auth \Authenticatable ;
3032use Illuminate \Database \Eloquent \Model ;
3133use Illuminate \Notifications \Notifiable ;
3234use Pterodactyl \Exceptions \DisplayException ;
33- use Nicolaslopezj \Searchable \SearchableTrait ;
3435use Illuminate \Auth \Passwords \CanResetPassword ;
3536use Illuminate \Foundation \Auth \Access \Authorizable ;
37+ use Sofa \Eloquence \Contracts \Validable as ValidableContract ;
3638use Illuminate \Contracts \Auth \Authenticatable as AuthenticatableContract ;
3739use Illuminate \Contracts \Auth \Access \Authorizable as AuthorizableContract ;
3840use Illuminate \Contracts \Auth \CanResetPassword as CanResetPasswordContract ;
3941use Pterodactyl \Notifications \SendPasswordReset as ResetPasswordNotification ;
4042
41- class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract
43+ class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract, ValidableContract
4244{
43- use Authenticatable, Authorizable, CanResetPassword, Notifiable, SearchableTrait ;
45+ use Authenticatable, Authorizable, CanResetPassword, Eloquence, Notifiable, Validable ;
4446
4547 /**
4648 * The rules for user passwords.
4749 *
4850 * @var string
51+ * @deprecated
4952 */
5053 const PASSWORD_RULES = 'regex:((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}) ' ;
5154
@@ -101,16 +104,53 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
101104 * @var array
102105 */
103106 protected $ searchable = [
104- 'columns ' => [
105- 'email ' => 10 ,
106- 'username ' => 9 ,
107- 'name_first ' => 6 ,
108- 'name_last ' => 6 ,
109- 'uuid ' => 1 ,
110- ],
107+ 'email ' => 10 ,
108+ 'username ' => 9 ,
109+ 'name_first ' => 6 ,
110+ 'name_last ' => 6 ,
111+ 'uuid ' => 1 ,
112+ ];
113+
114+ /**
115+ * Default values for specific fields in the database.
116+ *
117+ * @var array
118+ */
119+ protected $ attributes = [
120+ 'root_admin ' => false ,
121+ 'language ' => 'en ' ,
122+ 'use_totp ' => false ,
123+ 'totp_secret ' => null ,
124+ ];
125+
126+ /**
127+ * Rules verifying that the data passed in forms is valid and meets application logic rules.
128+ * @var array
129+ */
130+ protected static $ applicationRules = [
131+ 'email ' => 'required|email ' ,
132+ 'username ' => 'required|alpha_dash ' ,
133+ 'name_first ' => 'required|string ' ,
134+ 'name_last ' => 'required|string ' ,
135+ 'password ' => 'sometimes|regex:((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}) ' ,
111136 ];
112137
113- protected $ query ;
138+ /**
139+ * Rules verifying that the data being stored matches the expectations of the database.
140+ *
141+ * @var array
142+ */
143+ protected static $ dataIntegrityRules = [
144+ 'email ' => 'unique:users,email ' ,
145+ 'username ' => 'between:1,255|unique:users,username ' ,
146+ 'name_first ' => 'between:1,255 ' ,
147+ 'name_last ' => 'between:1,255 ' ,
148+ 'password ' => 'nullable|string ' ,
149+ 'root_admin ' => 'boolean ' ,
150+ 'language ' => 'string|between:2,5 ' ,
151+ 'use_totp ' => 'boolean ' ,
152+ 'totp_secret ' => 'nullable|string ' ,
153+ ];
114154
115155 /**
116156 * Enables or disables TOTP on an account if the token is valid.
@@ -209,7 +249,7 @@ public function serverAccessArray()
209249 * Change the access level for a given call to `access()` on the user.
210250 *
211251 * @param string $level can be all, admin, subuser, owner
212- * @return void
252+ * @return $this
213253 */
214254 public function setAccessLevel ($ level = 'all ' )
215255 {
@@ -226,7 +266,7 @@ public function setAccessLevel($level = 'all')
226266 * Note: does not account for user admin status.
227267 *
228268 * @param array $load
229- * @return \Illuiminate\Database\Eloquent\Builder
269+ * @return \Pterodactyl\Models\Server
230270 */
231271 public function access (...$ load )
232272 {
0 commit comments