diff --git a/src/components/Admin/AdminIdentify/Identify/Form/Firebase Querys/BringAdminCode.js b/src/components/Admin/AdminIdentify/Identify/Form/Firebase Querys/BringAdminCode.js index 5199c08..5ad572f 100644 --- a/src/components/Admin/AdminIdentify/Identify/Form/Firebase Querys/BringAdminCode.js +++ b/src/components/Admin/AdminIdentify/Identify/Form/Firebase Querys/BringAdminCode.js @@ -6,7 +6,7 @@ const BringAdminCode = async () => { try { const db = getFirestore(firestore) - const data = await collection(db, 'adminCodes') + const data = await collection(db, 'users') const result = await getDocs(data) return await result.docs.map(doc => doc.data()) diff --git a/src/components/Admin/AdminIdentify/Identify/Form/Firebase Querys/RegisterNewUser.js b/src/components/Admin/AdminIdentify/Identify/Form/Firebase Querys/RegisterNewUser.js index f363ddd..d8f55df 100644 --- a/src/components/Admin/AdminIdentify/Identify/Form/Firebase Querys/RegisterNewUser.js +++ b/src/components/Admin/AdminIdentify/Identify/Form/Firebase Querys/RegisterNewUser.js @@ -1,14 +1,24 @@ import { firestore } from '../../../../../../Firebase/Firebase_Config' -import {getAuth, createUserWithEmailAndPassword} from 'firebase/auth' +import {getAuth, createUserWithEmailAndPassword, } from 'firebase/auth' +import { getFirestore, setDoc, doc } from 'firebase/firestore' -const RegisterNewUser = async (email, password, setMessage) => { +const RegisterNewUser = async (name, email, password, setMessage, position, refferCode) => { const auth = getAuth() try { - const response = await createUserWithEmailAndPassword(auth, email, password) - console.log(response) + const responseUserCreate = await createUserWithEmailAndPassword(auth, email, password) + console.log(responseUserCreate) + + const db = getFirestore(firestore) + + await setDoc(doc(db, 'users', email), { + + name: name, + position: position, + refferCode: refferCode + }) } catch (error) { setMessage('There has been an error registering the user. Please try again later') diff --git a/src/components/Admin/AdminIdentify/Identify/Form/Form.jsx b/src/components/Admin/AdminIdentify/Identify/Form/Form.jsx index 8861d64..bc7a1d4 100644 --- a/src/components/Admin/AdminIdentify/Identify/Form/Form.jsx +++ b/src/components/Admin/AdminIdentify/Identify/Form/Form.jsx @@ -8,6 +8,7 @@ const Form = () => { const [option, setOption] = useState('login') + const [name, setName] = useState('') const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') @@ -88,11 +89,19 @@ const Form = () => {
{ - FormActions(e, [email, password, confirmPassword, adminReferredCode], option, setLoading, setMessage) + FormActions(e, [name, email, password, confirmPassword, adminReferredCode], option, setLoading, setMessage) clearStates() setLoading(true) }} > + setName(e.target.value)} + value={name} + /> + { + + let result = ''; + const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + const charactersLength = characters.length; + + for ( var i = 0; i < length; i++ ) { + + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + + } + return result; +} + +export default MakeRandomString diff --git a/src/components/Admin/AdminIdentify/Identify/Form/Scripts/ValidateRegister.js b/src/components/Admin/AdminIdentify/Identify/Form/Scripts/ValidateRegister.js index c882c0e..d350c9e 100644 --- a/src/components/Admin/AdminIdentify/Identify/Form/Scripts/ValidateRegister.js +++ b/src/components/Admin/AdminIdentify/Identify/Form/Scripts/ValidateRegister.js @@ -1,13 +1,15 @@ import React from 'react' import BringAdminCode from '../Firebase Querys/BringAdminCode' import RegisterNewUser from '../Firebase Querys/RegisterNewUser' +import MakeRandomString from './MakeRandomString' const ValidateRegister = async (data, setMessage) => { - const email = data[0] - const password = data[1] - const confirmPassword = data[2] - const adminRefferCode = data[3] + const name = data[0] + const email = data[1] + const password = data[2] + const confirmPassword = data[3] + const adminRefferCode = data[4] if (password.length < 6) { @@ -29,10 +31,13 @@ const ValidateRegister = async (data, setMessage) => { documents.forEach(document => { - if (adminRefferCode === document.code) { + if (adminRefferCode === document.refferCode) { adminRefferCodeIsValid = true - RegisterNewUser(email, password, setMessage) + + const position = document.position + const refferCode = MakeRandomString(30) + RegisterNewUser(name, email, password, setMessage, position, refferCode) } });