Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cloud_Computing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Automate
Agent sessions
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alexander Tim Hobelsberger
Cloud_Computing
Commits
a78cb286
Commit
a78cb286
authored
Oct 29, 2022
by
Alexander Tim Hobelsberger
Browse files
Options
Downloads
Patches
Plain Diff
EventListener
parent
eae55f26
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
routes/login.js
+7
-4
7 additions, 4 deletions
routes/login.js
views/login.html
+22
-16
22 additions, 16 deletions
views/login.html
views/register.html
+16
-6
16 additions, 6 deletions
views/register.html
with
45 additions
and
26 deletions
routes/login.js
+
7
−
4
View file @
a78cb286
const
User
=
require
(
'
../models/user
'
);
const
http
=
require
(
'
http
'
);
const
bcrypt
=
require
(
'
bcrypt
'
);
const
jwt
=
require
(
'
jsonwebtoken
'
);
const
express
=
require
(
'
express
'
);
...
...
@@ -10,22 +11,24 @@ const bodyParser = require('body-parser');
router
.
post
(
'
/
'
,
async
(
req
,
res
)
=>
{
var
name
=
req
.
body
.
name
;
var
password
=
req
.
body
.
password
;
res
.
status
(
200
);
console
.
log
(
name
,
password
);
User
.
findOne
({
name
:
name
})
.
then
(
user
=>
{
if
(
user
){
bcrypt
.
compare
(
password
,
user
.
password
,
function
(
err
,
result
)
{
if
(
err
){
console
.
log
(
"
Login Route Error
"
);
res
.
json
(
err
);
}
if
(
result
){
res
.
status
(
200
);
console
.
log
(
"
Index Route Result
"
);
let
token
=
jwt
.
sign
({
name
:
user
.
name
},
'
secretValue
'
,
{
expiresIn
:
'
1h
'
})
/*
res.json({
res
.
json
({
statusCode
:
'
200
'
,
token
}) */
})
}
else
{
res
.
status
(
401
);
}
...
...
This diff is collapsed.
Click to expand it.
views/login.html
+
22
−
16
View file @
a78cb286
...
...
@@ -8,24 +8,33 @@
<body>
<div
id =
"login"
>
<h1>
Login
</h1>
<form
id=
"
reg
-form"
>
<form
id=
"
login
-form"
>
<input
type=
"text"
autocomplete=
"off"
id=
"username"
placeholder=
"Username"
/>
<input
type=
"password"
autocomplete=
"off"
id=
"password"
placeholder=
"Password"
/>
<input
onclick =
"submitLoginData()"
type=
"submit"
value=
"Submit Form"
/>
<input
type=
"submit"
value=
"Submit Form"
/>
</form>
</div>
<script>
function
submitLoginData
()
{
const
form
=
document
.
getElementById
(
'
login-form
'
);
form
.
addEventListener
(
'
submit
'
,
submitLoginData
);
function
submitLoginData
(
event
)
{
event
.
preventDefault
();
var
username
=
document
.
getElementById
(
"
username
"
).
value
;
var
password
=
document
.
getElementById
(
"
password
"
).
value
;
var
myHeaders
=
new
Headers
();
myHeaders
.
append
(
"
Content-Type
"
,
"
application/json
"
);
var
raw
=
JSON
.
stringify
({
"
name
"
:
"
Tester
"
,
"
password
"
:
"
12345
"
"
name
"
:
username
,
"
password
"
:
password
});
console
.
log
(
raw
);
var
requestOptions
=
{
method
:
'
POST
'
,
headers
:
myHeaders
,
...
...
@@ -41,7 +50,4 @@
</script>
</body>
<style>
</style>
</html>
This diff is collapsed.
Click to expand it.
views/register.html
+
16
−
6
View file @
a78cb286
...
...
@@ -11,20 +11,31 @@
<form
id=
"reg-form"
>
<input
type=
"text"
autocomplete=
"off"
id=
"username"
placeholder=
"Username"
/>
<input
type=
"password"
autocomplete=
"off"
id=
"password"
placeholder=
"Password"
/>
<input
onclick =
"submitRegistrationData()"
type=
"submit"
value=
"Submit Form"
/>
<input
type=
"submit"
value=
"Submit Form"
/>
</form>
</div>
<script>
function
submitRegistrationData
()
{
var
myHeaders
=
new
Headers
();
myHeaders
.
append
(
"
Content-Type
"
,
"
application/json
"
);
const
form
=
document
.
getElementById
(
'
reg-form
'
);
form
.
addEventListener
(
'
submit
'
,
submitRegistrationData
);
async
function
submitRegistrationData
(
event
)
{
event
.
preventDefault
();
console
.
log
(
"
submit
"
);
var
username
=
document
.
getElementById
(
"
username
"
).
value
;
var
password
=
document
.
getElementById
(
"
password
"
).
value
;
console
.
log
(
username
,
password
);
var
myHeaders
=
new
Headers
();
myHeaders
.
append
(
"
Content-Type
"
,
"
application/json
"
);
var
raw
=
JSON
.
stringify
({
"
name
"
:
username
,
"
password
"
:
password
});
var
requestOptions
=
{
method
:
'
POST
'
,
...
...
@@ -33,7 +44,6 @@
redirect
:
'
follow
'
};
fetch
(
"
http://localhost:3000/register
"
,
requestOptions
)
.
then
(
response
=>
response
.
text
())
.
then
(
result
=>
console
.
log
(
result
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment