我最近試圖創建一個登錄頁面,當用戶登錄時,會彈出一個對話框,詢問他們是否要保存其憑據。如果是,則下一次用戶進入登錄頁面時,ID &密碼已被填寫。另外,彈出窗口再也不會再出現,除非它們是新用戶。有人能告訴我如何緩存登錄數據嗎?如何緩存登錄數據AngularJS?
JS:
//Check login credentials against db
$http.post('http://178.32.64.76:8765/login', {
IDNumber: $scope.login.IDnumber,
password: $scope.login.password
})
.then(function(response) {
$scope.status = response.status;
var confirmPopup = $ionicPopup.confirm({
template: 'Do you want to save your login credentials?',
okText: 'Yes',
cancelText: 'No'
});
confirmPopup.then(function(popupResponse) {
if (popupResponse) {
//Caching code will go here
}
$state.go('tab.dash');
});
輸入:
<input name="IDnumber" type="text" placeholder="ID Number"
ng-model="login.IDnumber" ng-minlength="10" ng-maxlength="10" numbers-only required>
<input name="password" type="password" placeholder="Password"
ng-model="login.password" required>
請注意,填寫密碼字段是非常糟糕的做法,因爲任何對Web檢查工具有一點了解的人都可以看到密碼字段背後隱藏的內容。您應該改爲重寫登錄頁面。 I.E.如果登錄頁面檢測到持久憑據,則不顯示錶單,而是返回上一頁或索引 – Aaron
這是用於演示目的,不需要在一分鐘內保護。只是在向人們演示時,我不必再次輸入憑證 – TheGarrett
那麼也許您只需要您的瀏覽器來存儲這些憑據?如果沒有提示,請確保您沒有禁用瀏覽器配置中的功能,並且表單被正確識別爲登錄表單(我認爲type =「password」的輸入是條件);那麼彈出窗口將被您的瀏覽器替換,提示您輸入憑證存儲 – Aaron