Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login reg #7

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2,444 changes: 2,444 additions & 0 deletions README.md

Large diffs are not rendered by default.

11,428 changes: 11,428 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"name": "vendordirectory",
"name": "vendorlist",
"version": "0.1.0",
"private": true,
"dependencies": {
"auth0-js": "^9.6.1",
"axios": "^0.18.0",
"jwt-decode": "^2.2.0",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-router-dom": "^4.3.1",
"react-scripts": "1.1.4"
},
"scripts": {
Expand All @@ -13,4 +17,4 @@
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
}
Binary file modified public/favicon.ico
Binary file not shown.
30 changes: 1 addition & 29 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>VendorList</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
36 changes: 17 additions & 19 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@
text-align: center;
}

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
.fl w-10{
height:40em;
}
/*login-reg*/

.App-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
.user-back{
background-image: url("http://architectureimg.com/wp-content/uploads/2016/08/houses-beautiful-place-shop-colorful-market-peaceful-building-vases-road-sky-water-greenery-balloons-store-city-clouds-buildings-house-grass-photography-town-high-resolution-1920x1080.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
min-height: 100vh;
width: 100%;
opacity: 0.3;
}

.App-title {
font-size: 1.5em;
}

.App-intro {
font-size: large;
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
.login-form-positon{
z-index: 99999;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
37 changes: 27 additions & 10 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import React, {Component} from 'react';
import Header from './components/header';
import Search from './components/search';
import Info from './components/info';
import './App.css';
import AuthService from './components/helper/auth';
import withAuth from './components/config/constants';
const Auth = new AuthService();

class App extends Component {
constructor(props) {
super(props)
this.handleLogout = this.handleLogout.bind(this)
}

handleLogout() {
Auth.logout()
this
.props
.history
.replace('/login');
}

render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to React</h1>
</header>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
<button type="button" className="form-submit" onClick={this.handleLogout}>Logout</button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this onClick event triggers the handleLogout method? you need to bind it .

<Header/>
<br/>
<Search/>
<br/>
<Info/>
</div>
);
}
}

export default App;
export default withAuth(App);
177 changes: 177 additions & 0 deletions src/components/User/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import React, { Component } from 'react';
import AuthService from '../helper/auth';
import axios from 'axios';

export default class Page extends Component {
state={
signup: true,
signin: false,
Auth: {},
Reg: {}
}

toggleSignUp(e){
this.setState({
signup: true,
signin: false
})
}

toggleSignIn(e){
this.setState({
signup: false,
signin: true
})
}


Auth = new AuthService ()

Login(e){
e.preventDefault();
const auth = {
email: this.Email.value,
password: this.Password.value
}
const Auth = {...this.state.Auth}
Object.assign(Auth, auth)
this.setState({
Auth
})
this.Auth.login(this.state.Auth.email,this.state.Auth.password)
.then(res=>{
this.props.history.replace("/");
})
.catch(err =>{
alert(err)
})
this.setState({
signup: false,
signin: true
})
}

register(e){
const reg = {
email: this.email.value,
name: this.name.value,
telephone: this.telephone.value,
password: this.password.value
}
const Reg = {...this.state.Reg}
const stamp = Date.now();
Reg[`reg-${stamp}`] = reg;
this.setState({
Reg
})
console.log(...this.state.Reg)
axios.post('https://Prostus.herokuapp.com/register', {...this.state.Reg})
.then(function(response){
console.log('saved successfully',response.data)
}).catch(err =>{
alert(err)
});
}

componentDidMount(){
if(this.Auth.loggedIn())
this.props.history.replace('/')
}

render() {

const {signin,signup} = this.state;

const Login = () => (
<div className="">
<form method="POST" onSubmit={(e)=> this.Login(e)} className="measure center">
<fieldset id="sign_up" className="b--black-80 ba b--transparent ph0 mh0">
<legend className="f4 fw6 ph0 mh0">Sign In</legend>
<div className="mt3">
<label className="db fw6 lh-copy f6" htmlFor="email-address">Email</label>
<input className="pa2 input-reset b--black-60 ba bg-transparent w-100" type="email" name="email-address" id="email-address" ref={(input) => this.Email = input}/>
</div>
<div className="mv3">
<label className="db fw6 lh-copy f6" htmlFor="password">Password</label>
<input className="b pa2 input-reset b--black-60 ba bg-transparent w-100" type="password" name="password" id="password" ref={(input)=> this.Password = input}/>
</div>
<label className="pa0 ma0 lh-copy f6 pointer"><input type="checkbox" /> Remember me</label>
</fieldset>
<div className="">
<input className="b ph3 pv2 input-reset b--black-60 ba bg-transparent grow pointer f6 dib" type="submit" value="Sign in" />
</div>
<div className="lh-copy mt3">
<a href="#0" className="f6 link dim black db" onClick={(e)=>this.toggleSignUp(e)}>Sign Up</a>
<a href="#0" className="f6 link dim black db">Forgot your password?</a>
</div>
</form>
<hr className="mv3"/>
<div className="inline-block-ns white">
<input className="b ph3 pv2 mv2 white b--transparent ba bg-red grow pointer f6 dib mr2" value="Sign In with Google" />
<input className="b ph3 pv2 mv2 white b--transparent ba bg-blue grow pointer f6 dib mr2" value="Sign In with Microsoft" />
<input className="b ph3 pv2 mv2 white b--transparent ba bg-dark-blue grow pointer f6 dib mr2" value="Sign In with Facebook" />
</div>
</div>
);

const Register = () => (
<div>
<form method="POST" onSubmit={(e)=> this.register(e)} className="measure center">
<fieldset id="sign_up" className="b--black-80 ba b--transparent ph0 mh0">
<legend className="f4 fw6 ph0 mh0">Sign Up</legend>
<div className="inline-flex-ns">
<div className="mt3 mr2">
<label className="db fw6 lh-copy f6" htmlFor="name">Name</label>
<input className="pa2 input-reset b--black-60 ba bg-transparent w-100" type="text" name="name" id="name" ref={(input)=> this.name = input} />
</div>
<div className="mv3 mr2">
<label className="db fw6 lh-copy f6" htmlFor="Telephone">Telephone</label>
<input className="b pa2 input-reset b--black-60 ba bg-transparent w-100" type="text" name="telephone" id="telephone" ref={(input)=> this.telephone = input} />
</div>
</div>
<div className="inline-flex-ns">
<div className="mt3 mr2">
<label className="db fw6 lh-copy f6" htmlFor="email-address">Email</label>
<input className="pa2 input-reset b--black-60 ba bg-transparent w-100" type="email" name="email-address" id="email-address" ref={(input)=> this.email = input} />
</div>
<div className="mv3 mr2">
<label className="db fw6 lh-copy f6" htmlFor="password">Password</label>
<input className="b pa2 input-reset b--black-60 ba bg-transparent w-100" type="password" name="password" id="password" ref={(input)=> this.password = input} />
</div>
</div>
</fieldset>
<div className="">
<input className="b ph3 pv2 input-reset b--black-60 ba bg-transparent grow pointer f6 dib" type="submit" value="Sign up" onClick={(e)=> this.register(e)} />
</div>
<div className="lh-copy mt3">
<a href="#0" className="f6 link dim black db" onClick={(e)=>this.toggleSignIn(e)}>Sign In</a>
</div>
</form>
<hr className="mv3"/>
<div className="inline-block-ns white">
<input className="b ph3 pv2 mv2 white b--transparent ba bg-red grow pointer f6 dib mr2" value="Sign In with Google" />
<input className="b ph3 pv2 mv2 white b--transparent ba bg-blue grow pointer f6 dib mr2" value="Sign In with Microsoft" />
<input className="b ph3 pv2 mv2 white b--transparent ba bg-dark-blue grow pointer f6 dib mr2" value="Sign In with Facebook" />
</div>
</div>
);



return (
<div>
<div className="user-back"></div>
<div className="login-form-positon ">
<div className="tc">
<img src="http://tachyons.io/img/avatar_1.jpg" className="br-100 h3 w3 dib ba b--black-60-05 pa2" alt="company logo" title="logo of the company" style={{paddingBotom: '0px'}}/>
<h1 className="f3 mt1 mb4">Vendor</h1>
</div>
<div className=" pa4 black-80 tc">
{signin === true && <Login />}
{signup === true && <Register />}
</div>
</div>
</div>
);
}
}
42 changes: 42 additions & 0 deletions src/components/config/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, {Component} from 'react';
import AuthService from '../helper/auth';

export default function withAuth(AuthComponent) {
const Auth = new AuthService('https://Prostus.herokuapp.com');
return class AuthWrapped extends Component {
constructor() {
super();
this.state = {
user: null
}
}
componentWillMount() {
if (!Auth.loggedIn()) {
this
.props
.history
.replace('/login')
} else {
try {
const profile = Auth.getProfile()
this.setState({user: profile})
} catch (err) {
Auth.logout()
this
.props
.history
.replace('/login')
}
}
}
render() {
if (this.state.user) {
return (<AuthComponent history={this.props.history} user={this.state.user}/>)
} else {
return (
<h1>loading....</h1>
)
}
}
}
}
Loading