fix: redirect to FC dashboard when login to FC
This commit is contained in:
@@ -1,94 +0,0 @@
|
||||
<template>
|
||||
<Dialog
|
||||
v-model="show"
|
||||
:options="{
|
||||
size: 'xl',
|
||||
title: __('Login to Frappe Cloud'),
|
||||
actions: [
|
||||
{
|
||||
label: __('Verify'),
|
||||
variant: 'solid',
|
||||
onClick: (close) => {
|
||||
verifyCode(close)
|
||||
},
|
||||
},
|
||||
],
|
||||
}"
|
||||
>
|
||||
<template #body-content>
|
||||
<div>
|
||||
<p>
|
||||
{{ __('We have sent the verificaton code to your email id ') }}
|
||||
<b>{{ props.email }}</b>
|
||||
</p>
|
||||
<FormControl
|
||||
v-model="code"
|
||||
:label="__('Verification Code')"
|
||||
class="mb-4"
|
||||
/>
|
||||
<p>
|
||||
{{ __("Didn't receive the code?") }}
|
||||
<a href="#" @click="resendCode">{{ __('Resend') }}</a>
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
<script setup>
|
||||
import { call, Dialog } from 'frappe-ui'
|
||||
import { showToast } from '@/utils'
|
||||
|
||||
const show = defineModel()
|
||||
const code = ref('')
|
||||
|
||||
const props = defineProps({
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
})
|
||||
|
||||
const verifyCode = (close) => {
|
||||
if (!code.value) {
|
||||
return
|
||||
}
|
||||
call(
|
||||
'frappe.integrations.frappe_providers.frappecloud_billing.verify_verification_code',
|
||||
{
|
||||
verification_code: code.value,
|
||||
route: window.route,
|
||||
}
|
||||
)
|
||||
.then((data) => {
|
||||
if (data.message.login_token) {
|
||||
close()
|
||||
window.open(
|
||||
`${frappeCloudBaseEndpoint}/api/method/press.api.developer.saas.login_to_fc?token=${data.message.login_token}`,
|
||||
'_blank'
|
||||
)
|
||||
showToast(
|
||||
__('Frappe Cloud Login Successful'),
|
||||
`<p>${__('You will be redirected to Frappe Cloud soon.')}</p><p>${__(
|
||||
"If you haven't been redirected,"
|
||||
)} <a href="${frappeCloudBaseEndpoint}/api/method/press.api.developer.saas.login_to_fc?token=${
|
||||
data.message.login_token
|
||||
}" target="_blank">${__('Click here to login')}</a></p>`,
|
||||
'check'
|
||||
)
|
||||
} else {
|
||||
showToast(__('Login failed'), __('Please try again'), 'x')
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
showToast(__('Login failed'), __('Please try again'), 'x')
|
||||
})
|
||||
}
|
||||
|
||||
const resendCode = () => {
|
||||
call(
|
||||
'frappe.integrations.frappe_providers.frappecloud_billing.send_verification_code'
|
||||
).catch((err) => {
|
||||
showToast(__('Failed to resend code'), __('Please try again'), 'x')
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@@ -59,22 +59,19 @@
|
||||
v-if="userResource.data?.is_moderator"
|
||||
v-model="showSettingsModal"
|
||||
/>
|
||||
<FCVerfiyCodeModal v-if="showFCLoginDialog" :email="verificationEmail" />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import LMSLogo from '@/components/Icons/LMSLogo.vue'
|
||||
import { sessionStore } from '@/stores/session'
|
||||
import { call, Dropdown } from 'frappe-ui'
|
||||
import { Dropdown } from 'frappe-ui'
|
||||
import Apps from '@/components/Apps.vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { convertToTitleCase, showToast } from '@/utils'
|
||||
import { convertToTitleCase } from '@/utils'
|
||||
import { usersStore } from '@/stores/user'
|
||||
import { useSettings } from '@/stores/settings'
|
||||
import { markRaw, watch, ref, onMounted, computed } from 'vue'
|
||||
import SettingsModal from '@/components/Modals/Settings.vue'
|
||||
import { createDialog } from '@/utils/dialogs'
|
||||
import FCVerfiyCodeModal from './Modals/FCVerfiyCodeModal.vue'
|
||||
import {
|
||||
ChevronDown,
|
||||
LogIn,
|
||||
@@ -93,12 +90,8 @@ const settingsStore = useSettings()
|
||||
let { isLoggedIn } = sessionStore()
|
||||
const showSettingsModal = ref(false)
|
||||
const theme = ref('light')
|
||||
const $dialog = createDialog
|
||||
const frappeCloudBaseEndpoint = 'https://frappecloud.com'
|
||||
|
||||
const showFCLoginDialog = ref(false)
|
||||
const verificationEmail = ref(null)
|
||||
|
||||
const props = defineProps({
|
||||
isCollapsed: {
|
||||
type: Boolean,
|
||||
@@ -169,7 +162,11 @@ const userDropdownOptions = computed(() => {
|
||||
icon: LogInIcon,
|
||||
label: 'Login to Frappe Cloud',
|
||||
onClick: () => {
|
||||
initiateRequestForLoginToFrappeCloud()
|
||||
let redirect_to = '/dashboard/welcome'
|
||||
if (userResource.data.site_info.is_payment_method_added) {
|
||||
redirect_to = '/dashboard/sites/' + userResource.data.sitename
|
||||
}
|
||||
window.open(`${frappeCloudBaseEndpoint}${redirect_to}`, '_blank')
|
||||
},
|
||||
condition: () => {
|
||||
return (
|
||||
@@ -202,48 +199,4 @@ const userDropdownOptions = computed(() => {
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
const initiateRequestForLoginToFrappeCloud = () => {
|
||||
$dialog({
|
||||
title: __('Login to Frappe Cloud?'),
|
||||
message: __(
|
||||
'Are you sure you want to login to your Frappe Cloud dashboard?'
|
||||
),
|
||||
actions: [
|
||||
{
|
||||
label: __('Confirm'),
|
||||
variant: 'solid',
|
||||
onClick(close) {
|
||||
requestLoginToFC()
|
||||
close()
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
const requestLoginToFC = () => {
|
||||
call(
|
||||
'frappe.integrations.frappe_providers.frappecloud_billing.send_verification_code'
|
||||
)
|
||||
.then((data) => {
|
||||
if (data.message.is_user_logged_in) {
|
||||
window.open(
|
||||
`${frappeCloudBaseEndpoint}${data.message.redirect_to}`,
|
||||
'_blank'
|
||||
)
|
||||
return
|
||||
} else {
|
||||
showFCLoginDialog.value = true
|
||||
verificationEmail.value = data.message.email
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
showToast(
|
||||
__('Failed to login to Frappe Cloud'),
|
||||
__('Please try again'),
|
||||
'x'
|
||||
)
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -22,7 +22,10 @@ from frappe.utils import (
|
||||
from lms.lms.utils import get_average_rating, get_lesson_count
|
||||
from xml.dom.minidom import parseString
|
||||
from lms.lms.doctype.course_lesson.course_lesson import save_progress
|
||||
from frappe.integrations.frappe_providers.frappecloud_billing import is_fc_site
|
||||
from frappe.integrations.frappe_providers.frappecloud_billing import (
|
||||
is_fc_site,
|
||||
current_site_info,
|
||||
)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
@@ -176,6 +179,9 @@ def get_user_info():
|
||||
user.is_evaluator = "Batch Evaluator" in user.roles
|
||||
user.is_student = "LMS Student" in user.roles
|
||||
user.is_fc_site = is_fc_site()
|
||||
if user.is_fc_site and user.user_type == "System User":
|
||||
user.site_info = current_site_info()
|
||||
user.sitename = frappe.local.site
|
||||
return user
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user