working on signup
This commit is contained in:
@@ -14,4 +14,4 @@ client.connect()
|
||||
.then(() => console.log('Successfully connected to database'))
|
||||
.catch((err) => console.log('Error on connecting to database: ', err));
|
||||
|
||||
module.export = client;
|
||||
module.exports = client;
|
||||
|
||||
16
index.js
16
index.js
@@ -1,7 +1,7 @@
|
||||
const express = require('express');
|
||||
const session = require('express-session');
|
||||
const path = require('path');
|
||||
const client = require('./app/db')
|
||||
const client = require('./app/db');
|
||||
const port = 3000
|
||||
const app = express()
|
||||
require('dotenv').config()
|
||||
@@ -17,7 +17,7 @@ app.use(session({
|
||||
saveUninitialized: true
|
||||
}));
|
||||
|
||||
app.post('/auth', async function(req, res) {
|
||||
app.post('/auth/login', async function(req, res) {
|
||||
let username = req.body.username.trim();
|
||||
let password = req.body.password.trim();
|
||||
|
||||
@@ -42,10 +42,22 @@ app.post('/auth', async function(req, res) {
|
||||
res.end();
|
||||
});
|
||||
|
||||
app.post('/auth/signup', (req, res) => {
|
||||
|
||||
let username = req.body.username.trim();
|
||||
let password = req.body.password.trim();
|
||||
let sPassword = req.body.sPassword.trim()
|
||||
|
||||
|
||||
})
|
||||
app.get('/login', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, '/public/routes/login.html'));
|
||||
})
|
||||
|
||||
app.get('/signup', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, '/public/routes/signup.html'));
|
||||
})
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, '/public/routes/index.html'));
|
||||
})
|
||||
|
||||
22
public/js/signup.js
Normal file
22
public/js/signup.js
Normal file
@@ -0,0 +1,22 @@
|
||||
function showPasswd() {
|
||||
let x = document.getElementById("password");
|
||||
let y = document.getElementById("sPassword");
|
||||
if(x.type == "password"){
|
||||
x.type = "text";
|
||||
y.type = "text";
|
||||
} else {
|
||||
x.type = "password";
|
||||
y.type = "password";
|
||||
}
|
||||
}
|
||||
|
||||
const password = document.getElementById("Password").trim();
|
||||
const sPassword = document.getElementById("sPassword").trim();
|
||||
|
||||
document.getElementById('signupForm').addEventListener('submit',function (event) {
|
||||
|
||||
if(password !== sPassword){
|
||||
alert("Passwords don't match!");
|
||||
event.preventDefault();
|
||||
}
|
||||
})
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
<div class="login">
|
||||
<h1>Login</h1>
|
||||
<form action="/auth" method="post">
|
||||
<form action="/auth/login" method="post">
|
||||
|
||||
<label for="username">
|
||||
</label>
|
||||
|
||||
36
public/routes/signup.html
Normal file
36
public/routes/signup.html
Normal file
@@ -0,0 +1,36 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Sign up</title>
|
||||
<script src="../js/signup.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="signup">
|
||||
<h1>Login</h1>
|
||||
<form action="/auth/signup" method="post" id="signupForm">
|
||||
|
||||
<label for="username">
|
||||
</label>
|
||||
<input type="text" name="username" placeholder="Username" id="username" required>
|
||||
|
||||
<label for="password">
|
||||
</label>
|
||||
<input type="password" name="password" placeholder="Password" id="password" required>
|
||||
|
||||
<label for="sPassword">
|
||||
</label>
|
||||
<input type="password" name="sPassword" placeholder="Confirm password" id="sPassword" required>
|
||||
|
||||
<input type="checkbox" onclick="showPasswd()">Show Passwords
|
||||
|
||||
<input type="submit" value="Sign up">
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user