2017-07-28 147 views
1

我試圖通過驗證的用戶登錄註冊獲取細節反應原生JSON數據。 但它不工作。我是新來的本地人,所以任何人都可以說我在做什麼錯。獲取用於驗證用戶登錄

Index.js

onPressLogin() 
{ 
    this.setState({ 
     isLoading: true, 
     error: '', 
    }); 
    dismissKeyboard(); 
    fetch('http://10.0.2.2/movies/signup.php' ,{ 
     method: 'GET', 
     headers: { 
      'Accept' : 'application/json' , 
      'Content-Type': 'application/json' 
     }, 
     body : JSON.stringify({ 
      contact : this.state.contact, 
      password: this.state.password 
     }) 
    }).then((response) => 
    { 
     return response.json(); 
    }).then((response) => { 
     if(response.json){ 
     const routeStack = this.props.navigator.getCurrentRoutes(); 
     this.props.navigator.jumpTo(routeStack[3]); 
     AsyncStorage.multiSet([ 
     [ 'contact' , response.contact], 
     ]); 
     } else { 
      alert("Invalid login"); 
     } 
    }); 
} 

我使用PHP作爲後端。

Signup.php

<?php 
include 'db.php'; 
$check_json = file_get_contents('php://input'); 
echo $obj1=json_decode($check_json); 
$contact=$obj1 ->{"contact"}; 
$pass=$obj1 ->{"password"}; 
$prep = $mysqli->prepare("select contact,password from signup where 
contact=? and password=?"); 
$prep->bind_param("ss",$contact,$pass); 
$prep->execute(); 
echo $result1=$prep->get_result(); 
$count= $result1->num_rows(); 
    if($count>0){   
     echo '1'; 
    } 
    else{ 
     echo'0'; 
    } 
?> 
+1

更改方法:'GET'到'method:'POST'? – Val

+0

**從來沒有明文存儲密碼!**。只存儲密碼哈希!使用PHP的['password_hash()'](http://php.net/manual/en/function.password-hash.php)和['password_verify()'](http://php.net/manual/en /function.password-verify.php)。如果您運行的PHP版本低於5.5(我希望不是),那麼可以使用[password_compat庫](https://github.com/ircmaxell/password_compat)來獲得相同的功能。 –

回答