0
My job myFunction
picks up the elements username
and password
typed,and sends these values storing in a global variable to the next page.
My job tToken
authenticate this information and play to next page the valid Token for me to manipulate.
The problem is that I am not able to do or think of a way to play the login and password typed in the field for the next pages dynamically. Then I managed to do this but it works only on the LOGIN page, it displays the filled object only on the login page. When the login is done and authenticated, after updating the page everything disappears, exactly for being stored in variables the values I want. How to do this, other than by variables?
var globalcredential = "/v1/credentials";
var globalauth = "/v1/auth";
var userlogin = new String();
var passwordlogin = new String();
function myFunction(){
var userElement = document.getElementsByName('username');
var passwordElement = document.getElementsByName('password');
userlogin = $(userElement).val().toString();
passwordlogin = $(passwordElement).val().toString();
};
function auth(){
var account = {
grant_type: "password",
login : userlogin,
senha : passwordlogin
};
var jsonAccount = JSON.stringify(account);
console.log(jsonAccount);
$.ajax({
type: "POST"
, method : "POST"
, url : globalauth
, contentType : "application/json"
, dataType : "json"
, data: jsonAccount
,success : function(data){
console.log("oi");
},beforeSend : function(request){
request.setRequestHeader('Content-Type', 'application/json');
},
}).done(function(response, status){
console.log(response,status);
}).fail(function(error){
console.log(error);
}).always(function(response, status){
});
}
var classname = document.getElementsByClassName("buttonlogin");
Array.from(classname).forEach(function(element) {
element.addEventListener('click', myFunction);
element.addEventListener('click', auth);
});
It’s a bit confusing. You’re authenticating via Ajax and want to redirect to another page?
– Sam
As far as I can tell, you don’t want to send password via client-side because the confidentiality and security of this falls below zero. Perhaps storing in a SESSION is safer and more viable.
– Sam
I want to return the user and password, but this user and password cannot be inline in the code. It has to be dynamic.
– Breno Sobral