From fc12b63fcc41a06ee818428640f962fbea536e1f Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 21 May 2019 23:35:40 +0300 Subject: [PATCH 1/2] mastoapi login works --- .../user_settings/user_settings.vue | 1 + src/services/api/api.service.js | 6 ++--- .../entity_normalizer.service.js | 23 +++++++++++++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index 2cb8b37a..377e8295 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -44,6 +44,7 @@ diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index c67eccf1..115c3296 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -1,5 +1,4 @@ /* eslint-env browser */ -const LOGIN_URL = '/api/account/verify_credentials.json' const REGISTRATION_URL = '/api/account/register.json' const BG_UPDATE_URL = '/api/qvitter/update_background_image.json' const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json' @@ -17,6 +16,7 @@ const ACTIVATION_STATUS_URL = screenName => `/api/pleroma/admin/users/${screenNa const ADMIN_USERS_URL = '/api/pleroma/admin/users' const SUGGESTIONS_URL = '/api/v1/suggestions' +const MASTODON_LOGIN_URL = '/api/v1/accounts/verify_credentials' const MASTODON_USER_FAVORITES_TIMELINE_URL = '/api/v1/favourites' const MASTODON_USER_NOTIFICATIONS_URL = '/api/v1/notifications' const MASTODON_FAVORITE_URL = id => `/api/v1/statuses/${id}/favourite` @@ -497,8 +497,7 @@ const fetchPinnedStatuses = ({ id, credentials }) => { } const verifyCredentials = (user) => { - return fetch(LOGIN_URL, { - method: 'POST', + return fetch(MASTODON_LOGIN_URL, { headers: authHeaders(user) }) .then((response) => { @@ -510,6 +509,7 @@ const verifyCredentials = (user) => { } } }) + .then((data) => data.error ? data : parseUser(data)) } diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index 46ca7602..f14c483c 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -72,6 +72,27 @@ export const parseUser = (data) => { moderator: data.pleroma.is_moderator, admin: data.pleroma.is_admin } + // TODO: Clean up in UI? This is duplication from what BE does for qvitterapi + if (output.rights.admin) { + output.role = 'admin' + } else if (output.rights.moderator) { + output.role = 'moderator' + } else { + output.role = 'member' + } + } + + if (data.source) { + output.description = data.source.note + output.default_scope = data.source.privacy + if (data.source.pleroma) { + if (data.source.pleroma.show_role) { + console.log(data.source) + console.log(data.pleroma) + } + output.no_rich_text = data.source.pleroma.no_rich_text + output.show_role = data.source.pleroma.show_role + } } // TODO: handle is_local @@ -106,8 +127,6 @@ export const parseUser = (data) => { output.muted = data.muted - // QVITTER ONLY FOR NOW - // Really only applies to logged in user, really.. I THINK if (data.rights) { output.rights = { moderator: data.rights.delete_others_notice, From a7b0b07e6fc81aa30769059ada197c824dfb0efb Mon Sep 17 00:00:00 2001 From: HJ <30-hj@users.noreply.git.pleroma.social> Date: Wed, 12 Jun 2019 11:44:14 +0000 Subject: [PATCH 2/2] Apply suggestion to src/services/entity_normalizer/entity_normalizer.service.js --- src/services/entity_normalizer/entity_normalizer.service.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index f14c483c..d68e5f72 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -86,10 +86,6 @@ export const parseUser = (data) => { output.description = data.source.note output.default_scope = data.source.privacy if (data.source.pleroma) { - if (data.source.pleroma.show_role) { - console.log(data.source) - console.log(data.pleroma) - } output.no_rich_text = data.source.pleroma.no_rich_text output.show_role = data.source.pleroma.show_role }