doushizhou4477 2016-02-08 11:39
浏览 24

too long

i am trying to make a post request to authorize user.

This is my route.php

Route::post('/user/login', 'OwnerController@login');

Here my 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 for 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 by 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 and Password', 'error_code' => 403);
                    $response_code = 200;
                }
            } else {
                $response_array = array('success' => false, 'error' => 'Not a 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 i tried to access this url from my ios project using AFNETWORKING: Login Link Localhost

I got this 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 any specific way to make a webservice like method and print json ? Is there a problem in IOS call or in Web output?

Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c