Add 2fa enabling flow to accounts view

This commit is contained in:
Johannes Zellner
2018-04-26 15:12:29 +02:00
parent 3f082ccace
commit 7a24d5fdfa
3 changed files with 150 additions and 4 deletions
+35 -2
View File
@@ -111,7 +111,8 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
id: null,
username: null,
email: null,
admin: false
admin: false,
twoFactorAuthenticationEnabled: false
};
this._config = {
apiServerOrigin: null,
@@ -220,6 +221,7 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
this._userInfo.fallbackEmail = userInfo.fallbackEmail;
this._userInfo.displayName = userInfo.displayName;
this._userInfo.admin = !!userInfo.admin;
this._userInfo.twoFactorAuthenticationEnabled = userInfo.twoFactorAuthenticationEnabled;
this._userInfo.gravatar = 'https://www.gravatar.com/avatar/' + md5.createHash(userInfo.email) + '.jpg?s=24&d=mm';
this._userInfo.gravatarHuge = 'https://www.gravatar.com/avatar/' + md5.createHash(userInfo.email) + '.jpg?s=128&d=mm';
};
@@ -725,7 +727,7 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
if (status !== 201 || typeof data !== 'object') return callback(new ClientError(status, data));
that.setToken(data.token);
that.setUserInfo({ username: username, email: email, admin: true });
that.setUserInfo({ username: username, email: email, admin: true, twoFactorAuthenticationEnabled: false });
callback(null, data.activated);
}).error(defaultErrorHandler(callback));
@@ -930,6 +932,37 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
}).error(defaultErrorHandler(callback));
};
Client.prototype.setTwoFactorAuthenticationSecret = function (callback) {
var data = {};
post('/api/v1/profile/twofactorauthentication', data).success(function(data, status) {
if (status !== 201) return callback(new ClientError(status, data));
callback(null, data);
}).error(defaultErrorHandler(callback));
};
Client.prototype.enableTwoFactorAuthentication = function (totpToken, callback) {
var data = {
totpToken: totpToken
};
post('/api/v1/profile/twofactorauthentication/enable', data).success(function(data, status) {
if (status !== 202) return callback(new ClientError(status, data));
callback(null);
}).error(defaultErrorHandler(callback));
};
Client.prototype.disableTwoFactorAuthentication = function (password, callback) {
var data = {
password: password
};
post('/api/v1/profile/twofactorauthentication/disable', data).success(function(data, status) {
if (status !== 202) return callback(new ClientError(status, data));
callback(null);
}).error(defaultErrorHandler(callback));
};
Client.prototype.refreshUserInfo = function (callback) {
var that = this;