Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: implement login/logout dialogs (#109)

Muhammad Ali1f455e45ba61
diff --git a/apps/web/src/components/dialogs/logindialog.js b/apps/web/src/components/dialogs/logindialog.js
index 49f43566e..08156e499 100644
--- a/apps/web/src/components/dialogs/logindialog.js
+++ b/apps/web/src/components/dialogs/logindialog.js
@@ -1,39 +1,90 @@
-import React from "react";
-import { Flex, Box, Button } from "rebass";
+import React, { useState } from "react";
+import { Flex, Box, Button, Text } from "rebass";
import { Input } from "@rebass/forms";
import * as Icon from "react-feather";
import Dialog, { showDialog } from "./dialog";
+import { showSignUpDialog } from "./signupdialog";
+import { db } from "../../common";
-const LoginDialog = props => (
- <Dialog
- isOpen={true}
- title={"Login"}
- icon={Icon.LogIn}
- onCloseClick={props.onClose}
- negativeButton={{ onClick: props.onClose }}
- positiveButton={{ text: "Login" }}
- content={
- <Box my={1}>
- <Input variant="default" placeholder="Email"></Input>
- <Input
- variant="default"
- placeholder="Password"
- sx={{ marginTop: 2 }}
- ></Input>
- <Flex
- flexDirection="row"
- justifyContent="space-between"
- sx={{ marginTop: 2 }}
- >
- <Button variant="links">Create a New Account</Button>
- <Button variant="links" alignItems="right">
- Forgot password?
- </Button>
- </Flex>
- </Box>
- }
- />
-);
+const LoginDialog = props => {
+ const [username, setUsername] = useState();
+ const [password, setPassword] = useState();
+ const [errorMessage, setErrorMessage] = useState();
+
+ return (
+ <Dialog
+ isOpen={true}
+ title={"Login"}
+ icon={Icon.LogIn}
+ onCloseClick={props.onClose}
+ negativeButton={{ onClick: props.onClose }}
+ positiveButton={{
+ text: "Login",
+ onClick: () => {
+ setErrorMessage();
+ if (username === "" || username === undefined) {
+ setErrorMessage("Please enter your username.");
+ return;
+ }
+
+ if (password === "" || password === undefined) {
+ setErrorMessage("Please enter your password.");
+ return;
+ }
+
+ db.user.login(username, password);
+ }
+ }}
+ content={
+ <Box my={1}>
+ <Input
+ variant="default"
+ placeholder="Username"
+ onChange={e => {
+ setUsername(e.target.value);
+ }}
+ ></Input>
+ <Input
+ type="password"
+ variant="default"
+ placeholder="Password"
+ sx={{ marginTop: 2 }}
+ onChange={e => {
+ setPassword(e.target.value);
+ }}
+ ></Input>
+ <Flex
+ flexDirection="row"
+ justifyContent="space-between"
+ sx={{ marginTop: 2 }}
+ >
+ <Button
+ variant="links"
+ onClick={() => {
+ showSignUpDialog();
+ }}
+ >
+ Create a New Account
+ </Button>
+ </Flex>
+ <Flex
+ flexDirection="row"
+ justifyContent="space-between"
+ sx={{ marginTop: errorMessage ? 2 : 0 }}
+ >
+ <Text
+ fontSize="subBody"
+ color="red"
+ sx={{ display: errorMessage ? "flex" : "none" }}
+ >
+ {errorMessage}
+ </Text>
+ </Flex>
+ </Box>
+ }
+ />
+ );
+};
export const showLogInDialog = () => {
return showDialog(perform => <LoginDialog onClose={() => perform(false)} />);
diff --git a/apps/web/src/components/dialogs/signupdialog.js b/apps/web/src/components/dialogs/signupdialog.js
new file mode 100644
index 000000000..1c4de0ee2
--- /dev/null
+++ b/apps/web/src/components/dialogs/signupdialog.js
@@ -0,0 +1,104 @@
+import React, { useState } from "react";
+import { Flex, Box, Text } from "rebass";
+import { Input } from "@rebass/forms";
+import * as Icon from "react-feather";
+import Dialog, { showDialog } from "./dialog";
+import { db } from "../../common";
+
+const SignUpDialog = props => {
+ const [username, setUserName] = useState();
+ const [email, setEmail] = useState();
+ const [password, setPassword] = useState();
+ const [confirmPassword, setConfirmPassword] = useState();
+ const [errorMessage, setErrorMessage] = useState();
+ return (
+ <Dialog
+ isOpen={true}
+ title={"Sign Up"}
+ icon={Icon.LogIn}
+ onCloseClick={props.onClose}
+ negativeButton={{ onClick: props.onClose }}
+ positiveButton={{
+ text: "Sign Up",
+ onClick: () => {
+ setErrorMessage();
+
+ if (username === "" || username === undefined) {
+ setErrorMessage("Please enter your username.");
+ return;
+ }
+
+ if (email === "" || email === undefined) {
+ setErrorMessage("Please enter your email address.");
+ return;
+ }
+
+ if (password !== confirmPassword) {
+ setErrorMessage("Passwords do not match! Please try again.");
+ return;
+ }
+
+ if (password === undefined || password === "") {
+ setErrorMessage("Please enter password.");
+ return;
+ }
+
+ db.user.signup(username, email, password);
+ }
+ }}
+ content={
+ <Box my={1}>
+ <Input
+ variant="default"
+ placeholder="Username"
+ onChange={e => {
+ setUserName(e.target.value);
+ }}
+ ></Input>
+ <Input
+ variant="default"
+ placeholder="Email"
+ onChange={e => {
+ setEmail(e.target.value);
+ }}
+ ></Input>
+ <Input
+ type="password"
+ variant="default"
+ placeholder="Password"
+ sx={{ marginTop: 2 }}
+ onChange={e => {
+ setPassword(e.target.value);
+ }}
+ ></Input>
+ <Input
+ type="password"
+ variant="default"
+ placeholder="Confirm Password"
+ sx={{ marginTop: 2 }}
+ onChange={e => {
+ setConfirmPassword(e.target.value);
+ }}
+ ></Input>
+ <Flex
+ flexDirection="row"
+ justifyContent="space-between"
+ sx={{ marginTop: 2 }}
+ >
+ <Text
+ fontSize="subBody"
+ color="red"
+ sx={{ display: errorMessage ? "flex" : "none" }}
+ >
+ {errorMessage}
+ </Text>
+ </Flex>
+ </Box>
+ }
+ />
+ );
+};
+
+export const showSignUpDialog = () => {
+ return showDialog(perform => <SignUpDialog onClose={() => perform(false)} />);
+};