Hello I have a laravel API to call for login. But seems the angular js won't pass the data from input. I'm just new to Angular.
Here's my Login controller:
public function login(Request $request) { $email = $request->input('email'); $password = $request->input('password'); $user = User::where('email', '=', $email)->first(); if (!$user) { //return an error if user is not found in the database return response()->json(['error' => 'employee_not_authorized'], 401); } else { try{ // verify the credentials and create a token for the user if (!$token = JWTAuth::fromUser($user)) { return response()->json(['error' => 'invalid_credentials'], 401); } } catch (JWTException $e) { return response()->json(['error' => 'could_not_create_token'], 500); } // if no errors are encountered we can return a JWT return response()->json(compact('token')); } }
And here's my angularjs controller for login that consumes laravel api but it is not working, it kept me giving error authorize 401 though testing in postman, laravel api works.
Signin: function (username, password) { //return $http.get("http://localhost:8080/bcpp/webservice/api.php?action=login&employee_id=" + username + "&pass=" + password) //.then(function (response) { // return (response.data); //});
return $http({ url: "../login", method: 'POST', data: { email: username, password: password }, headers: { 'Content-Type' : 'application/x-www-form-urlencoded'} }); },
Disclaimer: some code intended not to be completed.Please help. Thank you.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bGsgEU
via IFTTT
Aucun commentaire:
Enregistrer un commentaire