当我尝试登录离子应用程序时,我获得了无效的登录... API是使用Slim框架构建的。不知道错误来自哪里,我也尝试使用邮递员,但仍然收到相同的错误。
下面是我的API登录功能
function login() {
$request = \Slim\Slim::getInstance()->request();
$data = json_decode($request->getBody());
try {
$db = getDB();
$userData ='';
$sql = "SELECT user_id,email, username FROM users WHERE (username=:username or email=:username) and password=:password ";
$stmt = $db->prepare($sql);
$stmt->bindParam("username", $data->username, PDO::PARAM_STR);
$password=hash('sha256',$data->password);
$stmt->bindParam("password", $password, PDO::PARAM_STR);
$stmt->execute();
$mainCount=$stmt->rowCount();
$userData = $stmt->fetch(PDO::FETCH_OBJ);
if(!empty($userData))
{
$user_id=$userData->user_id;
$userData->token = apiToken($user_id);
}
$db = null;
if($userData){
$userData = json_encode($userData);
echo '{"userData": ' .$userData . '}';
} else {
echo '{"error":{"text":"Invalid username or password"}}';
}
}
catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}