As i am new to fusetools i found it usefull, but when i started to make a simple login page for my app, I dont know what i am doing wrong your help will be appreciated. below is javascript code which i get from your forum
var Observable = require("FuseJS/Observable");
var errmsg = Observable("");
var username = Observable("");
var password = Observable("");
var uri = "http://www.myurl.com/login.php"
var sendRequest = function() {
var options = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa(username.value + ':' + password.value)
},
body: JSON.stringify({
username: username.value,
password: password.value,
})
};
fetch(uri, options).then(function(response) {
var data = JSON.stringify(response)
debug_log(data);
}, function(error) {
debug_log(error);
errmsg = "Error Occured";
});
};
module.exports = {
username: username,
password: password,
send: sendRequest,
};
module.exports = {
items: items
username: username
password: password
loggingin : sendRequest
failedlogin: errmsg
};
and this are the textinputs of my .ux file
<TextInput Row="0" Column="1" PlaceholderText="Username" Value="{username}" PlaceholderColor="#999" TextColor="#fff" />
<TextInput Row="1" Column="1" PlaceholderText="Password" Value="{password}" PlaceholderColor="#999" TextColor="#fff" />
and this will generate click event after user enter valid login credentials
<Text ux:Name="text" Alignment="Center" Value="Sign in" FontSize="18" TextColor="#fff"/>
and following below is the php files which returns json format data
<?php
require_once 'include/DB_Functions.php';
$db = new DB_Functions();
// json response array
$response = array("error" => FALSE);
if (isset($_POST['username']) && isset($_POST['password'])) {
// receiving the post params
$username = $_POST['username'];
$password = $_POST['password'];
// get the user by email and password
$user = $db->getUserByUsernameAndPassword($username, $password);
if ($user != false) {echo json_encode($response);
} else {
// user is not found with the credentials
$response["error"] = TRUE;
$response["error_msg"] = "Login credentials are wrong. Please try again!";
echo json_encode($response);
}
} else {
// required post params is missing
$response["error"] = TRUE;
$response["error_msg"] = "Required parameters email or password is missing!";
echo json_encode($response);
}
?>
and Php Login Function ``` class DB_Functions {
private $conn;
// constructor
function __construct() {
require_once 'DB_Connect.php';
// connecting to database
$db = new Db_Connect();
$this->conn = $db->connect();
}
public function getUserByUsernameAndPassword($username, $password) {
$stmt = $this->conn->prepare("SELECT * FROM Users WHERE Username = ?");
$stmt->bind_param("s", $username);
if ($stmt->execute()) {
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
// verifying user password
//$salt = $user['salt'];
$encrypted_password = md5($password);
$encrypted_password1 = $user['Password'];
//$hash = $this->checkhashSSHA($salt, $password);
// check for password equality
if ($encrypted_password1 == $encrypted_password) {
// user authentication details are correct
return $user;
}
} else {
return NULL;
}
}
}
?> As Obvoius database connection and url is working fine but i am having problem in fuse only as the php side script is clear which returns data in normal nonfuse application login is working fine but i want to learn fuse and how its handling fetch
function i have gone through all the forums regarding mysql.