Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3230 | Rev 3263 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3230 Rev 3262
Línea 4... Línea 4...
4
import { useDispatch, useSelector } from 'react-redux'
4
import { useDispatch, useSelector } from 'react-redux'
5
import { Button, styled, Typography } from '@mui/material'
5
import { Button, styled, Typography } from '@mui/material'
6
import { Mail, Lock } from '@mui/icons-material'
6
import { Mail, Lock } from '@mui/icons-material'
7
import Recaptcha from 'react-recaptcha'
7
import Recaptcha from 'react-recaptcha'
Línea -... Línea 8...
-
 
8
 
8
 
9
import { axios } from '@utils'
-
 
10
import { useMobile } from '@hooks'
-
 
11
import { asyncLogin } from '@store/auth/auth.actions'
9
import { useMobile } from '@hooks'
12
import { addNotification } from '@store/notification/notification.actions'
Línea 10... Línea 13...
10
import CryptoJSAesJson from '@utils/crypto-js/cryptojs-aes-format'
13
import CryptoJSAesJson from '@utils/crypto-js/cryptojs-aes-format'
11
 
14
 
12
import FacebookIcon from '@components/UI/icons/FacebookIcon'
15
import FacebookIcon from '@components/UI/icons/FacebookIcon'
13
import XIcon from '@components/UI/icons/XIcon'
-
 
14
import GoogleIcon from '@components/UI/icons/GoogleIcon'
-
 
15
import { axios } from '@utils'
-
 
16
import { addNotification } from '@store/notification/notification.actions'
16
import XIcon from '@components/UI/icons/XIcon'
17
import { login } from '@store/auth/auth.actions'
17
import GoogleIcon from '@components/UI/icons/GoogleIcon'
18
import Form from '@components/common/form'
18
import Form from '@components/common/form'
19
import Input from '@components/UI/inputs/Input'
19
import Input from '@components/UI/inputs/Input'
Línea 20... Línea 20...
20
import CheckboxInput from '@components/UI/inputs/Checkbox'
20
import CheckboxInput from '@components/UI/inputs/Checkbox'
21
import Spinner from '@components/UI/Spinner'
21
import LoadingWrapper from '@components/common/loading-wrapper'
22
 
22
 
