Add support to upload custom profile avatar

This commit is contained in:
Johannes Zellner
2019-11-25 16:12:43 +01:00
parent beb3117bfc
commit 165ad229e2
4 changed files with 165 additions and 6 deletions
+28 -4
View File
@@ -206,7 +206,8 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
username: null,
email: null,
twoFactorAuthenticationEnabled: false,
source: null
source: null,
avatarUrl: null
};
this._config = {
apiServerOrigin: null,
@@ -332,8 +333,7 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
this._userInfo.twoFactorAuthenticationEnabled = userInfo.twoFactorAuthenticationEnabled;
this._userInfo.admin = userInfo.admin;
this._userInfo.source = userInfo.source;
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';
this._userInfo.avatarUrl = userInfo.avatarUrl;
};
Client.prototype.setConfig = function (config) {
@@ -1230,7 +1230,7 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
if (status !== 201) return callback(new ClientError(status, data));
that.setToken(data.token);
that.setUserInfo({ username: username, email: email, admin: true, twoFactorAuthenticationEnabled: false, source: '' });
that.setUserInfo({ username: username, email: email, admin: true, twoFactorAuthenticationEnabled: false, source: '', avatarUrl: null });
callback(null, data.activated);
});
@@ -1470,6 +1470,30 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
});
};
Client.prototype.clearAvatar = function (callback) {
del('/api/v1/profile/avatar', {}, function (error, data, status) {
if (error) return callback(error);
if (status !== 202) return callback(new ClientError(status, data));
callback(null);
});
};
Client.prototype.changeAvatar = function (avatarFile, callback) {
var fd = new FormData();
fd.append('avatar', avatarFile);
var config = {
headers: { 'Content-Type': undefined },
transformRequest: angular.identity
};
post('/api/v1/profile/avatar', fd, config, function (error, data, status) {
if (error) return callback(error);
if (status !== 202) return callback(new ClientError(status, data));
callback(null);
});
};
Client.prototype.changePassword = function (currentPassword, newPassword, callback) {
var data = {
password: currentPassword,