You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

normalForm.tsx 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. 'use client'
  2. import React, { useCallback, useEffect, useState } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import Link from 'next/link'
  5. import { RiContractLine, RiDoorLockLine, RiErrorWarningFill } from '@remixicon/react'
  6. import Loading from '@/app/components/base/loading'
  7. import MailAndCodeAuth from './components/mail-and-code-auth'
  8. import MailAndPasswordAuth from './components/mail-and-password-auth'
  9. import SSOAuth from './components/sso-auth'
  10. import cn from '@/utils/classnames'
  11. import { LicenseStatus } from '@/types/feature'
  12. import { IS_CE_EDITION } from '@/config'
  13. import { useGlobalPublicStore } from '@/context/global-public-context'
  14. const NormalForm = () => {
  15. const { t } = useTranslation()
  16. const [isLoading, setIsLoading] = useState(true)
  17. const { systemFeatures } = useGlobalPublicStore()
  18. const [authType, updateAuthType] = useState<'code' | 'password'>('password')
  19. const [showORLine, setShowORLine] = useState(false)
  20. const [allMethodsAreDisabled, setAllMethodsAreDisabled] = useState(false)
  21. const init = useCallback(async () => {
  22. try {
  23. setAllMethodsAreDisabled(!systemFeatures.enable_social_oauth_login && !systemFeatures.enable_email_code_login && !systemFeatures.enable_email_password_login && !systemFeatures.sso_enforced_for_signin)
  24. setShowORLine((systemFeatures.enable_social_oauth_login || systemFeatures.sso_enforced_for_signin) && (systemFeatures.enable_email_code_login || systemFeatures.enable_email_password_login))
  25. updateAuthType(systemFeatures.enable_email_password_login ? 'password' : 'code')
  26. }
  27. catch (error) {
  28. console.error(error)
  29. setAllMethodsAreDisabled(true)
  30. }
  31. finally { setIsLoading(false) }
  32. }, [systemFeatures])
  33. useEffect(() => {
  34. init()
  35. }, [init])
  36. if (isLoading) {
  37. return <div className={
  38. cn(
  39. 'flex w-full grow flex-col items-center justify-center',
  40. 'px-6',
  41. 'md:px-[108px]',
  42. )
  43. }>
  44. <Loading type='area' />
  45. </div>
  46. }
  47. if (systemFeatures.license?.status === LicenseStatus.LOST) {
  48. return <div className='mx-auto mt-8 w-full'>
  49. <div className='relative'>
  50. <div className="rounded-lg bg-gradient-to-r from-workflow-workflow-progress-bg-1 to-workflow-workflow-progress-bg-2 p-4">
  51. <div className='shadows-shadow-lg relative mb-2 flex h-10 w-10 items-center justify-center rounded-xl bg-components-card-bg shadow'>
  52. <RiContractLine className='h-5 w-5' />
  53. <RiErrorWarningFill className='absolute -right-1 -top-1 h-4 w-4 text-text-warning-secondary' />
  54. </div>
  55. <p className='system-sm-medium text-text-primary'>{t('login.licenseLost')}</p>
  56. <p className='system-xs-regular mt-1 text-text-tertiary'>{t('login.licenseLostTip')}</p>
  57. </div>
  58. </div>
  59. </div>
  60. }
  61. if (systemFeatures.license?.status === LicenseStatus.EXPIRED) {
  62. return <div className='mx-auto mt-8 w-full'>
  63. <div className='relative'>
  64. <div className="rounded-lg bg-gradient-to-r from-workflow-workflow-progress-bg-1 to-workflow-workflow-progress-bg-2 p-4">
  65. <div className='shadows-shadow-lg relative mb-2 flex h-10 w-10 items-center justify-center rounded-xl bg-components-card-bg shadow'>
  66. <RiContractLine className='h-5 w-5' />
  67. <RiErrorWarningFill className='absolute -right-1 -top-1 h-4 w-4 text-text-warning-secondary' />
  68. </div>
  69. <p className='system-sm-medium text-text-primary'>{t('login.licenseExpired')}</p>
  70. <p className='system-xs-regular mt-1 text-text-tertiary'>{t('login.licenseExpiredTip')}</p>
  71. </div>
  72. </div>
  73. </div>
  74. }
  75. if (systemFeatures.license?.status === LicenseStatus.INACTIVE) {
  76. return <div className='mx-auto mt-8 w-full'>
  77. <div className='relative'>
  78. <div className="rounded-lg bg-gradient-to-r from-workflow-workflow-progress-bg-1 to-workflow-workflow-progress-bg-2 p-4">
  79. <div className='shadows-shadow-lg relative mb-2 flex h-10 w-10 items-center justify-center rounded-xl bg-components-card-bg shadow'>
  80. <RiContractLine className='h-5 w-5' />
  81. <RiErrorWarningFill className='absolute -right-1 -top-1 h-4 w-4 text-text-warning-secondary' />
  82. </div>
  83. <p className='system-sm-medium text-text-primary'>{t('login.licenseInactive')}</p>
  84. <p className='system-xs-regular mt-1 text-text-tertiary'>{t('login.licenseInactiveTip')}</p>
  85. </div>
  86. </div>
  87. </div>
  88. }
  89. return (
  90. <>
  91. <div className="mx-auto mt-8 w-full">
  92. <div className="mx-auto w-full">
  93. <h2 className="title-4xl-semi-bold text-text-primary">{t('login.pageTitle')}</h2>
  94. {!systemFeatures.branding.enabled && <p className='body-md-regular mt-2 text-text-tertiary'>{t('login.welcome')}</p>}
  95. </div>
  96. <div className="relative">
  97. <div className="mt-6 flex flex-col gap-3">
  98. {systemFeatures.sso_enforced_for_signin && <div className='w-full'>
  99. <SSOAuth protocol={systemFeatures.sso_enforced_for_signin_protocol} />
  100. </div>}
  101. </div>
  102. {showORLine && <div className="relative mt-6">
  103. <div className="absolute inset-0 flex items-center" aria-hidden="true">
  104. <div className='h-px w-full bg-gradient-to-r from-background-gradient-mask-transparent via-divider-regular to-background-gradient-mask-transparent'></div>
  105. </div>
  106. <div className="relative flex justify-center">
  107. <span className="system-xs-medium-uppercase px-2 text-text-tertiary">{t('login.or')}</span>
  108. </div>
  109. </div>}
  110. {
  111. (systemFeatures.enable_email_code_login || systemFeatures.enable_email_password_login) && <>
  112. {systemFeatures.enable_email_code_login && authType === 'code' && <>
  113. <MailAndCodeAuth />
  114. {systemFeatures.enable_email_password_login && <div className='cursor-pointer py-1 text-center' onClick={() => { updateAuthType('password') }}>
  115. <span className='system-xs-medium text-components-button-secondary-accent-text'>{t('login.usePassword')}</span>
  116. </div>}
  117. </>}
  118. {systemFeatures.enable_email_password_login && authType === 'password' && <>
  119. <MailAndPasswordAuth isEmailSetup={systemFeatures.is_email_setup} />
  120. {systemFeatures.enable_email_code_login && <div className='cursor-pointer py-1 text-center' onClick={() => { updateAuthType('code') }}>
  121. <span className='system-xs-medium text-components-button-secondary-accent-text'>{t('login.useVerificationCode')}</span>
  122. </div>}
  123. </>}
  124. </>
  125. }
  126. {allMethodsAreDisabled && <>
  127. <div className="rounded-lg bg-gradient-to-r from-workflow-workflow-progress-bg-1 to-workflow-workflow-progress-bg-2 p-4">
  128. <div className='shadows-shadow-lg mb-2 flex h-10 w-10 items-center justify-center rounded-xl bg-components-card-bg shadow'>
  129. <RiDoorLockLine className='h-5 w-5' />
  130. </div>
  131. <p className='system-sm-medium text-text-primary'>{t('login.noLoginMethod')}</p>
  132. <p className='system-xs-regular mt-1 text-text-tertiary'>{t('login.noLoginMethodTip')}</p>
  133. </div>
  134. <div className="relative my-2 py-2">
  135. <div className="absolute inset-0 flex items-center" aria-hidden="true">
  136. <div className='h-px w-full bg-gradient-to-r from-background-gradient-mask-transparent via-divider-regular to-background-gradient-mask-transparent'></div>
  137. </div>
  138. </div>
  139. </>}
  140. {!systemFeatures.branding.enabled && <>
  141. <div className="system-xs-regular mt-2 block w-full text-text-tertiary">
  142. {t('login.tosDesc')}
  143. &nbsp;
  144. <Link
  145. className='system-xs-medium text-text-secondary hover:underline'
  146. target='_blank' rel='noopener noreferrer'
  147. href='https://dify.ai/terms'
  148. >{t('login.tos')}</Link>
  149. &nbsp;&&nbsp;
  150. <Link
  151. className='system-xs-medium text-text-secondary hover:underline'
  152. target='_blank' rel='noopener noreferrer'
  153. href='https://dify.ai/privacy'
  154. >{t('login.pp')}</Link>
  155. </div>
  156. {IS_CE_EDITION && <div className="w-hull system-xs-regular mt-2 block text-text-tertiary">
  157. {t('login.goToInit')}
  158. &nbsp;
  159. <Link
  160. className='system-xs-medium text-text-secondary hover:underline'
  161. href='/install'
  162. >{t('login.setAdminAccount')}</Link>
  163. </div>}
  164. </>}
  165. </div>
  166. </div>
  167. </>
  168. )
  169. }
  170. export default NormalForm