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
a0f82cfe
Commit
a0f82cfe
authored
Oct 30, 2022
by
Markus Klose
Browse files
Options
Downloads
Patches
Plain Diff
Username already exists Registration check
parent
8179eaaf
No related branches found
No related tags found
1 merge request
!5
Redirect
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
routes/register.js
+21
-9
21 additions, 9 deletions
routes/register.js
views/login.html
+28
-6
28 additions, 6 deletions
views/login.html
views/register.html
+9
-63
9 additions, 63 deletions
views/register.html
with
58 additions
and
78 deletions
routes/register.js
+
21
−
9
View file @
a0f82cfe
...
@@ -18,7 +18,17 @@ router.post('/', async(req, res) => {
...
@@ -18,7 +18,17 @@ router.post('/', async(req, res) => {
name
:
req
.
body
.
name
,
name
:
req
.
body
.
name
,
password
:
hashedPass
password
:
hashedPass
})
})
User
.
findOne
({
name
:
req
.
body
.
name
})
var
query
=
User
.
find
({
"
name
"
:
req
.
body
.
name
});
query
.
count
(
function
(
err
,
count
)
{
if
(
count
!==
0
)
{
res
.
sendStatus
(
401
);
}
else
{
console
.
log
(
"
Count is
"
,
count
)
user
.
save
()
user
.
save
()
.
then
(
user
=>
{
.
then
(
user
=>
{
res
.
sendStatus
(
200
);
res
.
sendStatus
(
200
);
...
@@ -28,6 +38,8 @@ router.post('/', async(req, res) => {
...
@@ -28,6 +38,8 @@ router.post('/', async(req, res) => {
message
:
'
Error occured
'
message
:
'
Error occured
'
})
})
})
})
}
})
})
})
});
});
...
...
This diff is collapsed.
Click to expand it.
views/login.html
+
28
−
6
View file @
a0f82cfe
...
@@ -24,15 +24,15 @@
...
@@ -24,15 +24,15 @@
event
.
preventDefault
();
event
.
preventDefault
();
var
username
=
document
.
getElementById
(
"
username
"
)
.
value
;
var
username
=
document
.
getElementById
(
"
username
"
);
var
password
=
document
.
getElementById
(
"
password
"
)
.
value
;
var
password
=
document
.
getElementById
(
"
password
"
);
var
myHeaders
=
new
Headers
();
var
myHeaders
=
new
Headers
();
myHeaders
.
append
(
"
Content-Type
"
,
"
application/json
"
);
myHeaders
.
append
(
"
Content-Type
"
,
"
application/json
"
);
var
raw
=
JSON
.
stringify
({
var
raw
=
JSON
.
stringify
({
"
name
"
:
username
,
"
name
"
:
username
.
value
.
trim
()
,
"
password
"
:
password
"
password
"
:
password
.
value
.
trim
()
});
});
var
requestOptions
=
{
var
requestOptions
=
{
...
@@ -43,8 +43,30 @@
...
@@ -43,8 +43,30 @@
};
};
fetch
(
"
http://localhost:3000/login
"
,
requestOptions
)
fetch
(
"
http://localhost:3000/login
"
,
requestOptions
)
.
then
(
response
=>
response
.
text
())
.
then
(
response
=>
response
.
json
())
.
then
(
result
=>
console
.
log
(
result
))
.
then
((
result
)
=>
{
// Statuscode abrufen mit JSON dingens
var
status
=
result
.
status
;
var
token
=
result
.
token
;
// Weiterleitung an Chatroom, bei erfolreicher Anmeldung
if
(
status
==
200
)
{
window
.
location
.
href
=
"
/chatroom
"
;
}
//
else
{
username
.
value
=
""
;
password
.
value
=
""
;
var
loginFailed
=
document
.
createElement
(
'
div
'
);
loginFailed
.
setAttribute
(
"
id
"
,
"
loginFailed
"
);
loginFailed
.
textContent
=
"
Login fehlgeschlagen, bitte versuche es erneut
"
;
document
.
body
.
appendChild
(
loginFailed
);
}
console
.
log
(
result
)
})
.
catch
(
error
=>
console
.
log
(
'
error
'
,
error
));
.
catch
(
error
=>
console
.
log
(
'
error
'
,
error
));
}
}
</script>
</script>
...
...
This diff is collapsed.
Click to expand it.
views/register.html
+
9
−
63
View file @
a0f82cfe
...
@@ -50,7 +50,6 @@
...
@@ -50,7 +50,6 @@
fetch
(
"
http://localhost:3000/register
"
,
requestOptions
)
fetch
(
"
http://localhost:3000/register
"
,
requestOptions
)
.
then
((
response
)
=>
{
.
then
((
response
)
=>
{
if
(
response
.
status
==
200
){
if
(
response
.
status
==
200
){
console
.
log
(
"
200
"
);
if
(
document
.
getElementById
(
"
divLeer
"
))
{
if
(
document
.
getElementById
(
"
divLeer
"
))
{
console
.
log
(
"
drinne
"
);
console
.
log
(
"
drinne
"
);
...
@@ -76,6 +75,15 @@
...
@@ -76,6 +75,15 @@
document
.
body
.
appendChild
(
button
);
document
.
body
.
appendChild
(
button
);
}
}
else
if
(
response
.
status
==
401
)
{
username
.
value
=
""
;
password
.
value
=
""
;
var
divVergeben
=
document
.
createElement
(
'
div
'
);
divVergeben
.
textContent
=
"
Der Nutzername ist bereits vergeben, bitte versuche es erneut.
"
;
document
.
body
.
appendChild
(
divVergeben
);
}
})
})
.
catch
(
error
=>
console
.
log
(
'
error
'
,
error
));
.
catch
(
error
=>
console
.
log
(
'
error
'
,
error
));
...
@@ -92,68 +100,6 @@
...
@@ -92,68 +100,6 @@
}
}
}
}
/* // Check if input Login and Password are empty
//
if (username.value.trim().length && password.value.trim().length === 0) {
username.value = "";
password.value = "";
var div = document.createElement('div');
div.textContent = "Bitte fülle beide Felder aus";
document.body.appendChild(div);
}
console.log(username, password);
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"name": username.value.trim(),
"password": password.value.trim()
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("http://localhost:3000/register", requestOptions)
.then((response) => {
if(response.status == 200){
console.log("200");
var div = document.createElement('div');
div.textContent = "Erfolgreich registriert!";
document.body.appendChild(div);
const button = document.createElement("button");
button.innerText = "Zum Login";
button.type = "submit";
button.name = "button";
button.classList.add("button");
button.addEventListener("click", () => {
window.location.href = "/login";
});
document.body.appendChild(button);
}
})
.catch(error => console.log('error', error));
} */
</script>
</script>
</body>
</body>
...
...
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