initial commit
This commit is contained in:
commit
3b3c9a9417
258 changed files with 20086 additions and 0 deletions
7
services/myblog/frontend/pages/_app.js
Normal file
7
services/myblog/frontend/pages/_app.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import '../styles/globals.css'
|
||||
|
||||
function MyApp({ Component, pageProps }) {
|
||||
return <Component {...pageProps} />
|
||||
}
|
||||
|
||||
export default MyApp
|
||||
5
services/myblog/frontend/pages/api/hello.js
Normal file
5
services/myblog/frontend/pages/api/hello.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
|
||||
export default function handler(req, res) {
|
||||
res.status(200).json({ name: 'John Doe' })
|
||||
}
|
||||
67
services/myblog/frontend/pages/auth.tsx
Normal file
67
services/myblog/frontend/pages/auth.tsx
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import {withLayout} from "../layout_auth/Layout";
|
||||
import {useState} from "react";
|
||||
import axios from 'axios';
|
||||
import Cookie from 'js-cookie';
|
||||
import {useRouter} from "next/router";
|
||||
import jwtDecode from "jwt-decode";
|
||||
import 'bootstrap/dist/css/bootstrap.min.css';
|
||||
import {
|
||||
Container, Row, Col, Form, Input, Button, Navbar, Nav,
|
||||
NavbarBrand, NavLink, NavItem, UncontrolledDropdown,
|
||||
DropdownToggle, DropdownMenu, DropdownItem
|
||||
} from 'reactstrap';
|
||||
|
||||
function setUserIDLocalStrorage(token: string): void{
|
||||
const decoded_token = jwtDecode<{user:{ID:string} }>(token);
|
||||
localStorage.setItem('user_id', decoded_token.user.ID);
|
||||
}
|
||||
|
||||
function Home() {
|
||||
const router = useRouter();
|
||||
const initialFormData = Object.freeze({
|
||||
username: "",
|
||||
password: ""
|
||||
});
|
||||
const [formData, updateFormData] = useState(initialFormData);
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
updateFormData({
|
||||
...formData,
|
||||
|
||||
// Trimming any whitespace
|
||||
[e.target.name]: e.target.value.trim()
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmit = (e: React.ChangeEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
axios.post('http://10.50.20.5:13377/api/auth/sign_in', formData, {withCredentials: true})
|
||||
.then(function(response){
|
||||
let cook = response.headers['set-cookie']
|
||||
//Cookies.set('api_session', cook)
|
||||
router.push('/blog');
|
||||
//Perform action based on response
|
||||
})
|
||||
.catch(function(error){
|
||||
console.log(error);
|
||||
alert("Bad creads")
|
||||
//Perform action based on error
|
||||
});
|
||||
|
||||
|
||||
// ... submit to API or something
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<form style={{gridArea: "form"}} onSubmit={handleSubmit}>
|
||||
<h1>Sign In</h1>
|
||||
<Input onChange={handleChange} name={"username"} placeholder={"Username"}/>
|
||||
<Input onChange={handleChange} name={"password"} placeholder={"Password"}/>
|
||||
<Button>Sign In</Button>
|
||||
<NavLink href={"/register"} style={{justifySelf: "center", alignSelf: "center"}}>Sign out</NavLink>
|
||||
</form>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default withLayout(Home);
|
||||
23
services/myblog/frontend/pages/blog.tsx
Normal file
23
services/myblog/frontend/pages/blog.tsx
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import {withLayout} from "../layout_blog/Layout";
|
||||
import {useState} from "react";
|
||||
import axios from 'axios';
|
||||
import Cookie from 'js-cookie';
|
||||
import {useRouter} from "next/router";
|
||||
import jwtDecode from "jwt-decode";
|
||||
import 'bootstrap/dist/css/bootstrap.min.css';
|
||||
import {
|
||||
Container, Row, Col, Form, Input, Button, Navbar, Nav,
|
||||
NavbarBrand, NavLink, NavItem, UncontrolledDropdown,
|
||||
DropdownToggle, DropdownMenu, DropdownItem
|
||||
} from 'reactstrap';
|
||||
|
||||
|
||||
function Home() {
|
||||
return (
|
||||
<>
|
||||
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default withLayout(Home);
|
||||
56
services/myblog/frontend/pages/index.tsx
Normal file
56
services/myblog/frontend/pages/index.tsx
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import Head from 'next/head'
|
||||
import Image from 'next/image'
|
||||
import styles from '../styles/Home.module.css'
|
||||
import {useRouter} from "next/router";
|
||||
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<Head>
|
||||
<title>MyBlog</title>
|
||||
<meta name="description" content="Generated by create next app" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
|
||||
<main className={styles.main}>
|
||||
<h1 className={styles.title}>
|
||||
Welcome to <a href="https://nextjs.org">Next.js!</a>
|
||||
</h1>
|
||||
|
||||
<div className={styles.grid}>
|
||||
<a href="/auth" className={styles.card}>
|
||||
<h2>Sign in MyBlog</h2>
|
||||
|
||||
</a>
|
||||
|
||||
<a href="/register" className={styles.card}>
|
||||
<h2>Register in MyBLog</h2>
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="/blog"
|
||||
className={styles.card}
|
||||
>
|
||||
<h2>Go to blog →</h2>
|
||||
</a>
|
||||
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer className={styles.footer}>
|
||||
<a
|
||||
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Powered by{' '}
|
||||
<span className={styles.logo}>
|
||||
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
|
||||
</span>
|
||||
</a>
|
||||
</footer>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
59
services/myblog/frontend/pages/register.tsx
Normal file
59
services/myblog/frontend/pages/register.tsx
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import {withLayout} from "../layout_auth/Layout";
|
||||
import {useState} from "react";
|
||||
import axios from 'axios';
|
||||
import 'bootstrap/dist/css/bootstrap.min.css';
|
||||
import {useRouter} from "next/router";
|
||||
import {
|
||||
Container, Row, Col, Form, Input, Button, Navbar, NavLink
|
||||
} from 'reactstrap';
|
||||
|
||||
function Home() {
|
||||
const router = useRouter();
|
||||
const initialFormData = Object.freeze({
|
||||
username: "",
|
||||
password: ""
|
||||
});
|
||||
const [formData, updateFormData] = useState(initialFormData);
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
updateFormData({
|
||||
...formData,
|
||||
|
||||
// Trimming any whitespace
|
||||
[e.target.name]: e.target.value.trim()
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmit = (e: React.ChangeEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
axios.post('http://10.50.20.5:13377/api/auth/sign_up', formData)
|
||||
.then(function(response){
|
||||
|
||||
router.push('/auth');
|
||||
//Perform action based on response
|
||||
})
|
||||
.catch(function(error){
|
||||
console.log(error);
|
||||
//Perform action based on error
|
||||
});
|
||||
|
||||
|
||||
// ... submit to API or something
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<form style={{gridArea: "form"}} onSubmit={handleSubmit}>
|
||||
<h1>Sign Out</h1>
|
||||
<Input onChange={handleChange} name={"username"} placeholder={"Username"}/>
|
||||
<Input onChange={handleChange} type={"password"} name={"password"} placeholder={"Password"}/>
|
||||
<Input onChange={handleChange} type={"password"} name={"password_repeat"} placeholder={"Password (repeat)"}/>
|
||||
<Button>Sign Out</Button>
|
||||
<NavLink href={"/auth"} style={{justifySelf: "center", alignSelf: "center"}}>Sign In</NavLink>
|
||||
</form>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default withLayout(Home);
|
||||
Loading…
Add table
Add a link
Reference in a new issue