Encara no acaba de crear amb codi
This commit is contained in:
parent
2530991ba0
commit
a7b3ba7cb5
@ -15,9 +15,9 @@ import CreatableSelect from 'react-select/creatable';
|
|||||||
// import { BarraNav } from "./BarraNav/BarraNav";
|
// import { BarraNav } from "./BarraNav/BarraNav";
|
||||||
|
|
||||||
// import InfiniteCalendar from 'react-infinite-calendar';
|
// import InfiniteCalendar from 'react-infinite-calendar';
|
||||||
import 'react-infinite-calendar/styles.css';
|
// import 'react-infinite-calendar/styles.css';
|
||||||
|
|
||||||
function generaCodi() {
|
function generaCodi() {0
|
||||||
return Random.id().slice(0, 5);
|
return Random.id().slice(0, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -53,7 +53,9 @@ export const Login = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (isLogin) {
|
if (isLogin) {
|
||||||
return <form onSubmit={handleLogin}>
|
return <form
|
||||||
|
onSubmit={handleLogin}
|
||||||
|
>
|
||||||
<label htmlFor="email">Correu electrònic o nom d'usuari: </label>
|
<label htmlFor="email">Correu electrònic o nom d'usuari: </label>
|
||||||
<input id="email" type="email" required />
|
<input id="email" type="email" required />
|
||||||
<br />
|
<br />
|
||||||
@ -66,24 +68,103 @@ export const Login = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleRegistration}>
|
<form
|
||||||
|
action={async d => {
|
||||||
|
|
||||||
|
// let userId, codi;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
const username = d.get('username');
|
||||||
|
const email = d.get('email');
|
||||||
|
const tel = d.get('tel');
|
||||||
|
const password = d.get('password');
|
||||||
|
const password2 = d.get('password2');
|
||||||
|
const codi = d.get('codi');
|
||||||
|
|
||||||
|
if (password !== password2) {
|
||||||
|
console.error("Passwords do not match!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("username: ", username);
|
||||||
|
console.log("email: ", email);
|
||||||
|
console.log("tel: ", tel);
|
||||||
|
console.log("password: ", password);
|
||||||
|
console.log("password2: ", password2);
|
||||||
|
console.log("codi: ", codi);
|
||||||
|
|
||||||
|
const uObj = {
|
||||||
|
username,
|
||||||
|
email,
|
||||||
|
tel,
|
||||||
|
password,
|
||||||
|
password2
|
||||||
|
};
|
||||||
|
|
||||||
|
Meteor.callAsync('creaUsuariAmbCodi', uObj, codi);
|
||||||
|
|
||||||
|
// userId = await Accounts.createUser({
|
||||||
|
// username,
|
||||||
|
// email,
|
||||||
|
// password
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
// userId && await Roles.addUsersToRolesAsync(userId, [ROLS_GLOBALS.USUARI]);
|
||||||
|
|
||||||
|
// console.log("userId deL NOU USUARI: ", userId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
alert(err);
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// userId && await Meteor.callAsync('usaCodiAmbUsuari', userId, codi);
|
||||||
|
// navigate('/');
|
||||||
|
// } catch (err2) {
|
||||||
|
// alert(err2);
|
||||||
|
// console.error(err2);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Meteor.callAsync('editaOAfigCodi', {
|
||||||
|
// ...codiGenerat || [],
|
||||||
|
// codi: codiGenerat,
|
||||||
|
// ambit: d.get('selAmbit') || "",
|
||||||
|
// rol: d.get('selRol'),
|
||||||
|
// act_abs: d.get('activ_abs'),
|
||||||
|
// act_cond: d.get('activ_cond'),
|
||||||
|
// periode_validesa_ini: d.get('periode_validesa_ini'),
|
||||||
|
// periode_validesa_fi: d.get('periode_validesa_fi')
|
||||||
|
// })
|
||||||
|
// .then(() => setAmbitSeleccionat(null))
|
||||||
|
// .catch(err => console.error(err))
|
||||||
|
// ;
|
||||||
|
|
||||||
|
}}
|
||||||
|
>
|
||||||
<label htmlFor="username">Nom d'usuari: </label>
|
<label htmlFor="username">Nom d'usuari: </label>
|
||||||
<input id="username" type="text" required />
|
<input id="username" name="username" type="text" required />
|
||||||
<br />
|
<br />
|
||||||
<label htmlFor="email">Correu electrònic: </label>
|
<label htmlFor="email">Correu electrònic: </label>
|
||||||
<input id="email" type="email" required />
|
<input id="email" name="email" type="email" required />
|
||||||
<br />
|
<br />
|
||||||
<label htmlFor="password">Contrasenya: </label>
|
<label htmlFor="password">Contrasenya: </label>
|
||||||
<input id="password" type="password" required />
|
<input id="password" name="password" type="password" required />
|
||||||
<br />
|
<br />
|
||||||
<label htmlFor="password2">Repeteix la contrasenya: </label>
|
<label htmlFor="password2">Repeteix la contrasenya: </label>
|
||||||
<input id="password2" type="password" required />
|
<input id="password2" name="password2" type="password" required />
|
||||||
<br />
|
<br />
|
||||||
<label htmlFor="tel">Telèfon: </label>
|
<label htmlFor="tel">Telèfon: </label>
|
||||||
<input id="tel" type="tel" required />
|
<input id="tel" name="tel" type="tel" required />
|
||||||
<br />
|
<br />
|
||||||
<label htmlFor="codi">Codi d'entrada (opcional): </label>
|
<label htmlFor="codi">Codi d'entrada (opcional): </label>
|
||||||
<input id="codi" type="text" />
|
<input id="codi" name="codi" type="text" style={{textAlign: `center`, fontWeight: `bolder`, fontSize: `1.1rem`}} onChange={ev => ev.target.value = (ev.currentTarget.value.length <= 5 && ev.currentTarget.value.toUpperCase()) || ev.currentTarget.value.slice(0, 5) } />
|
||||||
<br />
|
<br />
|
||||||
<button type="submit">Registrar</button>
|
<button type="submit">Registrar</button>
|
||||||
<button onClick={() => setIsLogin( true )}>Torna per accedir</button>
|
<button onClick={() => setIsLogin( true )}>Torna per accedir</button>
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import { ROLS_GLOBALS, ROLS_DE_POBLE } from '../imports/roles';
|
|||||||
import { NecessitatsCollection } from '../imports/api/necessitats';
|
import { NecessitatsCollection } from '../imports/api/necessitats';
|
||||||
import { TipusCollection } from '../imports/api/tipus';
|
import { TipusCollection } from '../imports/api/tipus';
|
||||||
import { CodisCollection } from '../imports/api/codis';
|
import { CodisCollection } from '../imports/api/codis';
|
||||||
|
// import { Codis } from '../imports/ui/Codis';
|
||||||
|
|
||||||
async function insertPoble({ nomPoble, cp, comarca }) {
|
async function insertPoble({ nomPoble, cp, comarca }) {
|
||||||
await PoblesCollection.insertAsync({ nomPoble, cp, comarca, createdAt: new Date() });
|
await PoblesCollection.insertAsync({ nomPoble, cp, comarca, createdAt: new Date() });
|
||||||
@ -425,6 +426,80 @@ Meteor.methods({
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
'creaUsuariAmbCodi': async function (uObj, codi) {
|
||||||
|
|
||||||
|
const codiObj = await CodisCollection.find({codi}).fetchAsync();
|
||||||
|
|
||||||
|
|
||||||
|
const userId = await Accounts.createUserAsync(uObj);
|
||||||
|
|
||||||
|
const ara = new Date();
|
||||||
|
const dataIni = codiObj.act_cond === "on" ? new Date(codiObj.periode_validesa_ini) : null;
|
||||||
|
const dataFi = codiObj.act_cond === "on" ? new Date(codiObj.periode_validesa_fi) : null;
|
||||||
|
|
||||||
|
console.log("codiObj: ", codiObj);
|
||||||
|
console.log("ara: ", ara);
|
||||||
|
console.log("dataIni: ", dataIni);
|
||||||
|
console.log("dataFi: ", dataFi);
|
||||||
|
console.log(`codiObj.act_cond === "on"`, codiObj.act_cond === "on");
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log(`APLICANT CODI "${codi}" sobre "${userId}".`); // Comprovant si ${Meteor.userId()} és Admin: `, esAdmin);
|
||||||
|
|
||||||
|
if ((codiObj.act_cond==="on" && (ara >= dataIni && ara <= dataFi)) || codiObj.act_abs) {
|
||||||
|
Roles.addUsersToRolesAsync(userId, codiObj.rol, codiObj.ambit);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
'usaCodiAmbUsuari': async function (userId, codi) {
|
||||||
|
// const esAdmin = await Roles.userIsInRoleAsync(Meteor.userId(), "admin");
|
||||||
|
const codiObj = await CodisCollection.find({codi}).fetchAsync();
|
||||||
|
const ara = new Date();
|
||||||
|
const dataIni = codiObj.act_cond === "on" ? new Date(codiObj.periode_validesa_ini) : null;
|
||||||
|
const dataFi = codiObj.act_cond === "on" ? new Date(codiObj.periode_validesa_fi) : null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
console.log("codiObj: ", codiObj);
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log(`APLICANT CODI "${codi}" sobre "${userId}".`); // Comprovant si ${Meteor.userId()} és Admin: `, esAdmin);
|
||||||
|
|
||||||
|
if ((codiObj.act_cond==="on" && (ara >= dataIni || ara <= dataFi)) || codiObj.act_abs) {
|
||||||
|
Roles.addUsersToRolesAsync(userId, codiObj.rol, codiObj.ambit);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// if (esAdmin && codiObj.codi) {
|
||||||
|
// return await CodisCollection.upsertAsync(
|
||||||
|
// {
|
||||||
|
// _id: codiObj._id
|
||||||
|
// }, {
|
||||||
|
// $set: {
|
||||||
|
// ...codiObj,
|
||||||
|
// usuari: Meteor.userId(),
|
||||||
|
// editedAt: new Date()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
// } else {
|
||||||
|
// throw new Error("El valor del codi no és vàlid");
|
||||||
|
// }
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user