This commit is contained in:
Mo Bitar
2017-12-23 14:21:37 -06:00
parent 0c31668625
commit 93ea71672b
5 changed files with 66 additions and 14 deletions

View 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;
}
}

View File

@@ -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);

View File

@@ -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();
}
});
})
}

View File

@@ -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 {

View File

@@ -5,7 +5,7 @@
-# Account Section
.mb-10
.step-one{"ng-if" => "!formData.showLogin && !formData.showRegister"}
.step-one{"ng-if" => "!formData.showLogin && !formData.showRegister && !formData.mfa"}
%h3 Sign in or register to enable sync and end-to-end encryption.
.small-v-space
@@ -41,6 +41,11 @@
Merge local data ({{notesAndTagsCount()}} notes and tags)
%button.ui-button.block.mt-10{"ng-click" => "submitAuthForm()"} {{formData.showLogin ? "Sign In" : "Register"}}
%form.mt-5{"ng-if" => "formData.mfa"}
%p {{formData.mfa.message}}
%input.form-control.mt-10{:autofocus => 'autofocus', :name => 'mfa', :required => true, 'ng-model' => 'formData.userMfaCode'}
%button.ui-button.block.mt-10{"ng-click" => "submitMfaForm()"} {{"Sign In"}}
.mt-15{"ng-if" => "formData.showRegister"}
%h3 No Password Reset.
%p.mt-5 Because your notes are encrypted using your password, Standard Notes does not have a password reset option. You cannot forget your password.