我正在尝试使用异步等待并使用 fetch api 获取数据
我的问题是,我只是不太明白我是如何真正从服务器得到答案的,而不是承诺的状态。我在控制台中得到以下信息
Promise {<pending>}
-------------------------------
{locale: "en"}
Run Code Online (Sandbox Code Playgroud)
但我更希望服务器响应应该是“locale: en”。
我的代码:
const locale = getLocale();
console.log(locale) // here I want to have "locale: en" as a output
async function fetchLocale() {
return await fetch('/get-language', {
headers: {
'Accept': 'application/json'
},
method: 'GET',
}).then(response => {
if (response.ok) {
return response.json()
}
return Promise.reject(Error('error'))
}).catch(error => {
return Promise.reject(Error(error.message))
})
}
async function getLocale() {
return await fetchLocale();
}
Run Code Online (Sandbox Code Playgroud)
我想要存档的目标是,返回此“locale: en”响应并将其存储在我的代码示例开头的“locale”const 中。
韩国
我正在寻找一种加密数据库中用户电子邮件的方法。由于加密总是生成其他字符串,因此失败。所以我拿了sha1。
在AuthenticatesUsers中,我已将凭据方法更改为:
protected function credentials(Request $request)
{
return ['email' => sha1(strtolower($request->email)), 'password' => ($request->password)];
}
Run Code Online (Sandbox Code Playgroud)
这对于登录/注册非常有用。但是重置密码存在问题。
重置密码使用SendsPasswordResetEmails特性。
那里有这个凭证方法:
protected function credentials(Request $request)
{
return $request->only('email');
}
Run Code Online (Sandbox Code Playgroud)
这总是失败,因为它找不到用户(因为用户是用sha1电子邮件保存的)
如果我将其更改为 return ['email' => sha1(strtolower($request['email']))];
我收到错误消息,表明电子邮件不在正确的RFC标准中,无法发送电子邮件。问题是,我找不到真正的地方,laravel是使用此电子邮件为用户搜索的地方。无论如何,我根本不知道如何解决这个问题。
我想对电子邮件本身进行加密,因为在德国,有一项法律强迫我们存储加密的个人数据,例如电子邮件。