1717 * you can switch to those as you see fit.
1818 *
1919 * Although a demo, it's a real controller and works correctly as is.
20- * You can continue your project like this or edit it to match your app.
20+ * You can always delete this controller or link it to a route if you wish
21+ * to use it as a reference.
2122 */
2223class UsersController extends Controller
2324{
2425 // refer to base controller to find package initialization
2526 // and auth settings
2627 public function login ()
2728 {
28- // From v2, you can also use request()
29- // $password = request()->get('password');
30-
3129 // You can also mass assign particular fields from the request
3230 $ credentials = request ()->get (['username ' , 'password ' ]);
3331
@@ -43,7 +41,7 @@ public function login()
4341
4442 // This line catches any errors that MAY happen
4543 if (!$ user ) {
46- response ()->throwErr (auth ()->errors ());
44+ response ()->exit (auth ()->errors ());
4745 }
4846
4947 // We can call json on the response global shortcut method
@@ -69,7 +67,7 @@ public function register()
6967 ]);
7068
7169 // Throws an error if there's an issue in validation
72- if (!$ validation ) response ()->throwErr (Form::errors ());
70+ if (!$ validation ) response ()->exit (Form::errors ());
7371
7472 // Direct registration with Leaf Auth. Registers and initiates a
7573 // login, so you don't have to call login again, unless you want
@@ -81,7 +79,7 @@ public function register()
8179
8280 // throw an auth error if there's an issue
8381 if (!$ user ) {
84- response ()->throwErr (auth ()->errors ());
82+ response ()->exit (auth ()->errors ());
8583 }
8684
8785 response ()->json ($ user );
@@ -93,7 +91,7 @@ public function recover_account()
9391 $ user = User::where ('email ' , $ username )->first () ?? null ;
9492
9593 if (!$ user ) {
96- response ()->throwErr (['email ' => 'Email not found ' ]);
94+ response ()->exit (['email ' => 'Email not found ' ]);
9795 }
9896
9997 // Set a temporary random password and reset user password
@@ -121,14 +119,14 @@ public function reset_password()
121119 // id retrieves the JWT from the headers, decodes it and returns
122120 // the user encoded into the token. If there's a problem with the token,
123121 // we can throw whatever error occurs. This means the user must be logged in.
124- $ userId = auth ()->id () ?? response ()->throwErr (auth ()->errors ());
122+ $ userId = auth ()->id () ?? response ()->exit (auth ()->errors ());
125123 $ password = request ()->get ('password ' );
126124
127125 // Get the current id
128126 $ user = User::find ($ userId );
129127
130128 if (!$ user ) {
131- response ()->throwErr (['user ' => 'User not found! Check somewhere... ' ]);
129+ response ()->exit (['user ' => 'User not found! Check somewhere... ' ]);
132130 }
133131
134132 // Change the user password
@@ -139,7 +137,7 @@ public function reset_password()
139137 $ user = auth ()->login (['id ' => $ userId ]);
140138
141139 if (!$ user ) {
142- response ()->throwErr (auth ()->errors ());
140+ response ()->exit (auth ()->errors ());
143141 }
144142
145143 response ()->json ($ user );
@@ -151,7 +149,7 @@ public function user() {
151149 // hide from the returned user
152150 $ user = auth ()->user (['id ' , 'remember_token ' , 'password ' ]);
153151
154- response ()->json ($ user ?? response ()->throwErr (auth ()->errors ()));
152+ response ()->json ($ user ?? response ()->exit (auth ()->errors ()));
155153 }
156154
157155 public function edit ()
@@ -166,6 +164,6 @@ public function edit()
166164 'username ' , 'email '
167165 ]);
168166
169- response ()->json ($ user ?? response ()->throwErr (auth ()->errors ()));
167+ response ()->json ($ user ?? response ()->exit (auth ()->errors ()));
170168 }
171169}
0 commit comments