Merge pull request 'feature/properly-display-emails' (#13) from feature/properly-display-emails into master
Reviewed-on: #13
This commit is contained in:
commit
32cefda0a0
|
@ -1,6 +1,13 @@
|
|||
type IntendedUser = {
|
||||
name: string;
|
||||
emails: string[];
|
||||
emails: OAuthEmail[];
|
||||
username: string;
|
||||
};
|
||||
|
||||
type OAuthEmail = {
|
||||
email: string;
|
||||
primary: boolean;
|
||||
verified: boolean;
|
||||
};
|
||||
|
||||
type IntendedLink = {
|
||||
|
|
|
@ -20,6 +20,7 @@ type AuthPageProps = {
|
|||
service: string;
|
||||
recipient: string;
|
||||
user: IntendedUser | null;
|
||||
error: string;
|
||||
};
|
||||
|
||||
interface Keys {
|
||||
|
@ -40,6 +41,7 @@ const AuthPage = (props: AuthPageProps) => {
|
|||
const [secretFileUrl, setSecretFileUrl] = useState<string>("#");
|
||||
const [secretFileName, setSecretFileName] = useState<string>("");
|
||||
const [secretMessage, setSecretMessage] = useState<string>("Decrypting...");
|
||||
const [messageRevealed, setMessageRevealed] = useState<boolean>(false);
|
||||
|
||||
useEffect(() => {
|
||||
init().catch((reason) => {
|
||||
|
@ -47,6 +49,9 @@ const AuthPage = (props: AuthPageProps) => {
|
|||
});
|
||||
}, []);
|
||||
|
||||
const capitalize = (s: string) =>
|
||||
(s && s[0].toUpperCase() + s.slice(1)) || "";
|
||||
|
||||
const init = async (): Promise<void> => {
|
||||
const link: LinkFiles | null = await retrieveLink();
|
||||
const keys: Keys | null = await retrieveKeys();
|
||||
|
@ -55,6 +60,14 @@ const AuthPage = (props: AuthPageProps) => {
|
|||
}
|
||||
};
|
||||
|
||||
const userEmails = (): string[] => {
|
||||
return user
|
||||
? user.emails
|
||||
.filter((email) => email.verified)
|
||||
.map((email) => email.email)
|
||||
: [];
|
||||
};
|
||||
|
||||
const retrieveLink = async (): Promise<LinkFiles | null> => {
|
||||
const urlSegments = new URL(document.URL).pathname.split("/");
|
||||
const linkId = urlSegments.pop() || urlSegments.pop();
|
||||
|
@ -135,6 +148,7 @@ const AuthPage = (props: AuthPageProps) => {
|
|||
// And voila
|
||||
HexMix.arrayBufferToString(encodedText, (result: string) => {
|
||||
setSecretMessage(result);
|
||||
setMessageRevealed(true);
|
||||
});
|
||||
}
|
||||
if (link?.file) {
|
||||
|
@ -153,21 +167,57 @@ const AuthPage = (props: AuthPageProps) => {
|
|||
type: link.filetype ? link.filetype : "text/plain",
|
||||
});
|
||||
setSecretFileUrl(window.URL.createObjectURL(blob));
|
||||
setMessageRevealed(true);
|
||||
}
|
||||
};
|
||||
|
||||
const renderFooter = (): JSX.Element => {
|
||||
if (!user) return <div></div>;
|
||||
return (
|
||||
<Header3
|
||||
small
|
||||
style={{ color: "#CCCCCC", fontSize: "1.4rem", textAlign: "left" }}
|
||||
>
|
||||
Hello {user.name}, you are logged in to{" "}
|
||||
<span style={{ color: "#A849CF" }}>{capitalize(service)}</span> as{" "}
|
||||
<span style={{ color: "#32EFE7" }}>{user.username}</span>. This account
|
||||
has the following emails associated with it:
|
||||
<br />
|
||||
<br />
|
||||
<span style={{ color: "#32EFE7" }}>{userEmails().join(", ")}</span>
|
||||
<br />
|
||||
<br />
|
||||
The intended recipient for this message is{" "}
|
||||
<span style={{ color: "#32EFE7" }}>{recipient}</span> on{" "}
|
||||
<span style={{ color: "#A849CF" }}>{capitalize(service)}</span>. If you
|
||||
need to authenticate with a different account, you may do so by logging
|
||||
out and accessing this link again. It's also possible that you have yet
|
||||
to verify your email address on{" "}
|
||||
<span style={{ color: "#A849CF" }}>{capitalize(service)}</span>.
|
||||
</Header3>
|
||||
);
|
||||
};
|
||||
|
||||
const renderHeader = (): JSX.Element => {
|
||||
return (
|
||||
<div>
|
||||
<Header2 style={{ margin: ".4rem" }}>Someone sent you a secret</Header2>
|
||||
<Header2 style={{ margin: ".4rem" }}>
|
||||
{user ? "You have been identified!" : "Someone sent you a secret"}
|
||||
</Header2>
|
||||
{user ? (
|
||||
<Header3 small>
|
||||
Hello {user.name}, you are logged in {service} which has the
|
||||
following verified emails: {user.emails.join(", ")}
|
||||
{messageRevealed
|
||||
? "The following message and/or file is for your eyes only."
|
||||
: "Unfortunately, you are not the intended recipient."}
|
||||
|
||||
<br />
|
||||
<br />
|
||||
</Header3>
|
||||
) : (
|
||||
<Header3 small>
|
||||
Please verify your identity to reveal this message.
|
||||
The intended recipient for this message is {recipient} on{" "}
|
||||
{capitalize(service)}. Please verify your identity to reveal this
|
||||
message.
|
||||
</Header3>
|
||||
)}
|
||||
</div>
|
||||
|
@ -232,11 +282,13 @@ const AuthPage = (props: AuthPageProps) => {
|
|||
/>
|
||||
</a>
|
||||
<Spacer space="3rem" />
|
||||
<a href={`https://intended.link/auth/${service}`}>
|
||||
<a href={`https://intended.link/auth/logout`}>
|
||||
<Button variant="primary" wide onClick={() => {}}>
|
||||
Re-Verify
|
||||
Logout
|
||||
</Button>
|
||||
</a>
|
||||
<Spacer space="3rem" />
|
||||
{renderFooter()}
|
||||
</CenteredContainer>
|
||||
</CenteredContainer>
|
||||
);
|
||||
|
|
|
@ -1,8 +1,30 @@
|
|||
import React from "react";
|
||||
import React, { useEffect } from "react";
|
||||
|
||||
import { CenteredContainer, SplashIconHeader, Header1, Header3, Spacer, Button, GlobalStyle } from '@intended/intended-ui';
|
||||
import {
|
||||
CenteredContainer,
|
||||
SplashIconHeader,
|
||||
Header1,
|
||||
Header3,
|
||||
Spacer,
|
||||
Button,
|
||||
GlobalStyle,
|
||||
} from "@intended/intended-ui";
|
||||
|
||||
type SplashPageProps = {
|
||||
error: string;
|
||||
};
|
||||
|
||||
const SplashPage = (props: SplashPageProps) => {
|
||||
useEffect(() => {
|
||||
displayErrors();
|
||||
});
|
||||
|
||||
const displayErrors = () => {
|
||||
const { error } = props;
|
||||
|
||||
if (error) alert(error);
|
||||
};
|
||||
|
||||
const SplashPage = () => {
|
||||
return (
|
||||
<React.StrictMode>
|
||||
<GlobalStyle />
|
||||
|
@ -15,7 +37,11 @@ const SplashPage = () => {
|
|||
and secretly.
|
||||
</Header3>
|
||||
<Spacer />
|
||||
<Button variant="secondary" boldFont onClick={() => window.location.href = "/just"}>
|
||||
<Button
|
||||
variant="secondary"
|
||||
boldFont
|
||||
onClick={() => (window.location.href = "/just")}
|
||||
>
|
||||
START SHARING
|
||||
</Button>
|
||||
</CenteredContainer>
|
||||
|
|
|
@ -40,9 +40,9 @@ defmodule EntenduWeb.Router do
|
|||
scope "/auth", EntenduWeb do
|
||||
pipe_through :browser
|
||||
|
||||
get "/logout", AuthController, :delete
|
||||
get "/:provider", AuthController, :request
|
||||
get "/:provider/callback", AuthController, :callback
|
||||
delete "/logout", AuthController, :delete
|
||||
end
|
||||
|
||||
scope "/uploads", EntenduWeb do
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
<main role="main">
|
||||
<p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
|
||||
<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
|
||||
<%= @inner_content %>
|
||||
</main>
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
service: @intended_link.service,
|
||||
recipient: @intended_link.recipient,
|
||||
user: current_user(@conn),
|
||||
link: current_link(@conn)
|
||||
link: current_link(@conn),
|
||||
error: get_flash(@conn, :error)
|
||||
}) %>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<section>
|
||||
|
||||
<%= react_component("Components.SplashPage") %>
|
||||
<%= react_component("Components.SplashPage", %{ error: get_flash(@conn, :error) }) %>
|
||||
|
||||
<%= if @current_user do %>
|
||||
<h2>Welcome, <%= @current_user.name %>!</h2>
|
||||
|
|
Loading…
Reference in New Issue