【发布时间】:2020-03-13 17:30:31
【问题描述】:
我有一个简单的登录表单,它在本地运行良好,但是当我尝试在部署模式下测试身份验证功能时,它给我带来了一些问题(并且令人头疼)。
我的后端是一个带有 php 的 api,在 postman 上工作得很好。这是我的身份验证功能:
$login = $_POST['login'];
$password = $_POST['password'];
if (empty($login) && empty($password)) {
response(400, "Authentification obligatoire! Paramètres non fournis.", NULL);
}
try {
$requete = $connection->prepare("SELECT login, password FROM user WHERE login = ?");
$requete->execute([$login]);
$user = $requete->fetch();
} catch (PDOException $e) {
response(500, $e->getMessage(), NULL);
}
if (empty($user) || $password != $user['password']) {
response(401, "Le login ou le mot de passe ne correspond pas", NULL);
}
response(200, "authentifié", $login);
在我的客户端,我使用 vuejs 和 vuex 来存储状态(同样,它真的很简单)。在我的方法中,我有一个功能:
connect() {
const logForm = {
login: this.login,
password: this.password
};
console.log("log form", logForm);
_axios
.post("authentication", logForm, {
headers: {
"Content-Type": "multipart/form-data"}
})
.then(response => {
console.log("response dans auth", response);
window.localStorage.setItem("login", response.data.data);
this.$store.commit("setAuthentication", true);
this.$router.push("/career-list");
})
.catch(error => {
console.log(error);
});
}
有人可以帮助我吗?谢谢!
【问题讨论】:
-
在部署中运行代码时遇到的问题/错误消息是什么?
-
这个问题在Code Review 似乎比在这里更合适。到目前为止,您的问题与您自己的代码过于相关。
-
您好,感谢您的回答!我得到 400,第一个条件
-
嗨@Rockcat 我认为这不是代码审查的主题。 CR 就是审查已经按预期工作的代码。一旦 OP 找出导致他们的问题的原因并修复它,我们很乐意审查最终结果。