gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: Add route history functionaltiy and au


From: gnunet
Subject: [libeufin] branch master updated: Add route history functionaltiy and auth actions
Date: Thu, 04 Jun 2020 19:15:41 +0200

This is an automated email from the git hooks/post-receive script.

heng-yeow pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 456081d  Add route history functionaltiy and auth actions
456081d is described below

commit 456081d2c53364876175e8d5363b87a62397094e
Author: tanhengyeow <E0032242@u.nus.edu>
AuthorDate: Fri Jun 5 01:15:28 2020 +0800

    Add route history functionaltiy and auth actions
---
 frontend/src/actions/auth.tsx | 73 +++++++++++++++++++++++++++++++++++++++++++
 frontend/src/history.tsx      | 12 +++++++
 frontend/src/import-png.d.ts  |  4 +++
 3 files changed, 89 insertions(+)

diff --git a/frontend/src/actions/auth.tsx b/frontend/src/actions/auth.tsx
new file mode 100644
index 0000000..80964fb
--- /dev/null
+++ b/frontend/src/actions/auth.tsx
@@ -0,0 +1,73 @@
+/* eslint-disable @typescript-eslint/no-explicit-any */
+import { ThunkDispatch as Dispatch } from 'redux-thunk';
+import { Base64 } from 'js-base64';
+import * as constants from '../constants';
+
+export interface Authenticate {
+  type: constants.AUTHENTICATE;
+}
+const authenticate = (): Authenticate => {
+  return {
+    type: constants.AUTHENTICATE,
+  };
+};
+
+export interface Unauthenticate {
+  type: constants.UNAUTHENTICATE;
+}
+const unauthenticate = (): Unauthenticate => {
+  return {
+    type: constants.UNAUTHENTICATE,
+  };
+};
+
+export type AuthenticationAction = Authenticate | Unauthenticate;
+
+export const login = (nexusURL: string, username: string, password: string) => 
{
+  return async (dispatch: Dispatch<AuthenticationAction, {}, any>) => {
+    if (nexusURL && username && password) {
+      await fetch(`/user`, {
+        headers: new Headers({
+          Authorization: `Basic ${Base64.encode(`${username}:${password}`)}`,
+        }),
+      })
+        .then((response) => {
+          if (response.ok) {
+            return response.json();
+          }
+          throw new Error('Error connecting to server');
+        })
+        .then(async () => {
+          await window.localStorage.setItem('authenticated', 'true');
+          await window.localStorage.setItem(
+            'authHeader',
+            `${Base64.encode(`${username}:${password}`)}`
+          );
+          dispatch(authenticate());
+        })
+        .catch((err) => {
+          console.log(err);
+        });
+    }
+  };
+};
+export const logout = () => {
+  return async (dispatch: Dispatch<AuthenticationAction, {}, any>) => {
+    await window.localStorage.setItem('authenticated', 'false');
+    await window.localStorage.setItem('authHeader', '');
+    dispatch(unauthenticate());
+  };
+};
+
+export const checkAuthentication = () => {
+  return async (dispatch: Dispatch<AuthenticationAction, {}, any>) => {
+    const auth = await window.localStorage.getItem('authenticated');
+    const formattedAuth = typeof auth === 'string' ? JSON.parse(auth) : null;
+
+    if (formattedAuth) {
+      dispatch(authenticate());
+    } else {
+      dispatch(unauthenticate());
+    }
+  };
+};
diff --git a/frontend/src/history.tsx b/frontend/src/history.tsx
new file mode 100644
index 0000000..0f33a2b
--- /dev/null
+++ b/frontend/src/history.tsx
@@ -0,0 +1,12 @@
+/* eslint-disable @typescript-eslint/no-explicit-any */
+import { createBrowserHistory } from 'history';
+
+declare global {
+  interface Window {
+    dataLayer: any;
+  }
+}
+
+const history = createBrowserHistory();
+
+export default history;
diff --git a/frontend/src/import-png.d.ts b/frontend/src/import-png.d.ts
new file mode 100644
index 0000000..0935dbb
--- /dev/null
+++ b/frontend/src/import-png.d.ts
@@ -0,0 +1,4 @@
+declare module '*.png' {
+  const value: any;
+  export default value;
+}

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]