Auth async
This commit is contained in:
@@ -303,7 +303,7 @@ angular.module('app')
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
authManager.login(server, email, pw, false, false, {}, function(response){
|
authManager.login(server, email, pw, false, false, {}).then((response) => {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,8 +59,7 @@ class AccountMenu {
|
|||||||
$scope.formData.status = "Generating Login Keys...";
|
$scope.formData.status = "Generating Login Keys...";
|
||||||
$timeout(function(){
|
$timeout(function(){
|
||||||
authManager.login($scope.formData.url, $scope.formData.email, $scope.formData.user_password,
|
authManager.login($scope.formData.url, $scope.formData.email, $scope.formData.user_password,
|
||||||
$scope.formData.ephemeral, $scope.formData.strictSignin, extraParams,
|
$scope.formData.ephemeral, $scope.formData.strictSignin, extraParams).then((response) => {
|
||||||
(response) => {
|
|
||||||
if(!response || response.error) {
|
if(!response || response.error) {
|
||||||
|
|
||||||
syncManager.unlockSyncing();
|
syncManager.unlockSyncing();
|
||||||
@@ -108,7 +107,7 @@ class AccountMenu {
|
|||||||
$scope.formData.status = "Generating Account Keys...";
|
$scope.formData.status = "Generating Account Keys...";
|
||||||
|
|
||||||
$timeout(function(){
|
$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) {
|
if(!response || response.error) {
|
||||||
$scope.formData.status = null;
|
$scope.formData.status = null;
|
||||||
var error = response ? response.error : {message: "An unknown error occured."}
|
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)
|
// 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) => {
|
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) {
|
if(response.error) {
|
||||||
alert(response.error.message ? response.error.message : "There was an error changing your password. Please try again.");
|
alert(response.error.message ? response.error.message : "There was an error changing your password. Please try again.");
|
||||||
$timeout(() => callback(false));
|
$timeout(() => callback(false));
|
||||||
|
|||||||
@@ -56,17 +56,6 @@ class AuthManager extends SFAuthManager {
|
|||||||
return this._authParams;
|
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() {
|
async protocolVersion() {
|
||||||
var authParams = this.getAuthParams();
|
var authParams = this.getAuthParams();
|
||||||
if(authParams && authParams.version) {
|
if(authParams && authParams.version) {
|
||||||
@@ -82,26 +71,51 @@ class AuthManager extends SFAuthManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuthParamsForEmail(url, email, extraParams, callback) {
|
async resolveResponseInTimeout(response) {
|
||||||
super.getAuthParamsForEmail(url, email, extraParams, (response) => {
|
return new Promise((resolve, reject) => {
|
||||||
callback(response);
|
this.$timeout(() => {
|
||||||
})
|
resolve(response);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
login(url, email, password, ephemeral, strictSignin, extraParams, callback) {
|
async getAuthParamsForEmail(url, email, extraParams) {
|
||||||
super.login(url, email, password, ephemeral, strictSignin, extraParams, (response) => {
|
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) {
|
if(!response.error) {
|
||||||
this.setEphemeral(ephemeral);
|
this.setEphemeral(ephemeral);
|
||||||
this.handleAuthResponse(response, email, url, authParams, keys);
|
this.handleAuthResponse(response, email, url, authParams, keys);
|
||||||
this.checkForSecurityUpdate();
|
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 {
|
try {
|
||||||
super.handleAuthResponse(response, email, url, authParams, keys);
|
await super.handleAuthResponse(response, email, url, authParams, keys);
|
||||||
this._authParams = authParams;
|
this._authParams = authParams;
|
||||||
this.user = response.user;
|
this.user = response.user;
|
||||||
this.storageManager.setItem("user", JSON.stringify(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() {
|
checkForSecurityUpdate() {
|
||||||
if(this.offline()) {
|
if(this.offline()) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user