Date: Thu, 10 Oct 2024 16:26:55 +0530
Subject: [PATCH 2/7] fix update bug
* fixed delete issue
* fix update bug
---
backend/server.js | 8 ++--
src/components/Manager.jsx | 75 ++++++++++++++++++++------------------
2 files changed, 43 insertions(+), 40 deletions(-)
diff --git a/backend/server.js b/backend/server.js
index 06bb253..454837a 100755
--- a/backend/server.js
+++ b/backend/server.js
@@ -83,8 +83,8 @@ app.post("/", async (req, res) => {
const db = client.db(dbName);
const collection = db.collection("passwords");
// Encrypt the password before saving
- const encryptedPassword = encrypt(password);
- const result = await collection.insertOne({ site, username, password: encryptedPassword });
+ // const encryptedPassword = encrypt(password);
+ const result = await collection.insertOne({ site, username, password});
res.status(201).json({ success: true, result });
} catch (error) {
console.error("Error saving password:", error);
@@ -109,11 +109,11 @@ app.put("/:id", async (req, res) => {
const collection = db.collection("passwords");
// Encrypt the new password before updating
- const encryptedPassword = encrypt(password);
+ // const encryptedPassword = encrypt(password);
const result = await collection.updateOne(
{ _id: new ObjectId(id) },
- { $set: { site, username, password: encryptedPassword } } // Use the encrypted password here
+ { $set: { site, username, password } } // Use the encrypted password here
);
if (result.matchedCount === 0) {
diff --git a/src/components/Manager.jsx b/src/components/Manager.jsx
index 9f8ad20..505862e 100755
--- a/src/components/Manager.jsx
+++ b/src/components/Manager.jsx
@@ -8,7 +8,7 @@ const Manager = () => {
const ref = useRef();
const passwordRef = useRef();
const [form, setForm] = useState({
- id: "",
+ _id: "",
site: "",
username: "",
password: "",
@@ -94,12 +94,14 @@ const Manager = () => {
return errors.length === 0;
};
const savePassword = async () => {
+
const errors = [];
// Validate Site URL
if (form.site.length <= 3 || !validateURL(form.site)) {
errors.push(
"Error: Invalid site name. Ensure it meets the required format."
+
);
}
@@ -132,39 +134,40 @@ const Manager = () => {
}
// Proceed to save the password if all validations pass
- if (form.id) {
- const updatedPasswords = passwordArray.map((item) =>
- item._id === form.id ? { ...form } : item
- );
- setPasswordArray(updatedPasswords);
- await fetch(`http://localhost:3000/${form.id}`, {
- method: "PUT",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify(form),
- });
- } else {
- const newPassword = { ...form, id: uuidv4() };
- setPasswordArray([...passwordArray, newPassword]);
- await fetch("http://localhost:3000/", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify(newPassword),
+ if (form._id) {
+ const updatedPasswords = passwordArray.map((item) =>
+ item._id === form._id ? { ...form } : item
+ );
+ setPasswordArray(updatedPasswords);
+ await fetch(`http://localhost:3000/${form._id}`, {
+ method: "PUT",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(form),
+ });
+ getPasswords();
+ } else {
+ const newPassword = { ...form };
+ setPasswordArray([...passwordArray, newPassword]);
+ await fetch("http://localhost:3000/", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(newPassword),
+ });
+ getPasswords();
+ }
+
+ setForm({ _id: "", site: "", username: "", password: "" });
+ toast("Password saved!", {
+ position: "top-right",
+ autoClose: 5000,
+ hideProgressBar: false,
+ closeOnClick: true,
+ pauseOnHover: true,
+ draggable: true,
+ progress: undefined,
+ theme: "dark",
});
- }
-
- // Clear form and show success toast
- setForm({ id: "", site: "", username: "", password: "" });
- toast("Password saved!", {
- position: "top-right",
- autoClose: 5000,
- hideProgressBar: false,
- closeOnClick: true,
- pauseOnHover: true,
- draggable: true,
- progress: undefined,
- theme: "dark",
- });
- };
+ }
const deletePassword = async (id) => {
const confirmDelete = confirm(
@@ -191,7 +194,7 @@ const Manager = () => {
};
const editPassword = (id) => {
- const passwordToEdit = passwordArray.find((item) => item.id === id);
+ const passwordToEdit = passwordArray.find((item) => item._id === id);
setForm({ ...passwordToEdit });
};
@@ -359,7 +362,7 @@ const Manager = () => {
src="https://cdn.lordicon.com/jgnvfzqg.json"
trigger="hover"
>
- {form.id ? "Update" : "Save"}
+ {form._id ? "Update" : "Save"}
+ {userLoggedIn ?
+
{ doSignOut().then(() => { navigate('/login') }) }} // Navigate to the login page
+ className="flex justify-center items-center gap-2 font-semibold bg-green-500 hover:bg-green-600 rounded-full px-4 py-1 border border-green-900"
+ >
+
+ Sign out
+
+ :
+
navigate('/sign-in')} // Navigate to the login page
+ className="flex justify-center items-center gap-2 font-semibold bg-green-500 hover:bg-green-600 rounded-full px-4 py-1 border border-green-900"
+ >
+
+ Sign in
+
+
+
+ }
+
+
+
+ {userLoggedIn ?
+ : ''}
{
+ const { userLoggedIn } = useAuth();
+
+ const [email, setEmail] = useState('')
+ const [password, setPassword] = useState('')
+ const [isSigningIn, setIsSigningIn] = useState(false)
+ const [errorMessage, setErrorMessage] = useState('')
+
+ const onSubmit = async (e) => {
+ e.preventDefault()
+ if (!isSigningIn) {
+ setIsSigningIn(true)
+ await doSignInWithEmailAndPassword(email, password)
+ // doSendEmailVerification()
+ }
+ }
+
+ const onGoogleSignIn = (e) => {
+ e.preventDefault()
+ if (!isSigningIn) {
+ setIsSigningIn(true)
+ doSignInWithGoogle().catch(err => {
+ setIsSigningIn(false)
+ })
+ }
+ }
+ if (userLoggedIn) {
+ return ;
+ }
+
+ return (
+
+
+
+
+
+
Don't have an account? Sign up
+
+
{ onGoogleSignIn(e) }}
+ className={`w-full flex items-center justify-center gap-x-3 py-2.5 border rounded-lg text-sm font-medium ${isSigningIn ? 'cursor-not-allowed' : 'hover:bg-gray-100 transition duration-300 active:bg-gray-100'}`}>
+
+ {isSigningIn ? 'Signing In...' : 'Continue with Google'}
+
+
+
+
+ )
+}
+
+export default SignIn
\ No newline at end of file
diff --git a/src/components/SignUp.jsx b/src/components/SignUp.jsx
new file mode 100644
index 0000000..c9da772
--- /dev/null
+++ b/src/components/SignUp.jsx
@@ -0,0 +1,107 @@
+import { useState } from 'react'
+import { Navigate, Link } from 'react-router-dom'
+import { useAuth } from '../contexts/authContext/index'
+import { doCreateUserWithEmailAndPassword } from '../firebase/auth'
+
+const Register = () => {
+
+
+ const [email, setEmail] = useState('')
+ const [password, setPassword] = useState('')
+ const [confirmPassword, setconfirmPassword] = useState('')
+ const [isRegistering, setIsRegistering] = useState(false)
+ const [errorMessage, setErrorMessage] = useState('')
+
+ const { userLoggedIn } = useAuth()
+
+ const onSubmit = async (e) => {
+ e.preventDefault()
+ if (!isRegistering) {
+ setIsRegistering(true)
+ await doCreateUserWithEmailAndPassword(email, password)
+ }
+ }
+
+ if (userLoggedIn) {
+ return ;
+ }
+
+ return (
+ <>
+
+
+
+
+
+
Create a New Account
+
+
+
+
+
+
+ >
+ )
+}
+
+export default Register
\ No newline at end of file
diff --git a/src/components/UserAccount.jsx b/src/components/UserAccount.jsx
new file mode 100644
index 0000000..79fc571
--- /dev/null
+++ b/src/components/UserAccount.jsx
@@ -0,0 +1,30 @@
+import { useState } from 'react';
+
+const UserAccount = ({ email, username }) => {
+ const [isHovered, setIsHovered] = useState(false);
+
+ // Extract the first letter of the email for the avatar
+ const avatarLetter = email.charAt(0).toUpperCase();
+
+ return (
+
+
setIsHovered(true)}
+ onMouseLeave={() => setIsHovered(false)}
+ >
+ {avatarLetter}
+
+
+ {isHovered && (
+
+ PassOp Account
+ {email}
+ {username && {username}}
+
+ )}
+
+ );
+};
+
+export default UserAccount;
diff --git a/src/contexts/authContext/index.jsx b/src/contexts/authContext/index.jsx
new file mode 100644
index 0000000..ecc4d83
--- /dev/null
+++ b/src/contexts/authContext/index.jsx
@@ -0,0 +1,63 @@
+import React, { useContext, useState, useEffect } from "react";
+import { auth } from "../../firebase/firebase";
+// import { GoogleAuthProvider } from "firebase/auth";
+import { onAuthStateChanged } from "firebase/auth";
+
+const AuthContext = React.createContext();
+
+export function useAuth() {
+ return useContext(AuthContext);
+}
+
+export function AuthProvider({ children }) {
+ const [currentUser, setCurrentUser] = useState(null);
+ const [userLoggedIn, setUserLoggedIn] = useState(false);
+ const [isEmailUser, setIsEmailUser] = useState(false);
+ const [isGoogleUser, setIsGoogleUser] = useState(false);
+ const [loading, setLoading] = useState(true);
+
+ useEffect(() => {
+ const unsubscribe = onAuthStateChanged(auth, initializeUser);
+ return unsubscribe;
+ }, []);
+
+ async function initializeUser(user) {
+ if (user) {
+
+ setCurrentUser({ ...user });
+
+ // check if provider is email and password login
+ const isEmail = user.providerData.some(
+ (provider) => provider.providerId === "password"
+ );
+ setIsEmailUser(isEmail);
+
+ // check if the auth provider is google or not
+ // const isGoogle = user.providerData.some(
+ // (provider) => provider.providerId === GoogleAuthProvider.PROVIDER_ID
+ // );
+ // setIsGoogleUser(isGoogle);
+
+ setUserLoggedIn(true);
+ } else {
+ setCurrentUser(null);
+ setUserLoggedIn(false);
+ }
+
+ setLoading(false);
+ }
+
+ const value = {
+ userLoggedIn,
+ isEmailUser,
+ isGoogleUser,
+ currentUser,
+ setCurrentUser
+ };
+
+ return (
+
+ {!loading && children}
+
+ );
+}
\ No newline at end of file
diff --git a/src/firebase/auth.js b/src/firebase/auth.js
new file mode 100644
index 0000000..925fd34
--- /dev/null
+++ b/src/firebase/auth.js
@@ -0,0 +1,44 @@
+import { auth } from "./firebase";
+import {
+ createUserWithEmailAndPassword,
+ signInWithEmailAndPassword,
+ sendPasswordResetEmail,
+ sendEmailVerification,
+ updatePassword,
+ signInWithPopup,
+ GoogleAuthProvider,
+} from "firebase/auth";
+
+export const doCreateUserWithEmailAndPassword = async (email, password) => {
+ return createUserWithEmailAndPassword(auth, email, password);
+};
+
+export const doSignInWithEmailAndPassword = (email, password) => {
+ return signInWithEmailAndPassword(auth, email, password);
+};
+
+export const doSignInWithGoogle = async () => {
+ const provider = new GoogleAuthProvider();
+ const result = await signInWithPopup(auth, provider);
+ const user = result.user;
+
+ // add user to firestore
+};
+
+export const doSignOut = () => {
+ return auth.signOut();
+};
+
+export const doPasswordReset = (email) => {
+ return sendPasswordResetEmail(auth, email);
+};
+
+export const doPasswordChange = (password) => {
+ return updatePassword(auth.currentUser, password);
+};
+
+export const doSendEmailVerification = () => {
+ return sendEmailVerification(auth.currentUser, {
+ url: `${window.location.origin}/home`,
+ });
+};
\ No newline at end of file
diff --git a/src/firebase/firebase.js b/src/firebase/firebase.js
new file mode 100644
index 0000000..0d4bf28
--- /dev/null
+++ b/src/firebase/firebase.js
@@ -0,0 +1,22 @@
+// Import the functions you need from the SDKs you need
+import { initializeApp } from "firebase/app";
+import { getAuth } from "firebase/auth"
+
+
+// Your web app's Firebase configuration
+// Create an accont on firebase and you get all this configuration just replace that with this
+// Then your sign-in / sign-up feature will work smothly
+const firebaseConfig = {
+ apiKey: "YOUR_API_KEY",
+ authDomain: "YOUR_AUTH_DOMAIN",
+ projectId: "PROJECT_ID",
+ storageBucket: "SOCKET_BUTTON",
+ messagingSenderId: "SENDER_ID",
+ appId: "APP_ID",
+ measurementId: "MEASUREMENT_ID"
+};
+
+// Initialize Firebase
+const app = initializeApp(firebaseConfig);
+const auth = getAuth(app);
+export { auth, app };
\ No newline at end of file
diff --git a/src/main.jsx b/src/main.jsx
index 0291fe5..491d31f 100755
--- a/src/main.jsx
+++ b/src/main.jsx
@@ -2,9 +2,12 @@ import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.jsx'
import './index.css'
+import { AuthProvider } from './contexts/authContext/index.jsx'
ReactDOM.createRoot(document.getElementById('root')).render(
-
+
+
+
,
)
\ No newline at end of file
From e9cfbdcef791eebfe0a88bf20b6e641c9cf04377 Mon Sep 17 00:00:00 2001
From: Adarsh
Date: Sat, 12 Oct 2024 19:53:27 +0530
Subject: [PATCH 7/7] Update greetings.yml
---
.github/workflows/greetings.yml | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml
index ff7fb64..355b95c 100644
--- a/.github/workflows/greetings.yml
+++ b/.github/workflows/greetings.yml
@@ -1,6 +1,10 @@
name: Greetings
-on: [pull_request_target, issues]
+on:
+ pull_request_target:
+ types: [opened, synchronized, reopened, closed]
+ issues:
+ types: [opened]
jobs:
greeting:
@@ -9,8 +13,26 @@ jobs:
issues: write
pull-requests: write
steps:
- - uses: actions/first-interaction@v1
+ - name: Greet on new issue
+ if: github.event_name == 'issues'
+ uses: actions/first-interaction@v1
with:
- repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: "👋 Thank you for raising an issue! We appreciate your effort in helping us improve. Our team will review it shortly. Stay tuned!"
- pr-message: " 🎉 Thank you for your contribution! Your pull request has been submitted successfully. A maintainer will review it as soon as possible. We appreciate your support in making this project better"
+
+ - name: Greet on new pull request
+ if: github.event_name == 'pull_request'
+ uses: actions/first-interaction@v1
+ with:
+ pr-message: "🎉 Thank you for your contribution! Your pull request has been submitted successfully. A maintainer will review it as soon as possible. We appreciate your support in making this project better."
+
+ - name: Congratulate on merged pull request
+ if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
+ run: |
+ echo "Congratulations to @${{ github.event.pull_request.user.login }} for merging your pull request! 🎉"
+ echo "If you enjoyed contributing, please consider giving us a star on GitHub and following us for updates!"
+ # Post a comment on the PR
+ curl -X POST \
+ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
+ -H "Accept: application/vnd.github.v3+json" \
+ https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \
+ -d "{\"body\": \"Congratulations @${{ github.event.pull_request.user.login }} for merging your pull request! 🎉 If you enjoyed contributing, please consider giving us a star on GitHub and following us for updates!\"}"