Auth async
This commit is contained in:
@@ -303,7 +303,7 @@ angular.module('app')
|
||||
})
|
||||
}
|
||||
} else {
|
||||
authManager.login(server, email, pw, false, false, {}, function(response){
|
||||
authManager.login(server, email, pw, false, false, {}).then((response) => {
|
||||
window.location.reload();
|
||||
})
|
||||
}
|
||||
|
||||
@@ -59,8 +59,7 @@ class AccountMenu {
|
||||
$scope.formData.status = "Generating Login Keys...";
|
||||
$timeout(function(){
|
||||
authManager.login($scope.formData.url, $scope.formData.email, $scope.formData.user_password,
|
||||
$scope.formData.ephemeral, $scope.formData.strictSignin, extraParams,
|
||||
(response) => {
|
||||
$scope.formData.ephemeral, $scope.formData.strictSignin, extraParams).then((response) => {
|
||||
if(!response || response.error) {
|
||||
|
||||
syncManager.unlockSyncing();
|
||||
@@ -108,7 +107,7 @@ class AccountMenu {
|
||||
$scope.formData.status = "Generating Account Keys...";
|
||||
|
||||
$timeout(function(){
|
||||
authManager.register($scope.formData.url, $scope.formData.email, $scope.formData.user_password, $scope.formData.ephemeral ,function(response){
|
||||
authManager.register($scope.formData.url, $scope.formData.email, $scope.formData.user_password, $scope.formData.ephemeral).then((response) => {
|
||||
if(!response || response.error) {
|
||||
$scope.formData.status = null;
|
||||
var error = response ? response.error : {message: "An unknown error occured."}
|
||||
|
||||
@@ -209,7 +209,7 @@ class PasswordWizard {
|
||||
|
||||
// perform a sync beforehand to pull in any last minutes changes before we change the encryption key (and thus cant decrypt new changes)
|
||||
syncManager.sync((response) => {
|
||||
authManager.changePassword(authManager.user.email, currentServerPw, newKeys, newAuthParams, (response) => {
|
||||
authManager.changePassword(authManager.user.email, currentServerPw, newKeys, newAuthParams).then((response) => {
|
||||
if(response.error) {
|
||||
alert(response.error.message ? response.error.message : "There was an error changing your password. Please try again.");
|
||||
$timeout(() => callback(false));
|
||||
|
||||
@@ -56,17 +56,6 @@ class AuthManager extends SFAuthManager {
|
||||
return this._authParams;
|
||||
}
|
||||
|
||||
keys() {
|
||||
if(!this._keys) {
|
||||
var mk = this.storageManager.getItemSync("mk");
|
||||
if(!mk) {
|
||||
return null;
|
||||
}
|
||||
this._keys = {mk: mk, ak: this.storageManager.getItemSync("ak")};
|
||||
}
|
||||
return this._keys;
|
||||
}
|
||||
|
||||
async protocolVersion() {
|
||||
var authParams = this.getAuthParams();
|
||||
if(authParams && authParams.version) {
|
||||
@@ -82,26 +71,51 @@ class AuthManager extends SFAuthManager {
|
||||
}
|
||||
}
|
||||
|
||||
getAuthParamsForEmail(url, email, extraParams, callback) {
|
||||
super.getAuthParamsForEmail(url, email, extraParams, (response) => {
|
||||
callback(response);
|
||||
})
|
||||
async resolveResponseInTimeout(response) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.$timeout(() => {
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
login(url, email, password, ephemeral, strictSignin, extraParams, callback) {
|
||||
super.login(url, email, password, ephemeral, strictSignin, extraParams, (response) => {
|
||||
async getAuthParamsForEmail(url, email, extraParams) {
|
||||
return super.getAuthParamsForEmail(url, email, extraParams);
|
||||
}
|
||||
|
||||
async login(url, email, password, ephemeral, strictSignin, extraParams) {
|
||||
return super.login(url, email, password, strictSignin, extraParams).then((response) => {
|
||||
if(!response.error) {
|
||||
this.setEphemeral(ephemeral);
|
||||
this.handleAuthResponse(response, email, url, authParams, keys);
|
||||
this.checkForSecurityUpdate();
|
||||
}
|
||||
this.$timeout(() => callback(response));
|
||||
|
||||
return this.resolveResponseInTimeout(response);
|
||||
})
|
||||
}
|
||||
|
||||
handleAuthResponse(response, email, url, authParams, keys) {
|
||||
async register(url, email, password, ephemeral) {
|
||||
super.register(url, email, password).then((response) => {
|
||||
if(!response.error) {
|
||||
this.setEphemeral(ephemeral);
|
||||
}
|
||||
return this.resolveResponseInTimeout(response);
|
||||
})
|
||||
}
|
||||
|
||||
async changePassword(email, current_server_pw, newKeys, newAuthParams) {
|
||||
super.changePassword(email, current_server_pw, newKeys, newAuthParams).then((response) => {
|
||||
if(!response.error) {
|
||||
this.checkForSecurityUpdate();
|
||||
}
|
||||
return this.resolveResponseInTimeout(response);
|
||||
})
|
||||
}
|
||||
|
||||
async handleAuthResponse(response, email, url, authParams, keys) {
|
||||
try {
|
||||
super.handleAuthResponse(response, email, url, authParams, keys);
|
||||
await super.handleAuthResponse(response, email, url, authParams, keys);
|
||||
this._authParams = authParams;
|
||||
this.user = response.user;
|
||||
this.storageManager.setItem("user", JSON.stringify(response.user));
|
||||
@@ -110,25 +124,6 @@ class AuthManager extends SFAuthManager {
|
||||
}
|
||||
}
|
||||
|
||||
register(url, email, password, ephemeral, callback) {
|
||||
super.register(url, email, password, ephemeral, (response) => {
|
||||
if(!response.error) {
|
||||
this.setEphemeral(ephemeral);
|
||||
}
|
||||
callback(response);
|
||||
})
|
||||
}
|
||||
|
||||
changePassword(email, current_server_pw, newKeys, newAuthParams, callback) {
|
||||
super.changePassword(email, current_server_pw, newKeys, newAuthParams, (response) => {
|
||||
if(!response.error) {
|
||||
// Allows security update status to be changed if neccessary
|
||||
this.checkForSecurityUpdate();
|
||||
}
|
||||
callback(response);
|
||||
})
|
||||
}
|
||||
|
||||
checkForSecurityUpdate() {
|
||||
if(this.offline()) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user