This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/components/SocialConnection.vue

87 lines
3.9 KiB
Vue
Raw Normal View History

2020-11-02 10:31:05 -08:00
<template>
<div class="d-flex flex-column flex-md-row justify-content-between align-items-center">
<span class="my-2">
2022-04-22 16:48:40 -07:00
<Icon :v="providerOptions.icon || provider" set="b"
:class="[providerOptions.icon && providerOptions.icon.endsWith('.png') ? 'mx-1 invertible' : '']"/>
2020-11-02 10:31:05 -08:00
{{ providerOptions.name }}
2022-04-23 04:02:20 -07:00
<button v-if="providerOptions.deprecated" class="badge bg-light text-dark border border-warning" @click="depreciationNotice(providerOptions.deprecated)">
<Icon v="exclamation-triangle"/>
<T>user.login.deprecated</T>
</button>
2020-11-02 10:31:05 -08:00
</span>
<span v-if="connection === undefined">
<template v-if="providerOptions.instanceRequired">
<form v-if="formShown"
2022-04-22 16:48:40 -07:00
:action="providerOptions.redirectViaHome ? `${homeUrl}/api/user/social-redirect/${provider}/${config.locale}` : `/api/connect/${provider}`"
class="input-group input-group-sm">
<input type="text" name="instance" class="form-control" autofocus required
:placeholder="$t(providerOptions.domain ? 'user.login.domainPlaceholder' : 'user.login.instancePlaceholder')"/>
<button type="submit" class="btn btn-outline-secondary">
<Icon v="link"/>
</button>
</form>
<button v-else class="badge bg-light text-dark border" @click="formShown = true">
<Icon v="link"/>
<T>user.socialConnection.connect</T>
</button>
</template>
2022-04-22 16:48:40 -07:00
<a v-else :href="providerOptions.redirectViaHome ? `${homeUrl}/api/user/social-redirect/${provider}/${config.locale}` : `/api/connect/${provider}`" class="badge bg-light text-dark border">
2020-11-02 10:31:05 -08:00
<Icon v="link"/>
<T>user.socialConnection.connect</T>
</a>
</span>
<span v-else class="text-center">
2022-04-22 16:48:40 -07:00
<span class="me-2">
<a v-if="providerOptions.avatars && connection.avatar" href="#" @click.prevent="$emit('setAvatar', provider)">
2020-11-02 12:12:15 -08:00
<Avatar :src="connection.avatar" :user="$user()" dsize="2rem"/>
</a>
2020-11-02 10:31:05 -08:00
{{connection.name}}
</span>
<br class="d-md-none"/>
2022-04-22 16:48:40 -07:00
<a :href="(providerOptions.redirectViaHome ? `${homeUrl}/api/user/social-redirect/${provider}/${config.locale}` : `/api/connect/${provider}`) + (providerOptions.instanceRequired ? '?instance=' + connection.name.split('@')[1] : '')"
2022-04-23 04:02:20 -07:00
class="badge bg-light text-dark border">
2020-11-02 10:31:05 -08:00
<Icon v="sync"/>
<T>user.socialConnection.refresh</T>
</a>
<Spinner v-if="disconnecting"/>
2021-01-22 14:54:24 -08:00
<a v-else href="#" class="badge bg-light text-dark" @click.prevent="disconnect">
2020-11-02 10:31:05 -08:00
<Icon v="unlink"/>
<T>user.socialConnection.disconnect</T>
</a>
</span>
</div>
</template>
<script>
2022-04-23 04:02:20 -07:00
export default {
props: {
provider: { required: true },
providerOptions: { required: true },
connection: {},
},
data() {
return {
disconnecting: false,
homeUrl: process.env.HOME_URL,
formShown: false,
}
},
methods: {
async disconnect() {
await this.$confirm(this.$t('user.socialConnection.disconnectConfirm', {email: this.$user().email}), 'danger');
2020-11-02 10:31:05 -08:00
2022-04-23 04:02:20 -07:00
this.disconnecting = true;
try {
const response = await this.$post(`/user/social-connection/${this.provider}/disconnect`);
this.$emit('disconnected', response);
} finally {
this.disconnecting = false;
}
2020-11-02 10:31:05 -08:00
},
2022-04-23 04:02:20 -07:00
async depreciationNotice(link) {
await this.$alert(this.$t('user.login.depreciationNotice', {link}), 'warning');
}
},
}
2020-11-02 10:31:05 -08:00
</script>