23
const SocialButton = styled(Button)`
23
const SocialButton = styled(Button)`
Línea 38... Línea 38...
38
const Login = ({
38
const Login = ({
39
  facebookOauth = '/signin/facebook',
39
  facebookOauth = '/signin/facebook',
40
  twitterOauth = '/signin/twitter',
40
  twitterOauth = '/signin/twitter',
41
  googleOauth = '/signin/google'
41
  googleOauth = '/signin/google'
42
}) => {
42
}) => {
43
  const [isLoading, setIsLoading] = useState(false)
-
 
44
  const [isVerified, setIsVerified] = useState(false)
43
  const [isVerified, setIsVerified] = useState(false)
45
  const isMobile = useMobile()
-
 
46
 
-
 
47
  const reCaptchaToken = useRef('')
-
 
48
  const reCaptchaInstance = useRef(null)
44
  const reCaptchaInstance = useRef(null)
49
 
-
 
-
 
45
  const reCaptchaToken = useRef('')
50
  const navigate = useNavigate()
46
  const navigate = useNavigate()
51
 
-
 
52
  const dispatch = useDispatch()
47
  const dispatch = useDispatch()
-
 
48
 
53
  const { site_key, aes, access_usign_social_networks } = useSelector(
49
  const { site_key, aes, access_usign_social_networks } = useSelector(
54
    ({ auth }) => auth
50
    ({ auth }) => auth
55
  )
51
  )
-
 
52
 
-
 
53
  const socialNetworksAccessAllowed = access_usign_social_networks === 'y'
-
 
54
  const isMobile = useMobile()
-
 
55
 
56
  const rrssOptions = [
56
  const rrssOptions = [
57
    { label: 'Facebook', icon: FacebookIcon, href: facebookOauth },
57
    { label: 'Facebook', icon: FacebookIcon, href: facebookOauth },
58
    { label: 'Twitter', icon: XIcon, href: twitterOauth },
58
    { label: 'Twitter', icon: XIcon, href: twitterOauth },
59
    { label: 'Google', icon: GoogleIcon, href: googleOauth }
59
    { label: 'Google', icon: GoogleIcon, href: googleOauth }
60
  ]
60
  ]
Línea 61... Línea 61...
61
 
61
 
62
  const {
62
  const {
63
    handleSubmit,
63
    formState: { errors, isSubmitting },
64
    control,
-
 
65
    setError,
64
    control,
66
    getValues,
-
 
67
    setValue,
65
    handleSubmit,
68
    reset,
-
 
69
    formState: { errors }
66
    reset
Línea 70... Línea 67...
70
  } = useForm({ mode: 'all' })
67
  } = useForm({ mode: 'all' })
71
 
68
 
72
  const onSubmitHandler = handleSubmit(
-
 
73
    async ({ email, password, remember }) => {
-
 
74
      const formData = new FormData()
-
 
75
      formData.append('email', CryptoJSAesJson.encrypt(email, aes))
-
 
76
      formData.append('password', CryptoJSAesJson.encrypt(password, aes))
-
 
77
      formData.append('remember', remember ? 1 : 0)
-
 
78
      formData.append('captcha', reCaptchaToken.current)
69
  const onSubmitHandler = handleSubmit(
79
 
-
 
80
      await axios
-
 
81
        .post('/signin', formData)
70
    async ({ email, password, remember }) => {
82
        .then(({ data: response }) => {
-
 
83
          const { success, data } = response
71
      try {
84
 
-
 
85
          if (!success) {
72
        const response = await dispatch(
86
            loginExpiredCallbackHandler()
-
 
87
            reCaptchaInstance.current.reset()
73
          asyncLogin({
88
 
-
 
89
            if (data.constructor.name === 'Object') {
-
 
90
              Object.entries(data).forEach(([key, value]) => {
74
            email: CryptoJSAesJson.encrypt(email, aes),
91
                if (key in getValues()) {
75
            password: CryptoJSAesJson.encrypt(password, aes),
92
                  setError(key, {
-
 
93
                    type: 'manual',
-
 
94
                    message: Array.isArray(value) ? value[0] : value
-
 
95
                  })
76
            remember: remember ? 1 : 0,
96
                }
-
 
97
              })
77
            captcha: reCaptchaToken.current
98
              return
-
 
99
            }
-
 
100
 
78
          })
101
            dispatch(addNotification({ style: 'danger', msg: data }))
-
 
102
            return
79
        )
103
          }
-
 
104
 
-
 
105
          const url = data.redirect.split('.com')[1]
-
 
106
          reCaptchaInstance.current.reset()
-
 
107
          loginExpiredCallbackHandler()
80
        reset()
108
          reset()
81
 
109
          dispatch(login())
82
        console.log(response)
110
 
83
 
111
          isMobile ? navigate('/apps-navigation') : navigate(url)
84
        isMobile ? navigate('/apps-navigation') : navigate('/dashboard')
112
        })
85
      } catch (error) {
113
        .catch((err) => {
86
        dispatch(addNotification({ style: 'danger', msg: error.message }))
114
          console.log(err)
-
 
115
          reCaptchaInstance.current.reset()
87
      } finally {
116
 
-
 
117
          loginExpiredCallbackHandler()
-
 
118
          setValue('password', '')
-
 
119
 
-
 
120
          dispatch(
-
 
121
            addNotification({
-
 
122
              style: 'danger',
-
 
123
              msg: 'Disculpe, ha ocurrido un error'
-
 
124
            })
88
        reCaptchaInstance.current.reset()
125
          )
-
 
126
        })
89
        loginExpiredCallbackHandler()
127
        .finally(() => setIsLoading(false))
90
      }
Línea 128... Línea 91...
128
    }
91
    }
129
  )
92
  )
Línea 157... Línea 120...
157
    reCaptchaInstance.current?.reset()
120
    reCaptchaInstance.current?.reset()
158
  }, [])
121
  }, [])
Línea 159... Línea 122...
159
 
122
 
160
  return (
123
  return (
161
    <Form onSubmit={onSubmitHandler}>
124
    <Form onSubmit={onSubmitHandler}>
Línea 162... Línea 125...
162
      {isLoading && <Spinner absolute />}
125
      <LoadingWrapper loading={isSubmitting} displayChildren></LoadingWrapper>
Línea 163... Línea 126...
163
 
126
 
164
      <Typography variant='h3'>Entrar</Typography>
127
      <Typography variant='h3'>Entrar</Typography>
Línea 224... Línea 187...
224
 
187
 
225
      <Button color='secondary' type='submit' disabled={!isVerified}>
188
      <Button color='secondary' type='submit' disabled={!isVerified}>
226
        Entrar
189
        Entrar
Línea 227... Línea 190...
227
      </Button>
190
      </Button>
228
 
191
 
229
      {access_usign_social_networks === 'y' && (
192
      {socialNetworksAccessAllowed && (
230
        <>
193
        <>
231
          <h4>Entrar usando su red social</h4>
194
          <h4>Entrar usando su red social</h4>
232
          <ul>
195
          <ul>