php - Laravel 4.2 Trying to authorize User using post method -
i trying make post request authorize user.
this route.php
route::post('/user/login', 'ownercontroller@login');
here login method:
$login_by = input::get('login_by'); $device_token = input::get('device_token'); $device_type = input::get('device_type'); if (input::has('email') && input::has('password')) { $email = input::get('email'); $password = input::get('password'); $validator = validator::make( array( 'password' => $password, 'email' => $email, 'device_token' => $device_token, 'device_type' => $device_type, 'login_by' => $login_by ), array( 'password' => 'required', 'email' => 'required|email', 'device_token' => 'required', 'device_type' => 'required|in:android,ios', 'login_by' => 'required|in:manual,facebook,google' ) ); if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'invalid input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; log::error('validation error during manual login owner = ' . print_r($error_messages, true)); } else { if ($owner = owner::where('email', '=', $email)->first()) { if (hash::check($password, $owner->password)) { if ($login_by !== "manual") { $response_array = array('success' => false, 'error' => 'login mismatch', 'error_code' => 417); $response_code = 200; } else { if ($owner->device_type != $device_type) { $owner->device_type = $device_type; } if ($owner->device_token != $device_token) { $owner->device_token = $device_token; } $owner->token = generate_token(); $owner->token_expiry = generate_expiry(); $owner->save(); /* send referral & promo info */ $settings = settings::where('key', 'referral_code_activation')->first(); $referral_code_activation = $settings->value; if ($referral_code_activation) { $referral_code_activation_txt = "referral on"; } else { $referral_code_activation_txt = "referral off"; } $settings = settings::where('key', 'promotional_code_activation')->first(); $promotional_code_activation = $settings->value; if ($promotional_code_activation) { $promotional_code_activation_txt = "promo on"; } else { $promotional_code_activation_txt = "promo off"; } /* send referral & promo info */ $code_data = ledger::where('owner_id', '=', $owner->id)->first(); $response_array = array( 'success' => true, 'id' => $owner->id, 'first_name' => $owner->first_name, 'last_name' => $owner->last_name, 'phone' => $owner->phone, 'email' => $owner->email, 'picture' => $owner->picture, 'bio' => $owner->bio, 'address' => $owner->address, 'state' => $owner->state, 'country' => $owner->country, 'zipcode' => $owner->zipcode, 'login_by' => $owner->login_by, 'social_unique_id' => $owner->social_unique_id, 'device_token' => $owner->device_token, 'device_type' => $owner->device_type, 'timezone' => $owner->timezone, 'token' => $owner->token, 'referral_code' => $code_data->referral_code, 'is_referee' => $owner->is_referee, 'promo_count' => $owner->promo_count, 'is_referral_active' => $referral_code_activation, 'is_referral_active_txt' => $referral_code_activation_txt, 'is_promo_active' => $promotional_code_activation, 'is_promo_active_txt' => $promotional_code_activation_txt, ); $dog = dog::find($owner->dog_id); if ($dog !== null) { $response_array = array_merge($response_array, array( 'dog_id' => $dog->id, 'age' => $dog->age, 'name' => $dog->name, 'breed' => $dog->breed, 'likes' => $dog->likes, 'image_url' => $dog->image_url, )); } $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'invalid username , password', 'error_code' => 403); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'not registered user', 'error_code' => 404); $response_code = 200; } } return response::make(json_encode($response_array,json_pretty_print))->header('content-type', "application/json");
but when tried access url ios project using afnetworking: login link localhost
i got error:
url: http://192.168.1.26/uberx/public/user/login } { status code: 500, headers { "cache-control" = "no-cache"; connection = close; "content-length" = 4390; "content-type" = "text/html; charset=utf-8"; date = "mon, 08 feb 2016 09:04:56 gmt"; server = "apache/2.4.17 (win32) openssl/1.0.2d php/5.6.14"; "set-cookie" = "laravel_session=eyjpdii6iis2vnvun2jwqw9umefkctbkukjtnwc9psisinzhbhvlijoivvpmew1kbkrmbla2k1hsngpbshphahnhngt2a3hab1banmdpvvq3ndvlafboznfum3qrdjr3dwlqufwvtfzia3vkt0zucldiyuxqnme1qxnlt3hjrjb3pt0ilcjtywmioiiwotjjzjlkmwvlzjg5nzq3zmy3mda1yjblyjdhn2u4mme3m2i5yzuwmdu0y2e4zmflmtkynzvkzwi2zdi0mtbmin0%3d; expires=mon, 08-feb-2016 11:04:57 gmt; max-age=7200; path=/; httponly"; "x-powered-by" = "php/5.6.14"; } }, nslocalizeddescription=request failed: unacceptable content-type: text/html}}} 2016-02-08 14:34:43.948 upper[23084:6636866] login response ---> (null)
is there specific way make webservice method , print json ? there problem in ios call or in web output?
thanks
Comments
Post a Comment