Skip to content

Commit 75719da

Browse files
Blog-977327 - added the client sample
1 parent b0ba4d1 commit 75719da

File tree

12 files changed

+838
-0
lines changed

12 files changed

+838
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Getting Started with Create React App
2+
3+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4+
5+
## Available Scripts
6+
7+
In the project directory, you can run:
8+
9+
### `npm start`
10+
11+
Runs the app in the development mode.\
12+
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
13+
14+
The page will reload when you make changes.\
15+
You may also see any lint errors in the console.
16+
17+
### `npm test`
18+
19+
Launches the test runner in the interactive watch mode.\
20+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21+
22+
### `npm run build`
23+
24+
Builds the app for production to the `build` folder.\
25+
It correctly bundles React in production mode and optimizes the build for the best performance.
26+
27+
The build is minified and the filenames include the hashes.\
28+
Your app is ready to be deployed!
29+
30+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31+
32+
### `npm run eject`
33+
34+
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
35+
36+
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37+
38+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
39+
40+
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
41+
42+
## Learn More
43+
44+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45+
46+
To learn React, check out the [React documentation](https://reactjs.org/).
47+
48+
### Code Splitting
49+
50+
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51+
52+
### Analyzing the Bundle Size
53+
54+
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55+
56+
### Making a Progressive Web App
57+
58+
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59+
60+
### Advanced Configuration
61+
62+
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63+
64+
### Deployment
65+
66+
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67+
68+
### `npm run build` fails to minify
69+
70+
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "syncfusion-pdf-viewer",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@syncfusion/ej2-base": "^31.2.2",
7+
"@syncfusion/ej2-react-dropdowns": "^31.2.3",
8+
"@syncfusion/ej2-react-pdfviewer": "^31.2.3",
9+
"@testing-library/dom": "^10.4.1",
10+
"@testing-library/jest-dom": "^6.8.0",
11+
"@testing-library/react": "^16.3.0",
12+
"@testing-library/user-event": "^13.5.0",
13+
"bootstrap": "^5.3.8",
14+
"react": "^19.1.1",
15+
"react-dom": "^19.1.1",
16+
"web-vitals": "^2.1.4"
17+
},
18+
"scripts": {
19+
"start": "react-scripts start",
20+
"build": "react-scripts build",
21+
"test": "react-scripts test",
22+
"eject": "react-scripts eject"
23+
},
24+
"eslintConfig": {
25+
"extends": [
26+
"react-app",
27+
"react-app/jest"
28+
]
29+
},
30+
"browserslist": {
31+
"production": [
32+
">0.2%",
33+
"not dead",
34+
"not op_mini all"
35+
],
36+
"development": [
37+
"last 1 chrome version",
38+
"last 1 firefox version",
39+
"last 1 safari version"
40+
]
41+
},
42+
"devDependencies": {
43+
"react-scripts": "^5.0.1"
44+
}
45+
}
Binary file not shown.
24.3 KB
Loading
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="theme-color" content="#000000" />
8+
<meta
9+
name="description"
10+
content="Web site created using create-react-app"
11+
/>
12+
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
13+
<!--
14+
manifest.json provides metadata used when your web app is installed on a
15+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
16+
-->
17+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18+
<!--
19+
Notice the use of %PUBLIC_URL% in the tags above.
20+
It will be replaced with the URL of the `public` folder during the build.
21+
Only files inside the `public` folder can be referenced from the HTML.
22+
23+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24+
work correctly both with client-side routing and a non-root public URL.
25+
Learn how to configure a non-root public URL by running `npm run build`.
26+
-->
27+
<title>React App</title>
28+
</head>
29+
<body>
30+
<noscript>You need to enable JavaScript to run this app.</noscript>
31+
<div id="root"></div>
32+
<!--
33+
This HTML file is a template.
34+
If you open it directly in the browser, you will see an empty page.
35+
36+
You can add webfonts, meta tags, or analytics to this file.
37+
The build step will place the bundled scripts into the <body> tag.
38+
39+
To begin the development, run `npm start` or `yarn start`.
40+
To create a production bundle, use `npm run build` or `yarn build`.
41+
-->
42+
</body>
43+
</html>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
},
10+
{
11+
"src": "logo192.png",
12+
"type": "image/png",
13+
"sizes": "192x192"
14+
},
15+
{
16+
"src": "logo512.png",
17+
"type": "image/png",
18+
"sizes": "512x512"
19+
}
20+
],
21+
"start_url": ".",
22+
"display": "standalone",
23+
"theme_color": "#000000",
24+
"background_color": "#ffffff"
25+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import { useState } from "react";
2+
import "./index.css"; // Make sure this CSS file exists and is correctly styled
3+
4+
const hostURL = "https://localhost:44310/api/Authentication";
5+
6+
function Authentication({ onLogin }) {
7+
const [isRegistering, setIsRegistering] = useState(false);
8+
const [message, setMessage] = useState("");
9+
const [username, setUsername] = useState("");
10+
11+
const validateEmail = (email) => /\S+@\S+\.\S+/.test(email);
12+
13+
const handleLogin = async (event) => {
14+
event.preventDefault();
15+
setMessage("");
16+
17+
const form = event.currentTarget;
18+
const email = form.elements.email.value.trim();
19+
const password = form.elements.password.value.trim();
20+
21+
if (!validateEmail(email)) {
22+
setMessage("❌ Please enter a valid email.");
23+
return;
24+
}
25+
26+
try {
27+
const response = await fetch(`${hostURL}/login`, {
28+
method: "POST",
29+
headers: { "Content-Type": "application/json" },
30+
body: JSON.stringify({ email, password }),
31+
});
32+
33+
if (response.ok) {
34+
const userData = await response.json();
35+
localStorage.setItem("user", JSON.stringify(userData));
36+
onLogin(userData);
37+
} else {
38+
setMessage("❌ Invalid email or password.");
39+
}
40+
} catch {
41+
setMessage("⚠️ Server error during login.");
42+
}
43+
};
44+
45+
const handleRegister = async (e) => {
46+
e.preventDefault();
47+
setMessage("");
48+
49+
const form = e.currentTarget;
50+
const email = form.elements.email.value;
51+
const password = form.elements.password.value;
52+
53+
if (!validateEmail(email)) {
54+
setMessage("❌ Please enter a valid email.");
55+
return;
56+
}
57+
58+
try {
59+
const register = await fetch(`${hostURL}/register`, {
60+
method: "POST",
61+
headers: { "Content-Type": "application/json" },
62+
body: JSON.stringify({ username, email, password }),
63+
});
64+
65+
const data = await register.json();
66+
if (register.ok) {
67+
setMessage("✅ Registration successful. You can now log in.");
68+
setIsRegistering(false);
69+
setUsername("");
70+
} else {
71+
setMessage(`❌ ${data.message || "Registration failed"}`);
72+
}
73+
} catch {
74+
setMessage("⚠️ Server error during registration.");
75+
}
76+
};
77+
78+
return (
79+
<div className="auth-container">
80+
<h2 className="auth-title">{isRegistering ? "Register" : "Login"}</h2>
81+
<form className="auth-form" onSubmit={isRegistering ? handleRegister : handleLogin}>
82+
{isRegistering && (
83+
<>
84+
<label className="auth-label" htmlFor="username">Username:</label>
85+
<input
86+
id="username"
87+
type="text"
88+
name="username"
89+
value={username}
90+
onChange={(e) => setUsername(e.target.value)}
91+
required
92+
className="auth-input"
93+
placeholder="Your username"
94+
/>
95+
</>
96+
)}
97+
<label className="auth-label" htmlFor="email">Email:</label>
98+
<input
99+
id="email"
100+
type="email"
101+
name="email"
102+
required
103+
className="auth-input"
104+
placeholder="[email protected]"
105+
/>
106+
<label className="auth-label" htmlFor="password">Password:</label>
107+
<input
108+
id="password"
109+
type="password"
110+
name="password"
111+
required
112+
className="auth-input"
113+
placeholder="Your password"
114+
/>
115+
<button type="submit" className="auth-button primary">
116+
{isRegistering ? "Register" : "Login"}
117+
</button>
118+
</form>
119+
<button
120+
className="auth-button secondary"
121+
onClick={() => {
122+
setIsRegistering(!isRegistering);
123+
setMessage("");
124+
setUsername("");
125+
}}
126+
style={{ marginTop: 12 }}
127+
>
128+
{isRegistering ? "Already have an account? Log in" : "Don't have an account? Register"}
129+
</button>
130+
{message && <p className="auth-message">{message}</p>}
131+
</div>
132+
);
133+
}
134+
135+
export default Authentication;

0 commit comments

Comments
 (0)