Merge branch 'feature/add-login-pleroma-link' into 'master'

Add "login-pleroma" link

See merge request pleroma/admin-fe!41
This commit is contained in:
Maxim Filippov 2019-09-13 20:50:21 +00:00
commit 433bd2d1db
6 changed files with 52 additions and 4 deletions

View file

@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added ### Added
- add ability to configure new settings (UploadS3 bucket namespace, Rate limit for Activity pub routes, Email notifications settings, MRF Vocabulary, user bio and name length and others) - add ability to configure new settings (UploadS3 bucket namespace, Rate limit for Activity pub routes, Email notifications settings, MRF Vocabulary, user bio and name length and others)
- add sign in via PleromaFE
### Changed ### Changed

View file

@ -14,7 +14,7 @@ function hasPermission(roles, permissionRoles) {
return roles.some(role => permissionRoles.indexOf(role) >= 0) return roles.some(role => permissionRoles.indexOf(role) >= 0)
} }
const whiteList = ['/login', '/auth-redirect']// no redirect whitelist const whiteList = ['/login', '/auth-redirect', '/login-pleroma']// no redirect whitelist
export const beforeEachRoute = (to, from, next) => { export const beforeEachRoute = (to, from, next) => {
NProgress.start() // start progress bar NProgress.start() // start progress bar

View file

@ -18,6 +18,11 @@ export const constantRouterMap = [
} }
] ]
}, },
{
path: '/login-pleroma',
component: () => import('@/views/login/pleroma'),
hidden: true
},
{ {
path: '/login', path: '/login',
component: () => import('@/views/login/index'), component: () => import('@/views/login/index'),

View file

@ -0,0 +1,15 @@
import localforage from 'localforage'
import _ from 'lodash'
const pleromaFEStateKey = 'vuex-lz'
export const authenticateWithPleromaFE = async(store) => {
const pleromaFEState = await localforage.getItem(pleromaFEStateKey)
const token = _.get(pleromaFEState, 'oauth.userToken')
if (token === undefined) {
throw new Error('PleromaFE token not found')
}
await store.dispatch('LoginByPleromaFE', { token })
}

View file

@ -53,6 +53,7 @@ import SvgIcon from '@/components/SvgIcon'
import localforage from 'localforage' import localforage from 'localforage'
import _ from 'lodash' import _ from 'lodash'
import i18n from '@/lang' import i18n from '@/lang'
import { authenticateWithPleromaFE } from '@/services/pleromaAuth'
export default { export default {
name: 'Login', name: 'Login',
@ -112,16 +113,16 @@ export default {
async handlePleromaFELogin() { async handlePleromaFELogin() {
this.loadingPleromaFE = true this.loadingPleromaFE = true
try { try {
await this.$store.dispatch('LoginByPleromaFE', { token: this.pleromaFEState.oauth.userToken }) await authenticateWithPleromaFE(this.$store)
} catch (error) { } catch (error) {
this.loadingPleromaFE = false this.loadingPleromaFE = false
this.$message.error(i18n.t('login.pleromaFELoginFailed')) this.$message.error(i18n.t('login.pleromaFELoginFailed'))
} }
this.loadingPleromaFE = false this.loadingPleromaFE = false
this.$router.push({ path: this.redirect || '/users/index' })
this.$message.success(i18n.t('login.pleromaFELoginSucceed')) this.$message.success(i18n.t('login.pleromaFELoginSucceed'))
this.$router.push({ path: this.redirect || '/users/index' })
}, },
getLoginData() { getLoginData() {
const [username, authHost] = this.loginForm.username.split('@') const [username, authHost] = this.loginForm.username.split('@')

View file

@ -0,0 +1,26 @@
<template>
<div />
</template>
<script>
import { Loading } from 'element-ui'
import { authenticateWithPleromaFE } from '@/services/pleromaAuth'
import i18n from '@/lang'
export default {
name: 'LoginPleroma',
async mounted() {
const loadingInstance = Loading.service({ fullscreen: true })
try {
await authenticateWithPleromaFE(this.$store)
} catch (error) {
this.$message.error(i18n.t('login.pleromaFELoginFailed'))
}
loadingInstance.close()
this.$router.push({ path: '/users/index' })
this.$message.success(i18n.t('login.pleromaFELoginSucceed'))
}
}
</script>