Skip to content

Commit

Permalink
Add js file for login
Browse files Browse the repository at this point in the history
Add cors to app.js
  • Loading branch information
ebenezerdon committed Nov 10, 2018
1 parent e7ed785 commit 0e05f12
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 16 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"root": true,
"extends": "airbnb-base",
"env": {
"browser": true,
"node": true,
"es6": true,
"mocha": true
Expand All @@ -12,5 +13,9 @@
},
"rules": {
"linebreak-style": ["error", "windows"]
}
},
"globals": {
"localStorage": true,
"fetch": true
}
}
45 changes: 45 additions & 0 deletions UI/assets/js/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// const loginUser = () => {
// const emailaddress = document.getElementById('emailaddress').value;
// const password = document.getElementById('password').value;
// fetch('https://newstoremanager.herokuapp.com/api/v1/auth/login', {
// method: 'POST',
// headers: {
// Accept: 'application/json, text/plain, */*',
// 'content-Type': 'application/json',
// },
// body: JSON.stringify({
// emailaddress: emailaddress,
// password: password,
// }),
// }).then(res => res.json())
// .then((data) => {
// console.log(data);
// if (data.status === 200) {
// localStorage.setItem('accesstoken', `${data.data}`);
// }
// });
// };

// document.getElementById('login').addEventListener('submit', loginUser);
const loginDetails = {
emailaddress: document.getElementById('emailaddress').value,
password: document.getElementById('password').value,
};

const options = {
method: 'POST',
body: JSON.stringify(loginDetails),
headers: new Headers({
'Content-Type': 'application/json'
}),
};

const loginUser = (e) => {
e.preventDefault();
fetch('https://newstoremanager.herokuapp.com/api/v1/auth/login', options)
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.log(err));
};

document.getElementById('login').addEventListener('submit', loginUser);
19 changes: 4 additions & 15 deletions UI/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="./assets/css/main.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous">
<script src="main.js"></script>
</head>

<body>
Expand All @@ -21,18 +20,7 @@
<div class="nav-2">
<h2>Hello awesome!</h2>
</div>

<!-- <div class="card-div">
<ul class="card">
<li class="card-item item6"></li>
<li class="card-item item5"></li>
<li class="card-item item4"></li>
<li class="card-item item3"></li>
<li class="card-item item2"></li>
<li class="card-item item1"></li>
</ul>
</div> -->
<section class="login-form">
<section class="login-form" id="login">
<form action="" autocomplete="on">
<h1>Login Here</h1>
<div>
Expand All @@ -41,12 +29,13 @@ <h1>Login Here</h1>
<div>
<input type="password" placeholder="Password" required="" id="password" />
</div>
<button class="button">Login</button>
<button type="submit" class="button">Login</button>
<!-- <button class="button" id="loginbutton">Login</button> -->
<!-- <a href="#">Lost your password?</a> -->
</div>
</form>
</section>
</div>
<script type="text/javascript" src="assets/js/login.js"></script>
</body>

</html>
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import express from 'express';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import logger from 'morgan';
import cors from 'cors';
import router from './server/routes/index';

const app = express();
Expand All @@ -13,6 +14,7 @@ app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(cors());

// use body parser to parse request
app.use(bodyParser.urlencoded({ extended: true }));
Expand Down

0 comments on commit 0e05f12

Please sign in to comment.