@maka/maka-cli 4.10.2 → 4.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/obf/package.json +1 -1
- package/bundle/obf/src/command.js +1 -1
- package/bundle/obf/src/commands/_index.js +1 -1
- package/bundle/obf/src/commands/ai.js +1 -1
- package/bundle/obf/src/commands/aws/_index.js +1 -1
- package/bundle/obf/src/commands/aws/aws.command.js +1 -1
- package/bundle/obf/src/commands/aws/chz.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/aws/ci.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/aws/ckp.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/aws/csg.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/aws/di.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/aws/dkp.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/aws/dsg.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/aws/rbi.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/aws/rdn.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/aws/rkp.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/aws/sth.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/aws/ti.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/build/_index.js +1 -1
- package/bundle/obf/src/commands/build/build.js +1 -1
- package/bundle/obf/src/commands/build/docker.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/create.js +1 -1
- package/bundle/obf/src/commands/debug.js +1 -1
- package/bundle/obf/src/commands/deploy/_index.js +1 -1
- package/bundle/obf/src/commands/deploy/deploy.command.js +1 -1
- package/bundle/obf/src/commands/deploy/galaxy.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/deploy/ubuntu.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/game/_index.js +1 -1
- package/bundle/obf/src/commands/game/battleship.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/game/play.command.js +1 -1
- package/bundle/obf/src/commands/game/pong.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/commands/command.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/commands/drop.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/commands/equip.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/commands/go.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/commands/lock.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/commands/look.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/commands/say.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/commands/search.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/commands/solve.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/commands/take.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/commands/unequip.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/commands/unlock.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/commands/use.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/factories/commandF.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/factories/roomsF.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/game.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/models/_index.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/models/door.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/models/inventory.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/models/item.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/models/npc.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/models/player.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/models/puzzle.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/models/room.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/models/scene.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/scenes/items.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/scenes/rooms.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/types/abstracts.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/types/enums.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/types/interfaces.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/types/types.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/ui.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest/utilities/logger.js +1 -1
- package/bundle/obf/src/commands/game/sideQuest.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/game/snake.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/game/tetris.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/generate.js +1 -1
- package/bundle/obf/src/commands/get/_index.js +1 -1
- package/bundle/obf/src/commands/get/get.command.js +1 -1
- package/bundle/obf/src/commands/get/global.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/get/local.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/get/whoami.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/help.js +1 -1
- package/bundle/obf/src/commands/install.js +1 -1
- package/bundle/obf/src/commands/jsdoc.js +1 -1
- package/bundle/obf/src/commands/lint.js +1 -1
- package/bundle/obf/src/commands/login.js +1 -1
- package/bundle/obf/src/commands/logout.js +1 -1
- package/bundle/obf/src/commands/logs.js +1 -1
- package/bundle/obf/src/commands/maka.cmd.js +1 -1
- package/bundle/obf/src/commands/murder.js +1 -1
- package/bundle/obf/src/commands/patreon.js +1 -1
- package/bundle/obf/src/commands/proxy.js +1 -1
- package/bundle/obf/src/commands/reconfig.js +1 -1
- package/bundle/obf/src/commands/register.js +1 -1
- package/bundle/obf/src/commands/run/_index.js +1 -1
- package/bundle/obf/src/commands/run/docker.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/run/run.command.js +1 -1
- package/bundle/obf/src/commands/set/_index.js +1 -1
- package/bundle/obf/src/commands/set/global.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/set/local.sub.cmd.js +1 -1
- package/bundle/obf/src/commands/set/set.command.js +1 -1
- package/bundle/obf/src/commands/ssh.js +1 -1
- package/bundle/obf/src/commands/ssl.js +1 -1
- package/bundle/obf/src/commands/test.js +1 -1
- package/bundle/obf/src/commands/undo.js +1 -1
- package/bundle/obf/src/commands/version.js +1 -1
- package/bundle/obf/src/error.js +1 -1
- package/bundle/obf/src/exec.js +1 -1
- package/bundle/obf/src/generator.js +1 -1
- package/bundle/obf/src/generators/_index.js +1 -1
- package/bundle/obf/src/generators/api.js +1 -1
- package/bundle/obf/src/generators/collection.js +1 -1
- package/bundle/obf/src/generators/component.js +1 -1
- package/bundle/obf/src/generators/config.js +1 -1
- package/bundle/obf/src/generators/dbc.js +1 -1
- package/bundle/obf/src/generators/dockerfile.js +1 -1
- package/bundle/obf/src/generators/hook.js +1 -1
- package/bundle/obf/src/generators/kits/_index.js +1 -1
- package/bundle/obf/src/generators/kits/auth/_index.js +1 -0
- package/bundle/obf/src/generators/kits/auth/auth.generator.js +1 -0
- package/bundle/obf/src/generators/kits/auth/basic-meteor.auth.gen.js +1 -0
- package/bundle/obf/src/generators/kits/auth/provider.auth.gen.js +1 -0
- package/bundle/obf/src/generators/kits/esri/_index.js +1 -1
- package/bundle/obf/src/generators/kits/esri/esri.generator.js +1 -1
- package/bundle/obf/src/generators/kits/esri/map.esri.gen.js +1 -1
- package/bundle/obf/src/generators/kits/kit.js +1 -1
- package/bundle/obf/src/generators/kits/mui/_index.js +1 -1
- package/bundle/obf/src/generators/kits/mui/auth.mui.gen.js +1 -0
- package/bundle/obf/src/generators/kits/mui/frame.mui.gen.js +1 -1
- package/bundle/obf/src/generators/kits/mui/mui.generator.js +1 -1
- package/bundle/obf/src/generators/layout.js +1 -1
- package/bundle/obf/src/generators/maka.gen.js +1 -1
- package/bundle/obf/src/generators/methods.js +1 -1
- package/bundle/obf/src/generators/package.js +1 -1
- package/bundle/obf/src/generators/page.js +1 -1
- package/bundle/obf/src/generators/publish.js +1 -1
- package/bundle/obf/src/generators/route.js +1 -1
- package/bundle/obf/src/generators/service.js +1 -1
- package/bundle/obf/src/generators/services/_index.js +1 -1
- package/bundle/obf/src/generators/services/openssl.js +1 -1
- package/bundle/obf/src/generators/services/translation.js +1 -1
- package/bundle/obf/src/maka.js +1 -1
- package/bundle/obf/src/templates/meteor/app/client/head.html +0 -3
- package/bundle/obf/src/templates/meteor/app/client/main.js +2 -0
- package/bundle/obf/src/templates/meteor/app/client/main.js.jsx +2 -0
- package/bundle/obf/src/templates/meteor/app/client/main.js.ts +2 -0
- package/bundle/obf/src/templates/meteor/app/client/main.js.tsx +2 -0
- package/bundle/obf/src/templates/meteor/app/imports/startup/client/index.js.jsx +5 -6
- package/bundle/obf/src/templates/meteor/app/imports/startup/client/index.js.tsx +5 -6
- package/bundle/obf/src/templates/meteor/app/imports/startup/client/routes.js.jsx +4 -3
- package/bundle/obf/src/templates/meteor/app/imports/startup/client/routes.js.tsx +4 -3
- package/bundle/obf/src/templates/meteor/app/imports/startup/lib/index.js.jsx +2 -2
- package/bundle/obf/src/templates/meteor/app/imports/startup/lib/index.js.tsx +2 -2
- package/bundle/obf/src/templates/meteor/app/imports/startup/lib/routes.js.jsx +4 -3
- package/bundle/obf/src/templates/meteor/app/imports/startup/lib/routes.js.tsx +4 -3
- package/bundle/obf/src/templates/meteor/app/imports/startup/server/index.js.jsx +1 -1
- package/bundle/obf/src/templates/meteor/app/imports/startup/server/index.js.tsx +1 -1
- package/bundle/obf/src/templates/meteor/app/lib/main.js +2 -0
- package/bundle/obf/src/templates/meteor/app/lib/main.js.jsx +2 -0
- package/bundle/obf/src/templates/meteor/app/lib/main.js.ts +2 -0
- package/bundle/obf/src/templates/meteor/app/lib/main.js.tsx +2 -0
- package/bundle/obf/src/templates/meteor/app/server/main.js +2 -0
- package/bundle/obf/src/templates/meteor/app/server/main.js.jsx +2 -0
- package/bundle/obf/src/templates/meteor/app/server/main.js.ts +2 -0
- package/bundle/obf/src/templates/meteor/app/server/main.js.tsx +2 -0
- package/bundle/obf/src/templates/meteor/config/settings.json +1 -1
- package/bundle/obf/src/templates/meteor/publish/publish.js +2 -2
- package/bundle/obf/src/templates/meteor/publish/publish.js.ts +3 -0
- package/bundle/obf/src/templates/react/kit/auth/provider/authentication-provider.js.jsx +281 -0
- package/bundle/obf/src/templates/react/kit/auth/provider/authentication-provider.js.tsx +318 -0
- package/bundle/obf/src/templates/react/kit/auth/service/meteor-auth-service.js.jsx +136 -0
- package/bundle/obf/src/templates/react/kit/auth/service/meteor-auth-service.js.tsx +136 -0
- package/bundle/obf/src/templates/react/kit/esri/map/basic-map.js.jsx +4 -2
- package/bundle/obf/src/templates/react/kit/esri/map/basic-map.js.tsx +5 -3
- package/bundle/obf/src/templates/react/kit/mui/auth/forgot-password/basic-forgot-password-page.js.jsx +32 -0
- package/bundle/obf/src/templates/react/kit/mui/auth/forgot-password/basic-forgot-password-page.js.tsx +31 -0
- package/bundle/obf/src/templates/react/kit/mui/auth/login/basic-login-page.js.jsx +51 -0
- package/bundle/obf/src/templates/react/kit/mui/auth/login/basic-login-page.js.tsx +52 -0
- package/bundle/obf/src/templates/react/kit/mui/auth/logout/basic-logout-page.js.jsx +24 -0
- package/bundle/obf/src/templates/react/kit/mui/auth/logout/basic-logout-page.js.tsx +24 -0
- package/bundle/obf/src/templates/react/kit/mui/auth/password-reset/basic-password-reset-page.js.jsx +34 -0
- package/bundle/obf/src/templates/react/kit/mui/auth/password-reset/basic-password-reset-page.js.tsx +34 -0
- package/bundle/obf/src/templates/react/kit/mui/auth/register/basic-register-page.js.jsx +32 -0
- package/bundle/obf/src/templates/react/kit/mui/auth/register/basic-register-page.js.tsx +32 -0
- package/bundle/obf/src/templates/react/kit/mui/frame/app-bars/basic-app-bar.js.jsx +5 -5
- package/bundle/obf/src/templates/react/kit/mui/frame/app-bars/basic-app-bar.js.tsx +4 -3
- package/bundle/obf/src/templates/react/kit/mui/frame/drawers/basic-drawer.js.jsx +7 -4
- package/bundle/obf/src/templates/react/kit/mui/frame/drawers/basic-drawer.js.tsx +5 -4
- package/bundle/obf/src/templates/react/kit/mui/frame/footers/basic-sticky-footer.js.jsx +41 -0
- package/bundle/obf/src/templates/react/kit/mui/frame/footers/basic-sticky-footer.js.tsx +41 -0
- package/bundle/obf/src/templates/service/eslint/eslintrc.json +22 -1
- package/bundle/obf/src/tool.js +1 -1
- package/bundle/obf/src/tools/actions/actions.class.js +1 -1
- package/bundle/obf/src/tools/aws/aws.class.js +1 -1
- package/bundle/obf/src/tools/aws/aws.interfaces.js +1 -1
- package/bundle/obf/src/tools/docker/docker.class.js +1 -1
- package/bundle/obf/src/tools/docker/docker.interfaces.js +1 -1
- package/bundle/obf/src/tools/fsi/fsi.class.js +1 -1
- package/bundle/obf/src/tools/fsi/fsi.interfaces.js +1 -1
- package/bundle/obf/src/tools/https/https.class.js +1 -1
- package/bundle/obf/src/tools/https/https.interface.js +1 -1
- package/bundle/obf/src/tools/log/log.class.js +1 -1
- package/bundle/obf/src/tools/log/log.interfaces.js +1 -1
- package/bundle/obf/src/tools/options/options.class.js +1 -1
- package/bundle/obf/src/tools/progress/progress.class.js +1 -1
- package/bundle/obf/src/tools/spawn-async/spawn-async.class.js +1 -1
- package/bundle/obf/src/tools/spawn-async/spawn-async.interfaces.js +1 -1
- package/bundle/obf/src/tools/ssh/ssh.class.js +1 -1
- package/bundle/obf/src/tools/ssh/ssh.interfaces.js +1 -1
- package/bundle/obf/src/tools/ssl/ssl.class.js +1 -1
- package/package.json +1 -1
- package/bundle/obf/src/templates/meteor/publish/publish.js.jsx +0 -3
- package/bundle/obf/src/templates/meteor/publish/publish.js.tsx +0 -3
- package/bundle/obf/src/templates/meteor/publish/publish.ts +0 -3
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { Meteor } from 'meteor/meteor';
|
|
2
|
+
import React, { createContext, useState, useEffect, ReactNode, useMemo } from 'react';
|
|
3
|
+
import { Alert } from '@mui/material';
|
|
4
|
+
|
|
5
|
+
// Define types for user and credentials
|
|
6
|
+
// These are just placeholders to demonstrate the concept.
|
|
7
|
+
// TODO: Define a user for your application
|
|
8
|
+
interface User {
|
|
9
|
+
name: string;
|
|
10
|
+
id: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface Credentials {
|
|
14
|
+
username?: string;
|
|
15
|
+
password?: string;
|
|
16
|
+
token?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Define type for the AuthProvider's props
|
|
20
|
+
interface AuthProviderProps {
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
timeoutDuration?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Authorization Context
|
|
26
|
+
export const AuthContext = createContext<{
|
|
27
|
+
currentUser: User | null;
|
|
28
|
+
userAuthorizations: string[];
|
|
29
|
+
login: (credentials: Credentials) => Promise<void>;
|
|
30
|
+
logout: () => void;
|
|
31
|
+
loading: boolean;
|
|
32
|
+
} | null>({});
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Maka-CLI will replace the contents of these functions with
|
|
36
|
+
* a template that you can customize to fit your application's needs.
|
|
37
|
+
*/
|
|
38
|
+
const authenticateUser = async (username: string, password: string): Promise<User> => {
|
|
39
|
+
// Replace these with your actual authentication logic
|
|
40
|
+
// and define what constitutes as a valid user and permissions.
|
|
41
|
+
// These are just placeholders to demonstrate the concept.
|
|
42
|
+
|
|
43
|
+
// TODO: Remove this once you've implemented your own authentication logic
|
|
44
|
+
if (Meteor.isProduction) {
|
|
45
|
+
throw new Error('You must implement your own authentication logic');
|
|
46
|
+
}
|
|
47
|
+
// Simulated user authentication
|
|
48
|
+
// Replace with API call or other logic
|
|
49
|
+
if (username === 'test' && password === 'password') {
|
|
50
|
+
localStorage.setItem('token', 'valid-token');
|
|
51
|
+
return { name: 'Test User', id: '12345' };
|
|
52
|
+
}
|
|
53
|
+
throw new Error('Invalid credentials');
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const authenticateToken = async (): Promise<User> => {
|
|
57
|
+
// TODO: Remove this once you've implemented your own authentication logic
|
|
58
|
+
if (Meteor.isProduction) {
|
|
59
|
+
throw new Error('You must implement your own authentication logic');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// A token should either already exist as a result of the login process
|
|
63
|
+
// or another sso style login
|
|
64
|
+
const token = localStorage.getItem('token');
|
|
65
|
+
// Simulated token validation
|
|
66
|
+
// Replace with token validation logic
|
|
67
|
+
//
|
|
68
|
+
// Note: This is a very basic example of token validation.
|
|
69
|
+
// You should add additional logic to validate the token
|
|
70
|
+
// as well as handle token expiration, renewal, etc.
|
|
71
|
+
if (token === 'valid-token') {
|
|
72
|
+
return { name: 'Token User', id: '67890' };
|
|
73
|
+
}
|
|
74
|
+
throw new Error('Invalid token');
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const getUserAuthorizations = async (user: User): Promise<string[]> => {
|
|
78
|
+
// Placeholder function to simulate fetching user permissions
|
|
79
|
+
|
|
80
|
+
// TODO: Remove this once you've implemented your own authentication logic
|
|
81
|
+
if (Meteor.isProduction) {
|
|
82
|
+
throw new Error('You must implement your own permission logic');
|
|
83
|
+
}
|
|
84
|
+
// Simulate an API call to fetch permissions, or other logic
|
|
85
|
+
// such as parsing a JWT token to retrieve permissions
|
|
86
|
+
// Replace with your actual logic
|
|
87
|
+
if (user.id === '12345') {
|
|
88
|
+
return ['read', 'write', 'edit'];
|
|
89
|
+
}
|
|
90
|
+
return [];
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const deauthenticateUser = async (): Promise<boolean> => {
|
|
94
|
+
// Placeholder function to simulate deauthorizing a user
|
|
95
|
+
// TODO: Remove this once you've implemented your own authentication logic
|
|
96
|
+
if (Meteor.isProduction) {
|
|
97
|
+
throw new Error('You must implement your own deauthorization logic');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Simulate an API call to deauthorize a user
|
|
101
|
+
// Replace with your actual logic
|
|
102
|
+
// Note: This is a very basic example of deauthorization.
|
|
103
|
+
// You should add additional logic to deauthorize the user
|
|
104
|
+
// and handle any errors that may occur.
|
|
105
|
+
return true;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const sendForgotPasswordEmail = async (email: string) => {
|
|
109
|
+
// Placeholder function to simulate sending a password reset email
|
|
110
|
+
// TODO: Remove this once you've implemented your own authentication logic
|
|
111
|
+
if (Meteor.isProduction) {
|
|
112
|
+
throw new Error('You must implement your own send forgot email logic');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Simulate an API call to send a password reset email
|
|
116
|
+
// Replace with your actual logic
|
|
117
|
+
// Note: This is a very basic example of sending a password reset email.
|
|
118
|
+
// You should add additional logic to send the email
|
|
119
|
+
// and handle any errors that may occur.
|
|
120
|
+
console.log(`Sending password reset email to ${email}`);
|
|
121
|
+
return true;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const registerNewUser = async (email: string, password: string) => {
|
|
125
|
+
// Placeholder function to simulate registering a new user
|
|
126
|
+
// TODO: Remove this once you've implemented your own authentication logic
|
|
127
|
+
if (Meteor.isProduction) {
|
|
128
|
+
throw new Error('You must implement your own registration logic');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
console.log(`Registering new user with email ${email}`);
|
|
132
|
+
console.log(`Registering new user with password ${password.length} characters`);
|
|
133
|
+
return true;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const resetPasswordWithToken = async (token: string, password: string) => {
|
|
137
|
+
// Placeholder function to simulate resetting a password with a token
|
|
138
|
+
// TODO: Remove this once you've implemented your own authentication logic
|
|
139
|
+
if (Meteor.isProduction) {
|
|
140
|
+
throw new Error('You must implement your own password reset logic');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
console.log(`Resetting password with token ${token}`);
|
|
144
|
+
console.log(`Resetting password with password ${password.length} characters`);
|
|
145
|
+
return true;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
// Authorization Provider
|
|
150
|
+
export const AuthProvider = ({ children, timeoutDuration = 3600000 }: AuthProviderProps) => {
|
|
151
|
+
const [currentUser, setCurrentUser] = useState<User | null>(null);
|
|
152
|
+
const [userAuthorizations, setUserAuthorizations] = useState<string[]>([]);
|
|
153
|
+
const [loading, setLoading] = useState<boolean>(true);
|
|
154
|
+
const [alert, setAlert] = useState({ show: false, message: '', severity: '' });
|
|
155
|
+
|
|
156
|
+
const setAlertMessage = (message: string, severity: string) => {
|
|
157
|
+
setAlert({ show: true, message, severity });
|
|
158
|
+
setTimeout(() => setAlert({ show: false, message: '', severity: '' }), 5000); // Auto-hide after 5 seconds
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const logout = async () => {
|
|
162
|
+
try {
|
|
163
|
+
if (currentUser) {
|
|
164
|
+
await deauthenticateUser();
|
|
165
|
+
setCurrentUser(null);
|
|
166
|
+
setLoading(false);
|
|
167
|
+
setAlertMessage('Logout successful!', 'success');
|
|
168
|
+
}
|
|
169
|
+
} catch (error) {
|
|
170
|
+
setAlertMessage('Logout failed: ' + error.message, 'error');
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const loginUserWithUsernameAndPassword = async (username: string, password: string) => {
|
|
175
|
+
// Add logic for username/password authentication
|
|
176
|
+
// E.g., call a backend API and validate the credentials
|
|
177
|
+
try {
|
|
178
|
+
const user = await authenticateUser(username, password);
|
|
179
|
+
setCurrentUser(user);
|
|
180
|
+
setLoading(false);
|
|
181
|
+
setAlertMessage('Login successful!', 'success');
|
|
182
|
+
return user;
|
|
183
|
+
} catch (error) {
|
|
184
|
+
setLoading(false);
|
|
185
|
+
setCurrentUser(null);
|
|
186
|
+
setAlertMessage('Login failed: ' + error.message, 'error');
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const login = async (credentials: Credentials) => {
|
|
192
|
+
// Check the type of credentials provided and call the appropriate method
|
|
193
|
+
if (credentials.username && credentials.password) {
|
|
194
|
+
// Handle username/password authentication
|
|
195
|
+
return loginUserWithUsernameAndPassword(credentials.username, credentials.password);
|
|
196
|
+
} else {
|
|
197
|
+
setLoading(false);
|
|
198
|
+
throw new Error('Invalid login credentials');
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const loginUserWithToken = async () => {
|
|
203
|
+
// Add logic for token-based authentication
|
|
204
|
+
// E.g., validate the token with your backend or a third-party service
|
|
205
|
+
try {
|
|
206
|
+
const user = await authenticateToken();
|
|
207
|
+
setCurrentUser(user);
|
|
208
|
+
setLoading(false);
|
|
209
|
+
return user;
|
|
210
|
+
} catch (error) {
|
|
211
|
+
setLoading(false);
|
|
212
|
+
setCurrentUser(null);
|
|
213
|
+
setAlertMessage('Login failed: ' + error.message, 'error');
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const fetchUserAuthorizations = async (user: User) => {
|
|
219
|
+
// Placeholder function to fetch user permissions
|
|
220
|
+
// Replace this with your actual logic to retrieve permissions
|
|
221
|
+
const authorizations = await getUserAuthorizations(user);
|
|
222
|
+
setUserAuthorizations(authorizations);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const forgotPassword = async (email: string) => {
|
|
226
|
+
try {
|
|
227
|
+
await sendForgotPasswordEmail(email);
|
|
228
|
+
setAlertMessage('Please check your email.', 'success');
|
|
229
|
+
return true;
|
|
230
|
+
} catch (error) {
|
|
231
|
+
setAlertMessage('Error sending email: ' + error.message, 'error');
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const register = async (email: string, password: string) => {
|
|
237
|
+
try {
|
|
238
|
+
const user = await registerNewUser(email, password);
|
|
239
|
+
setCurrentUser(user);
|
|
240
|
+
fetchUserAuthorizations(user); // Fetch permissions when a user logs in
|
|
241
|
+
setAlertMessage('Registration sucess, welcome!', 'success');
|
|
242
|
+
setLoading(false);
|
|
243
|
+
return user;
|
|
244
|
+
} catch (error) {
|
|
245
|
+
setAlertMessage('Register failed: ' + error.message, 'error');
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const resetPassword = async (token, password) => {
|
|
251
|
+
try {
|
|
252
|
+
const user = await resetPasswordWithToken(token, password);
|
|
253
|
+
setCurrentUser(user);
|
|
254
|
+
fetchUserAuthorizations(user); // Fetch permissions when a user logs in
|
|
255
|
+
setAlertMessage('Password reset!', 'success');
|
|
256
|
+
setLoading(false);
|
|
257
|
+
return true;
|
|
258
|
+
} catch (error) {
|
|
259
|
+
setAlertMessage('Password reset failed: ' + error.message, 'error');
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
let logoutTimer: NodeJS.Timeout;
|
|
266
|
+
|
|
267
|
+
const setLogoutTimer = () => {
|
|
268
|
+
if (logoutTimer) {
|
|
269
|
+
clearTimeout(logoutTimer);
|
|
270
|
+
}
|
|
271
|
+
logoutTimer = setTimeout(logout, timeoutDuration);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
if (currentUser) {
|
|
275
|
+
setLogoutTimer();
|
|
276
|
+
fetchUserAuthorizations(currentUser); // Fetch permissions when a user logs in
|
|
277
|
+
} else {
|
|
278
|
+
setLoading(true);
|
|
279
|
+
// attempt to re-authenticate the user
|
|
280
|
+
const renewedUser = loginUserWithToken();
|
|
281
|
+
if (currentUser) {
|
|
282
|
+
setCurrentUser(renewedUser);
|
|
283
|
+
setLogoutTimer();
|
|
284
|
+
fetchUserAuthorizations(renewedUser); // Fetch permissions when a user logs in
|
|
285
|
+
} else {
|
|
286
|
+
setUserAuthorizations([]); // Clear permissions when logged out
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return () => {
|
|
291
|
+
clearTimeout(logoutTimer);
|
|
292
|
+
};
|
|
293
|
+
}, [currentUser, timeoutDuration]);
|
|
294
|
+
|
|
295
|
+
const contextValue = useMemo(() => ({
|
|
296
|
+
currentUser,
|
|
297
|
+
userAuthorizations,
|
|
298
|
+
login,
|
|
299
|
+
logout,
|
|
300
|
+
loading,
|
|
301
|
+
forgotPassword,
|
|
302
|
+
resetPassword,
|
|
303
|
+
register,
|
|
304
|
+
}), [currentUser, userAuthorizations, login, logout, loading, forgotPassword, resetPassword, register]);
|
|
305
|
+
|
|
306
|
+
return (
|
|
307
|
+
<AuthContext.Provider value={contextValue}>
|
|
308
|
+
{alert.show && (
|
|
309
|
+
<Alert severity={alert.severity} style={{ position: 'fixed', bottom: 20, right: 20, zIndex: 100000 }}>
|
|
310
|
+
{alert.message}
|
|
311
|
+
</Alert>
|
|
312
|
+
)}
|
|
313
|
+
{children}
|
|
314
|
+
</AuthContext.Provider>
|
|
315
|
+
);
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Meteor } from 'meteor/meteor';
|
|
2
|
+
import { Roles } from 'meteor/alanning:roles';
|
|
3
|
+
import { Accounts } from 'meteor/accounts-base';
|
|
4
|
+
|
|
5
|
+
class AuthService {
|
|
6
|
+
static getUserQuerySelector(username) {
|
|
7
|
+
// if the username is an email address, use the email field
|
|
8
|
+
if (username.indexOf('@') > -1) {
|
|
9
|
+
return { email: username };
|
|
10
|
+
} else {
|
|
11
|
+
return { username };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static async authenticateUser(username, password) {
|
|
16
|
+
// Implement Meteor-specific login logic
|
|
17
|
+
try {
|
|
18
|
+
const selector = AuthService.getUserQuerySelector(username);
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
Meteor.loginWithPassword(selector, password, (error) => {
|
|
21
|
+
if (error) {
|
|
22
|
+
reject(error);
|
|
23
|
+
} else {
|
|
24
|
+
resolve(Meteor.user());
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error('Meteor authentication failed:', error);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static async authenticateToken() {
|
|
36
|
+
// Implement token validation logic using Meteor
|
|
37
|
+
try {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const token = localStorage.getItem('Meteor.loginToken');
|
|
40
|
+
if (token) {
|
|
41
|
+
Meteor.loginWithToken(token, (error) => {
|
|
42
|
+
if (error) {
|
|
43
|
+
reject(error);
|
|
44
|
+
}
|
|
45
|
+
resolve(Meteor.user());
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
resolve(null);
|
|
49
|
+
});
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error('Token validation failed:', error);
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static async getUserAuthorizations(userId) {
|
|
57
|
+
// Implement logic to fetch user permissions from Meteor
|
|
58
|
+
try {
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
const roles = Roles.getRolesForUser(userId);
|
|
61
|
+
resolve(roles);
|
|
62
|
+
});
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error('Failed to fetch user permissions:', error);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static async deauthenticateUser() {
|
|
70
|
+
// Implement logout logic using Meteor
|
|
71
|
+
try {
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
Meteor.logout((error) => {
|
|
74
|
+
if (error) {
|
|
75
|
+
reject(error);
|
|
76
|
+
}
|
|
77
|
+
resolve(true);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('Logout failed:', error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static async registerNewUser(username, password) {
|
|
86
|
+
try {
|
|
87
|
+
const selector = AuthService.getUserQuerySelector(username);
|
|
88
|
+
selector.password = password;
|
|
89
|
+
|
|
90
|
+
// Implement user registration logic using Meteor
|
|
91
|
+
await Accounts.createUserAsync(selector);
|
|
92
|
+
return Meteor.user();
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error('Registration failed:', error);
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static async sendForgotPasswordEmail(email) {
|
|
100
|
+
try {
|
|
101
|
+
// Implement password reset logic using Meteor
|
|
102
|
+
return new Promise ((resolve, reject) => {
|
|
103
|
+
Accounts.forgotPassword({ email }, (error) => {
|
|
104
|
+
if (error) {
|
|
105
|
+
reject(error);
|
|
106
|
+
} else {
|
|
107
|
+
resolve();
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error('Password reset failed:', error);
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static async resetPasswordWithToken(token, password) {
|
|
118
|
+
try {
|
|
119
|
+
// Implement password reset logic using Meteor
|
|
120
|
+
return new Promise ((resolve, reject) => {
|
|
121
|
+
Accounts.resetPassword(token, password, (error) => {
|
|
122
|
+
if (error) {
|
|
123
|
+
reject(error);
|
|
124
|
+
} else {
|
|
125
|
+
resolve(Meteor.user());
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error('Password reset failed:', error);
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export default AuthService;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Meteor } from 'meteor/meteor';
|
|
2
|
+
import { Roles } from 'meteor/alanning:roles';
|
|
3
|
+
import { Accounts } from 'meteor/accounts-base';
|
|
4
|
+
|
|
5
|
+
class AuthService {
|
|
6
|
+
static getUserQuerySelector(username) {
|
|
7
|
+
// if the username is an email address, use the email field
|
|
8
|
+
if (username.indexOf('@') > -1) {
|
|
9
|
+
return { email: username };
|
|
10
|
+
} else {
|
|
11
|
+
return { username };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static async authenticateUser(username, password) {
|
|
16
|
+
// Implement Meteor-specific login logic
|
|
17
|
+
try {
|
|
18
|
+
const selector = AuthService.getUserQuerySelector(username);
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
Meteor.loginWithPassword(selector, password, (error) => {
|
|
21
|
+
if (error) {
|
|
22
|
+
reject(error);
|
|
23
|
+
} else {
|
|
24
|
+
resolve(Meteor.user());
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error('Meteor authentication failed:', error);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static async authenticateToken() {
|
|
36
|
+
// Implement token validation logic using Meteor
|
|
37
|
+
try {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const token = localStorage.getItem('Meteor.loginToken');
|
|
40
|
+
if (token) {
|
|
41
|
+
Meteor.loginWithToken(token, (error) => {
|
|
42
|
+
if (error) {
|
|
43
|
+
reject(error);
|
|
44
|
+
}
|
|
45
|
+
resolve(Meteor.user());
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
resolve(null);
|
|
49
|
+
});
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error('Token validation failed:', error);
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static async getUserAuthorizations(userId) {
|
|
57
|
+
// Implement logic to fetch user permissions from Meteor
|
|
58
|
+
try {
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
const roles = Roles.getRolesForUser(userId);
|
|
61
|
+
resolve(roles);
|
|
62
|
+
});
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error('Failed to fetch user permissions:', error);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static async deauthenticateUser() {
|
|
70
|
+
// Implement logout logic using Meteor
|
|
71
|
+
try {
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
Meteor.logout((error) => {
|
|
74
|
+
if (error) {
|
|
75
|
+
reject(error);
|
|
76
|
+
}
|
|
77
|
+
resolve(true);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('Logout failed:', error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static async registerNewUser(username: string, password: string) {
|
|
86
|
+
try {
|
|
87
|
+
const selector = AuthService.getUserQuerySelector(username);
|
|
88
|
+
selector.password = password;
|
|
89
|
+
|
|
90
|
+
// Implement user registration logic using Meteor
|
|
91
|
+
const user = await Accounts.createUserAsync(selector);
|
|
92
|
+
return user;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error('Registration failed:', error);
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static async sendForgotPasswordEmail(email: string) {
|
|
100
|
+
try {
|
|
101
|
+
// Implement password reset logic using Meteor
|
|
102
|
+
return new Promise ((resolve, reject) => {
|
|
103
|
+
Accounts.forgotPassword({ email }, (error) => {
|
|
104
|
+
if (error) {
|
|
105
|
+
reject(error);
|
|
106
|
+
} else {
|
|
107
|
+
resolve(true);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error('Password reset failed:', error);
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static async resetPasswordWithToken(token: string, password: string) {
|
|
118
|
+
try {
|
|
119
|
+
// Implement password reset logic using Meteor
|
|
120
|
+
return new Promise ((resolve, reject) => {
|
|
121
|
+
Accounts.resetPassword(token, password, (error) => {
|
|
122
|
+
if (error) {
|
|
123
|
+
reject(error);
|
|
124
|
+
} else {
|
|
125
|
+
resolve(true);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error('Password reset failed:', error);
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export default AuthService;
|
|
@@ -10,10 +10,12 @@ const <%= componentName %> = () => {
|
|
|
10
10
|
|
|
11
11
|
// Check if an element with id "app-bar" exists
|
|
12
12
|
const appBar = document.getElementById('app-bar');
|
|
13
|
+
const footer = document.getElementById('footer');
|
|
13
14
|
if (appBar) {
|
|
14
|
-
const appBarHeight = appBar.getBoundingClientRect().height;
|
|
15
|
+
const appBarHeight = appBar ? appBar.getBoundingClientRect().height : 0;
|
|
16
|
+
const footerHeight = footer ? footer.getBoundingClientRect().height : 0;
|
|
15
17
|
const windowHeight = window.innerHeight;
|
|
16
|
-
const adjustedHeight = windowHeight - appBarHeight;
|
|
18
|
+
const adjustedHeight = windowHeight - appBarHeight - footerHeight;
|
|
17
19
|
setMapHeight(`${adjustedHeight}px`);
|
|
18
20
|
}
|
|
19
21
|
}, []); // Empty dependency array means this useEffect runs once, similar to componentDidMount
|
|
@@ -14,10 +14,12 @@ const <%= componentName %> = () => {
|
|
|
14
14
|
|
|
15
15
|
// Check if an element with id "app-bar" exists
|
|
16
16
|
const appBar = document.getElementById('app-bar');
|
|
17
|
+
const footer = document.getElementById('footer');
|
|
17
18
|
if (appBar) {
|
|
18
|
-
const appBarHeight = appBar.getBoundingClientRect().height;
|
|
19
|
+
const appBarHeight = appBar ? appBar.getBoundingClientRect().height : 0;
|
|
20
|
+
const footerHeight = footer ? footer.getBoundingClientRect().height : 0;
|
|
19
21
|
const windowHeight = window.innerHeight;
|
|
20
|
-
const adjustedHeight = windowHeight - appBarHeight;
|
|
22
|
+
const adjustedHeight = windowHeight - appBarHeight - footerHeight;
|
|
21
23
|
setMapHeight(`${adjustedHeight}px`);
|
|
22
24
|
}
|
|
23
25
|
}, []); // Empty dependency array means this useEffect runs once, similar to componentDidMount
|
|
@@ -27,4 +29,4 @@ const <%= componentName %> = () => {
|
|
|
27
29
|
);
|
|
28
30
|
};
|
|
29
31
|
|
|
30
|
-
export { <%= componentName %> }
|
|
32
|
+
export { <%= componentName %> }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { Container, Paper, Typography, TextField, Button } from '@mui/material';
|
|
3
|
+
import { browserHistory } from 'react-router';
|
|
4
|
+
|
|
5
|
+
export const BasicForgotPasswordPage = () => {
|
|
6
|
+
const { forgotPassword } = useContext(AuthContext);
|
|
7
|
+
const handleSubmit = async (event) => {
|
|
8
|
+
event.preventDefault();
|
|
9
|
+
const { email } = event.target;
|
|
10
|
+
await forgotPassword(email.value);
|
|
11
|
+
browserHistory.push('/');
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<Container component="main" maxWidth="xs">
|
|
16
|
+
<Paper elevation={3} style={{ marginTop: '8vh', padding: '20px' }}>
|
|
17
|
+
<Typography component="h1" variant="h5">Forgot Password</Typography>
|
|
18
|
+
<form onSubmit={handleSubmit}>
|
|
19
|
+
{/* Form Field */}
|
|
20
|
+
<TextField id="email" type="email" label="Email*" fullWidth autoFocus margin="normal" />
|
|
21
|
+
<Button type="submit" fullWidth variant="contained" color="primary" style={{ margin: '20px 0' }}>
|
|
22
|
+
Send Password Reset Email
|
|
23
|
+
</Button>
|
|
24
|
+
<Button onClick={() => browserHistory.push('/login')} fullWidth>
|
|
25
|
+
Back to Login
|
|
26
|
+
</Button>
|
|
27
|
+
</form>
|
|
28
|
+
</Paper>
|
|
29
|
+
</Container>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { Container, Paper, Typography, TextField, Button } from '@mui/material';
|
|
3
|
+
import { browserHistory } from 'react-router';
|
|
4
|
+
|
|
5
|
+
export const BasicForgotPasswordPage = () => {
|
|
6
|
+
const { forgotPassword } = useContext(AuthContext);
|
|
7
|
+
const handleSubmit = async (event) => {
|
|
8
|
+
event.preventDefault();
|
|
9
|
+
const { email } = event.target;
|
|
10
|
+
await forgotPassword(email.value);
|
|
11
|
+
browserHistory.push('/');
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<Container component="main" maxWidth="xs">
|
|
16
|
+
<Paper elevation={3} style={{ marginTop: '8vh', padding: '20px' }}>
|
|
17
|
+
<Typography component="h1" variant="h5">Forgot Password</Typography>
|
|
18
|
+
<form onSubmit={handleSubmit}>
|
|
19
|
+
{/* Form Field */}
|
|
20
|
+
<TextField id="email" type="email" label="Email*" fullWidth autoFocus margin="normal" />
|
|
21
|
+
<Button type="submit" fullWidth variant="contained" color="primary" style={{ margin: '20px 0' }}>
|
|
22
|
+
Send Password Reset Email
|
|
23
|
+
</Button>
|
|
24
|
+
<Button onClick={() => browserHistory.push('/login')} fullWidth>
|
|
25
|
+
Back to Login
|
|
26
|
+
</Button>
|
|
27
|
+
</form>
|
|
28
|
+
</Paper>
|
|
29
|
+
</Container>
|
|
30
|
+
);
|
|
31
|
+
};
|