Я изучаю Front End Development и в настоящее время работаю над проектом с пятью другими коллегами. Мне нужно реализовать страницу входа в систему. Нам также необходимо реализовать страницу регистрации и выхода. Вот как выглядит часть моего html и js-кода для страницы входа:
Login here
Username
Password
[url=#] Lost your password?[/url]
[url=#] Don't have an account?[/url]
(Javascript)
window.addEventListener("load",function (){
var username = document.getElementById("Username");
var password = document.getElementById("Password");
var submit=document.getElementById("submitButton");
var messageContainer=document.getElementById("Login");
var auth =new Auth();
submit.addEventListener("click",function ()
{
var username = document.getElementById("Username").value;
var password = document.getElementById("Password").value;
});
auth.Login();
auth.Login(username,password)
.then(function(response){
const token=response.accessToken;
auth.login(auth.Token);
auth.token=token;
document.cookie="accessToken="+token;
console.log(response.accessToken);
})
.catch(function(e) {
console.log(e) ;
loginContainer.innerHTML=e.status+ " You have to be registered in order to
login";
});
});
function Auth(){
}
Auth.prototype.Login=function(Username, Password){
var root = 'https://ancient-caverns-16784.herokuapp.com';
return $.post(root+"/auth/login",{
username: 'test',
password: 'test'
},
function(response) {
var xmlhttp = new XMLHttpRequest();
console.log(xmlhttp);
xmlhttp.open("post", "Login", true);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 401 && xmlhttp.status == 200) {
loginResults();
}
};
console.log(response);
});
};
Насколько я понял, мне нужно только добавить имя пользователя и пароль в функцию Auth. Я получаю сообщение об ошибке: auth.login не является функцией. Я что-то упускаю? Буду признателен за любую оказанную помощь.
Я изучаю Front End Development и в настоящее время работаю над проектом с пятью другими коллегами. Мне нужно реализовать страницу входа в систему. Нам также необходимо реализовать страницу регистрации и выхода. Вот как выглядит часть моего html и js-кода для страницы входа:
[code]
Login here
Username
Password
[url=#] Lost your password?[/url]
[url=#] Don't have an account?[/url]
(Javascript)
window.addEventListener("load",function (){ var username = document.getElementById("Username"); var password = document.getElementById("Password"); var submit=document.getElementById("submitButton"); var messageContainer=document.getElementById("Login"); var auth =new Auth();
submit.addEventListener("click",function ()
{
var username = document.getElementById("Username").value; var password = document.getElementById("Password").value;
}); auth.Login();
auth.Login(username,password) .then(function(response){ const token=response.accessToken; auth.login(auth.Token); auth.token=token; document.cookie="accessToken="+token; console.log(response.accessToken); }) .catch(function(e) { console.log(e) ; loginContainer.innerHTML=e.status+ " You have to be registered in order to login"; });
});
function Auth(){ } Auth.prototype.Login=function(Username, Password){ var root = 'https://ancient-caverns-16784.herokuapp.com'; return $.post(root+"/auth/login",{ username: 'test', password: 'test' }, function(response) { var xmlhttp = new XMLHttpRequest(); console.log(xmlhttp); xmlhttp.open("post", "Login", true); xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 401 && xmlhttp.status == 200) { loginResults(); } }; console.log(response); });
}; [/code]
Насколько я понял, мне нужно только добавить имя пользователя и пароль в функцию Auth. Я получаю сообщение об ошибке: auth.login не является функцией. Я что-то упускаю? Буду признателен за любую оказанную помощь.