Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
avibedi1768 committed Sep 10, 2023
1 parent bbcb4c6 commit d906c16
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 26 deletions.
39 changes: 18 additions & 21 deletions src/Components/jsx/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,25 @@ function Login() {
let [user, setUser] = useState('');
let [pass, setPass] = useState('');

function match(){
get(ref(db, 'username/' + user + '/password'))
.then((snapshot)=>{
if(snapshot.exists()){
//username exists!
const p=snapshot.val();
console.log(p);
//if password matches
if(pass == p){
alert("password matches");
window.location.href='/main#'+user;
}else{
alert("password does not match. plz try again");
function match() {
get(ref(db, 'username/' + user + '/credentials/password'))
.then((snapshot) => {
if (snapshot.exists()) {
//username exists!
const p = snapshot.val();
console.log(p);
//if password matches
if (pass == p) {
alert("password matches");
window.location.href='/main#'+user;
} else {
alert("password does not match. plz try again");
}
} else {
alert('no user found. kindly signup');
window.location.href='/signup';
}
}else{
alert('no user found. kindly signup');
window.location.href='/signup';
}
})
.catch((error)=>{
console.log('error in reading: ' + error);
});
})
}

let style1 = {
Expand Down
47 changes: 44 additions & 3 deletions src/Components/jsx/Main.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
import React from 'react'
import React, { useState } from 'react'
import Arrow1 from '../imgs/Arrow 1.png'
import Arrow2 from '../imgs/Arrow 2.png'
import '../css/main.css'

//import firebase
import { db } from '../../firebase'
import { set, ref, get, update } from 'firebase/database'

function Main() {

let [msg, setMsg] = useState('');
let user = window.location.href.split('#')[1];
var n;

function sendmsg() {
console.log(user);
// first get number
get(ref(db, '/username/' + user + '/credentials/number'))
.then((snapshot) => {
n = snapshot.val()
console.log(n + ' inside')
sendToFirebase(n);
})
// console.log(n + ' outside')

}

function sendToFirebase(n) {
//update number
update(ref(db, 'username/' + user + '/credentials'), {
number:n+1
})

//send msg
set(ref(db, 'username/' + user + '/messages/' + n), {
message: msg
})

return


}

return (
<div className='main'>
<div className="container">
Expand All @@ -22,14 +60,17 @@ function Main() {
type="text"
rows="4"
id="msg"
value={msg}
onChange={(e) => setMsg(e.target.value)}
placeholder="Send your message anonymously"
></textarea>
</div>
</div>

<div id="buttons">
<button type="submit" className="btn" id="sugg">Suggestions</button>
<button type="submit" className="btn" id="go">
{/* <button type="submit" className="btn" id="sugg">Suggestions</button> */}

<button type="submit" className="btn" id="go" onClick={sendmsg}>
Go <img id="white_arrow" src={Arrow1} />
<img id="black_arrow" src={Arrow2} /> </button>
<br />
Expand Down
6 changes: 4 additions & 2 deletions src/Components/jsx/Signup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ function Signup() {
}

else {
set(ref(db, 'username/' + user), {
password: pass
set(ref(db, 'username/' + user + '/credentials/'), {
password: pass,
username: user,
number: 0
})

alert('signup successful')
Expand Down

0 comments on commit d906c16

Please sign in to comment.