Browse Source

update pwd with encode functionality

amenpunk 2 years ago
parent
commit
4d0949517a

+ 58 - 45
src/Components/Password/Operation.jsx

5
     Button, Dialog, DialogActions, DialogContent, DialogTitle,
5
     Button, Dialog, DialogActions, DialogContent, DialogTitle,
6
     FormControlLabel, Checkbox,
6
     FormControlLabel, Checkbox,
7
     TextField, Stack,
7
     TextField, Stack,
8
-    //Autocomplete
8
+    // Autocomplete
9
 } from '@mui/material'
9
 } from '@mui/material'
10
 
10
 
11
 import toast, { Toaster } from 'react-hot-toast';
11
 import toast, { Toaster } from 'react-hot-toast';
12
-
13
-
14
-
15
 import * as Yup from 'yup';
12
 import * as Yup from 'yup';
16
 
13
 
17
 import { useQuery } from 'react-query'
14
 import { useQuery } from 'react-query'
23
 import DateFnsUtils from '@date-io/date-fns';
20
 import DateFnsUtils from '@date-io/date-fns';
24
 import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
21
 import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
25
 
22
 
26
-// function getNombrePuesto(id_plaz, puestos){
27
-//     let nombre = "";
28
-//     puestos.forEach(( p) => {
29
-//         if(p.id === id_plaz){
30
-//             nombre = p.nombrepuesto;
31
-//         }
32
-//     })
33
-//     return nombre;
34
-// }
35
-//
36
-
37
 export function Operation(props) {
23
 export function Operation(props) {
38
 
24
 
39
     let [open, setOpen] = React.useState(false);
25
     let [open, setOpen] = React.useState(false);
71
     }
57
     }
72
 
58
 
73
     let { data: result } = useQuery('contra', getPassword);
59
     let { data: result } = useQuery('contra', getPassword);
74
-
60
+    console.log('PWD INFO ',result)
61
+    //
75
     // const getPuestos = async () => {
62
     // const getPuestos = async () => {
76
     //     let rest = new Service('/plaza/getall')
63
     //     let rest = new Service('/plaza/getall')
77
-    //     return rest.getQuery(token);
64
+    //     return rest.getQuery(token.current);
78
     // }
65
     // }
79
     //
66
     //
80
     // let { data } = useQuery('puestos', getPuestos)
67
     // let { data } = useQuery('puestos', getPuestos)
81
     // let puestos = data ? data.data.map(({ nombrepuesto, id }) => ({ nombrepuesto, id })) : []
68
     // let puestos = data ? data.data.map(({ nombrepuesto, id }) => ({ nombrepuesto, id })) : []
82
 
69
 
83
-
84
     let initialValues = {
70
     let initialValues = {
85
         id: result?.data?.id,
71
         id: result?.data?.id,
86
         pwd: result?.data?.pwd,
72
         pwd: result?.data?.pwd,
87
         deadpwd: result?.data?.deadpwd ? new Date(result?.data?.deadpwd) : now.current,
73
         deadpwd: result?.data?.deadpwd ? new Date(result?.data?.deadpwd) : now.current,
88
         state: result?.data?.state,
74
         state: result?.data?.state,
89
-        dateToActived:
90
-            result?.data.dateToActived ? new Date(result?.data?.dateToActived) : now.current,
91
-        // plaza_id: [{ id:result?.data?.plaza_id, }]
75
+        dateToActived: result?.data.dateToActived ? new Date(result?.data?.dateToActived) : now.current,
76
+        plaza_id: result?.data?.plaza_id,
77
+        candidato_id : result?.data?.candidato_id
92
     }
78
     }
93
 
79
 
