Mfa wip
This commit is contained in:
33
app/assets/javascripts/app/frontend/models/api/mfa.js
Normal file
33
app/assets/javascripts/app/frontend/models/api/mfa.js
Normal file
@@ -0,0 +1,33 @@
|
||||
class Mfa extends Item {
|
||||
|
||||
constructor(json_obj) {
|
||||
super(json_obj);
|
||||
}
|
||||
|
||||
mapContentToLocalProperties(content) {
|
||||
super.mapContentToLocalProperties(content)
|
||||
this.name = content.name;
|
||||
}
|
||||
|
||||
structureParams() {
|
||||
var params = {
|
||||
name: this.name,
|
||||
};
|
||||
|
||||
_.merge(params, super.structureParams());
|
||||
return params;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {uuid: this.uuid}
|
||||
}
|
||||
|
||||
get content_type() {
|
||||
return "SN|MFA";
|
||||
}
|
||||
|
||||
doNotEncrypt() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -117,7 +117,7 @@ angular.module('app.frontend')
|
||||
}
|
||||
}
|
||||
|
||||
this.login = function(url, email, password, ephemeral, callback) {
|
||||
this.login = function(url, email, password, ephemeral, extraParams, callback) {
|
||||
this.getAuthParamsForEmail(url, email, function(authParams){
|
||||
|
||||
if(!authParams || !authParams.pw_cost) {
|
||||
@@ -150,7 +150,7 @@ angular.module('app.frontend')
|
||||
Neeto.crypto.computeEncryptionKeysForUser(_.merge({password: password}, authParams), function(keys){
|
||||
|
||||
var requestUrl = url + "/auth/sign_in";
|
||||
var params = {password: keys.pw, email: email};
|
||||
var params = _.merge({password: keys.pw, email: email}, extraParams);
|
||||
httpManager.postAbsolute(requestUrl, params, function(response){
|
||||
this.setEphemeral(ephemeral);
|
||||
this.handleAuthResponse(response, email, url, authParams, keys);
|
||||
|
||||
@@ -89,6 +89,12 @@ class AccountMenu {
|
||||
})
|
||||
}
|
||||
|
||||
$scope.submitMfaForm = function() {
|
||||
var params = {};
|
||||
params[$scope.formData.mfa.payload.mfa_key] = $scope.formData.userMfaCode;
|
||||
$scope.login(params);
|
||||
}
|
||||
|
||||
$scope.submitAuthForm = function() {
|
||||
if($scope.formData.showLogin) {
|
||||
$scope.login();
|
||||
@@ -97,19 +103,25 @@ class AccountMenu {
|
||||
}
|
||||
}
|
||||
|
||||
$scope.login = function() {
|
||||
$scope.login = function(extraParams) {
|
||||
$scope.formData.status = "Generating Login Keys...";
|
||||
$timeout(function(){
|
||||
authManager.login($scope.formData.url, $scope.formData.email, $scope.formData.user_password, $scope.formData.ephemeral, function(response){
|
||||
if(!response || response.error) {
|
||||
$scope.formData.status = null;
|
||||
var error = response ? response.error : {message: "An unknown error occured."}
|
||||
if(!response || (response && !response.didDisplayAlert)) {
|
||||
alert(error.message);
|
||||
authManager.login($scope.formData.url, $scope.formData.email, $scope.formData.user_password, $scope.formData.ephemeral, extraParams,
|
||||
(response) => {
|
||||
if(!response || response.error) {
|
||||
$scope.formData.status = null;
|
||||
var error = response ? response.error : {message: "An unknown error occured."}
|
||||
if(error.tag == "mfa-required") {
|
||||
$timeout(() => {
|
||||
$scope.formData.showLogin = false;
|
||||
$scope.formData.mfa = error;
|
||||
})
|
||||
} else if(!response || (response && !response.didDisplayAlert)) {
|
||||
alert(error.message);
|
||||
}
|
||||
} else {
|
||||
$scope.onAuthSuccess();
|
||||
}
|
||||
} else {
|
||||
$scope.onAuthSuccess();
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class ModelManager {
|
||||
this._extensions = [];
|
||||
this.acceptableContentTypes = [
|
||||
"Note", "Tag", "Extension", "SN|Editor", "SN|Theme",
|
||||
"SN|Component", "SF|Extension", "SN|UserPreferences"
|
||||
"SN|Component", "SF|Extension", "SN|UserPreferences", "SF|MFA"
|
||||
];
|
||||
}
|
||||
|
||||
@@ -211,6 +211,8 @@ class ModelManager {
|
||||
item = new Component(json_obj);
|
||||
} else if(json_obj.content_type == "SF|Extension") {
|
||||
item = new SyncAdapter(json_obj);
|
||||
} else if(json_obj.content_type == "SF|MFA") {
|
||||
item = new Mfa(json_obj);
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user