94
     return (
80
     return (
98
             aria-labelledby="alert-dialog-title"
84
             aria-labelledby="alert-dialog-title"
99
             aria-describedby="alert-dialog-description"
85
             aria-describedby="alert-dialog-description"
100
         >
86
         >
101
-            <DialogTitle id="alert-dialog-title">
102
-                {pwd}
103
-            </DialogTitle>
104
             <DialogContent>
87
             <DialogContent>
105
                 <ModalForm
88
                 <ModalForm
89
+                    //puestos={puestos}
106
                     initialValues={initialValues}
90
                     initialValues={initialValues}
107
                     handleOpen={handleOpen}
91
                     handleOpen={handleOpen}
92
+                    token={token.current}
108
                 />
93
                 />
109
             </DialogContent>
94
             </DialogContent>
110
         </Dialog>
95
         </Dialog>
113
 
98
 
114
 function ModalForm(props) {
99
 function ModalForm(props) {
115
 
100
 
116
-
117
     const pwdSchema = Yup.object().shape({
101
     const pwdSchema = Yup.object().shape({
118
         id: Yup.number(),
102
         id: Yup.number(),
119
         pwd: Yup.string().required("Escoge un nombre valido"),
103
         pwd: Yup.string().required("Escoge un nombre valido"),
120
         deadpwd: Yup.date().required("Escoge una fecha valida"),
104
         deadpwd: Yup.date().required("Escoge una fecha valida"),
121
         state: Yup.number(),
105
         state: Yup.number(),
122
         dateToActived: Yup.date('Escoge una fecha valida').required("Escoge una fecha valida"),
106
         dateToActived: Yup.date('Escoge una fecha valida').required("Escoge una fecha valida"),
123
-        // plaza_id: Yup.array().required("Escoge una plaza valida")
107
+        //plaza_id: Yup.array().required("Escoge una plaza valida")
108
+        //plaza_id: Yup.array().required("Escoge una plaza valida")
124
     })
109
     })
125
 
110
 
126
-
127
     const formik = useFormik({
111
     const formik = useFormik({
128
         initialValues: {
112
         initialValues: {
129
             state: 1,
113
             state: 1,
130
             pwd:"",
114
             pwd:"",
131
             deadpwd:"",
115
             deadpwd:"",
132
             dateToActived:"",
116
             dateToActived:"",
133
-            // plaza_id:[]
117
+            // plaza_id:[],
134
         },
118
         },
135
         onSubmit: (fields) => {
119
         onSubmit: (fields) => {
136
-            console.log('campos> ', fields)
137
-            toast.success("Contraseña Actualizada")
138
-            setTimeout(()=>{
139
-                props.handleOpen(false)
140
-            },1000)
120
+
121
+            let rest = new Service('/contrasenia/create');
122
+            let { deadpwd,dateToActived,pwd } = fields
123
+            
124
+            fields['pwd'] = btoa(pwd);
125
+            fields['deadpwd'] = new Date(deadpwd).toISOString();
126
+            fields['dateToActived'] = new Date(dateToActived).toISOString();
127
+            fields['candidato_id'] = props.initialValues.candidato_id
128
+            fields['plaza_id'] = props.initialValues.plaza_id
129
+
130
+            rest.put(fields, props.token)
131
+                .then(result => {
132
+                    console.log(result)
133
+                    setTimeout(()=>{
134
+                        props.handleOpen(false)
135
+                    },700)
136
+                    toast.success("Contraseña Actualizada")
137
+                })
138
+                .catch(bad => {
139
+                    console.log('ERROR',bad)
140
+                    toast.error("Ocurrio un error")
141
+                })
141
         },
142
         },
142
         validationSchema: pwdSchema,
143
         validationSchema: pwdSchema,
143
     })
144
     })
145
     const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
146
     const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
146
 
147
 
147
     React.useEffect(() => {
148
     React.useEffect(() => {
148
-        setValues({ ...props.initialValues })
149
+        setValues({ 
150
+            ...props.initialValues,
151
+            pwd : props.initialValues.pwd ? atob( props.initialValues.pwd ) : 'loading'
152
+        })
149
     }, [props, setValues])
153
     }, [props, setValues])
150
 
154
 
151
     return (
155
     return (
152
         <FormikProvider value={formik}>
156
         <FormikProvider value={formik}>
153
-            <Form style={{ padding: 20, maxWidth: 450 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
157
+            <Form style={{ padding: 20, maxWidth: 950 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
154
                 <Stack spacing={4}>
158
                 <Stack spacing={4}>
159
+                    <TextField
160
+                        value={btoa( values.pwd )}
161
+                        variant="filled"
162
+                        disabled
163
+                        fullWidth
164
+                        type="text"
165
+                        label="Contraseña Cifrada"
166
+                        />
155
 
167
 
156
                     <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
168
                     <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
157
 
169
 
158
                         <TextField
170
                         <TextField
159
-                            fullWidth
160
                             type="text"
171
                             type="text"
161
                             label="Contraseña"
172
                             label="Contraseña"
162
                             {...getFieldProps('pwd')}
173
                             {...getFieldProps('pwd')}
181
                         />
192
                         />
182
 
193
 
183
                     </Stack>
194
                     </Stack>
184
-
195
+                        
185
 
196
 
186
                     <LocalizationProvider
197
                     <LocalizationProvider
187
                         dateAdapter={DateFnsUtils}>
198
                         dateAdapter={DateFnsUtils}>
227
                     </LocalizationProvider>
238
                     </LocalizationProvider>
228
 
239
 
229
 
240
 
230
-                        {/*
241
+                    {/*
231
                     <Autocomplete
242
                     <Autocomplete
243
+                        {...getFieldProps('plaza_id')}
244
+                        onChange={(_a,current_list,_c,_individual,_f) => {
245
+                            console.log("CURRENT LIST : ",current_list)
246
+                            setValues({
247
+                                ...values,
248
+                                plaza_id:current_list
249
+                            })
250
+                        }}
251
+                        value={props.puestos.filter(p=> p.id=== values.plaza_id ).shift()}
232
                         id="combo-box-demo"
252
                         id="combo-box-demo"
233
                         options={props.puestos}
253
                         options={props.puestos}
234
                         isOptionEqualToValue={
254
                         isOptionEqualToValue={
237
                         getOptionLabel={(option) => {
257
                         getOptionLabel={(option) => {
238
                             return option.nombrepuesto
258
                             return option.nombrepuesto
239
                         }}
259
                         }}
240
-                        onChange={(_e, newValue) => {
241
-                            console.log('CHANGE',newValue);
242
-                            setValues({
243
-                                ...values,
244
-                                plaza_id:newValue
245
-                            })
246
-                        }}
247
                         renderInput={(params) =>
260
                         renderInput={(params) =>
248
                             <TextField
261
                             <TextField
249
                                 {...params}
262
                                 {...params}

+ 2 - 2
src/Components/Password/Rows.js

31
         disablePadding: true,
31
         disablePadding: true,
32
         label: 'Operación',
32
         label: 'Operación',
33
         options: {
33
         options: {
34
-            filter: true,
34
+            filter: false,
35
             sort: false,
35
             sort: false,
36
         }
36
         }
37
     },
37
     },
54
     return pwds.map(password => {
54
     return pwds.map(password => {
55
         let { candidato: user, plaza_id, pwd } = password
55
         let { candidato: user, plaza_id, pwd } = password
56
         return {
56
         return {
57
-            pass: atob( pwd ),
57
+            pass: pwd ? atob(pwd): '',
58
             name: user.nombre,
58
             name: user.nombre,
59
             apell: user.apellidos,
59
             apell: user.apellidos,
60
             mail: user.mail,
60
             mail: user.mail,

+ 1 - 0
src/Components/Password/Steps/password.jsx

76
                         fullWidth
76
                         fullWidth
77
                         type="text"
77
                         type="text"
78
                         label="Identificador Codificado"
78
                         label="Identificador Codificado"
79
+                        variant="filled"
79
                         />
80
                         />
80
 
81
 
81
                     <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
82
                     <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>

+ 1 - 1
src/Components/User.jsx

87
                         <MenuIcon />
87
                         <MenuIcon />
88
                     </IconButton>
88
                     </IconButton>
89
                     <Typography variant="h6" noWrap component="div">
89
                     <Typography variant="h6" noWrap component="div">
90
-                        Responsive drawer
90
+                        Pruebas Psicometricas
91
                     </Typography>
91
                     </Typography>
92
                 </Toolbar>
92
                 </Toolbar>
93
             </AppBar>
93
             </AppBar>

+ 2 - 2
src/Pages/ContrasV2.jsx

20
         return await rest.getQuery(token.current)
20
         return await rest.getQuery(token.current)
21
     }
21
     }
22
 
22
 
23
-    const { data  } = useQuery('passwords', getAllPwd );
23
+    const { data, status  } = useQuery('passwords', getAllPwd );
24
 
24
 
25
     const options = {
25
     const options = {
26
         filterType: 'checkbox',
26
         filterType: 'checkbox',
42
                             <MUIDataTable
42
                             <MUIDataTable
43
                                 sx={{ '& MuiPaper': { elevation: 0, boxShadow: 'none', color: "red" } }}
43
                                 sx={{ '& MuiPaper': { elevation: 0, boxShadow: 'none', color: "red" } }}
44
                                 title={"Contraseñas"}
44
                                 title={"Contraseñas"}
45
-                                data={Build(data ? data.data : [])}
45
+                                data={Build( status ==='success' ? data.data : [])}
46
                                 columns={Encabezados}
46
                                 columns={Encabezados}
47
                                 options={options}
47
                                 options={options}
48
                             />
48
                             />