Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
profwebfrontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s87777
profwebfrontend
Commits
1caf117d
Commit
1caf117d
authored
1 year ago
by
s87777
Browse files
Options
Downloads
Patches
Plain Diff
User register
parent
2cc6d7df
No related branches found
No related tags found
No related merge requests found
Pipeline
#52127
passed
1 year ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+3
-0
3 additions, 0 deletions
.gitignore
src/backend/userapi.ts
+22
-0
22 additions, 0 deletions
src/backend/userapi.ts
src/components/LoginDialog.tsx
+17
-14
17 additions, 14 deletions
src/components/LoginDialog.tsx
with
42 additions
and
14 deletions
.gitignore
+
3
−
0
View file @
1caf117d
...
...
@@ -21,3 +21,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Ignore kube directory
kube
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/backend/userapi.ts
+
22
−
0
View file @
1caf117d
...
...
@@ -43,6 +43,28 @@ export async function createUser(name: string, email: string, password: string,
}
}
export
async
function
registerUser
(
name
:
string
,
email
:
string
,
password
:
string
):
Promise
<
any
>
{
const
url
=
`
${
HOST
}
/api/user/register`
;
// eslint-disable-next-line no-useless-catch
try
{
const
response
:
Response
=
await
fetch
(
url
,
{
method
:
"
POST
"
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
},
body
:
JSON
.
stringify
({
name
,
email
,
password
}),
})
if
(
response
.
ok
){
const
userResource
:
UserResource
=
await
response
.
json
();
return
userResource
;
}
else
if
(
response
.
status
===
400
){
throw
new
Error
(
"
Invalid email or password
"
);
}
}
catch
(
err
){
throw
(
err
);
}
}
export
async
function
deleteUser
(
userId
:
string
):
Promise
<
void
>
{
// eslint-disable-next-line no-useless-catch
try
{
...
...
This diff is collapsed.
Click to expand it.
src/components/LoginDialog.tsx
+
17
−
14
View file @
1caf117d
import
React
from
'
react
'
;
import
{
Fragment
,
useState
}
from
"
react
"
;
import
{
useState
}
from
"
react
"
;
import
{
Alert
,
Form
,
Modal
}
from
"
react-bootstrap
"
;
import
{
Button
}
from
"
react-bootstrap
"
;
import
{
login
}
from
"
../backend/shopperapi
"
;
import
{
getLoginInfoFromJWT
,
storeJWT
}
from
"
../JWTManager
"
;
import
{
useLoginContext
}
from
"
../LoginContext
"
;
import
{
c
re
a
teUser
}
from
"
../backend/userapi
"
;
import
{
re
gis
te
r
User
}
from
"
../backend/userapi
"
;
import
ReactGA
from
"
react-ga4
"
;
...
...
@@ -37,9 +37,10 @@ export default function LoginDialog({show, onHide}: LoginDialogProps){
const
doRegistration
=
async
(
e
:
React
.
FormEvent
)
=>
{
e
.
preventDefault
();
try
{
await
c
re
a
teUser
(
username
,
email
,
password
,
false
);
await
re
gis
te
r
User
(
username
,
email
,
password
);
//doLogin(e);
console
.
log
(
"
Registriert
"
);
setMessage
(
"
Registriert
"
);
}
catch
(
err
){
setMessage
(
String
(
err
));
}
...
...
@@ -96,33 +97,35 @@ export default function LoginDialog({show, onHide}: LoginDialogProps){
<
Modal
.
Body
>
<
Form
>
{
registrieren
?
<>
<
Form
.
Group
controlId
=
"formUsername"
>
<
div
>
<
Form
.
Group
>
<
Form
.
Label
>
Username
</
Form
.
Label
>
<
Form
.
Control
id
=
"inputUsername"
type
=
"text"
name
=
"Username"
placeholder
=
"Enter Username"
onChange
=
{
e
=>
setUsername
(
e
.
target
.
value
)
}
/>
</
Form
.
Group
>
<
Form
.
Group
controlId
=
"formUsername"
className
=
"mt-3"
>
<
Form
.
Group
className
=
"mt-3"
>
<
Form
.
Label
>
E-Mail
</
Form
.
Label
>
<
Form
.
Control
id
=
"inputEmail"
type
=
"text"
name
=
"Email"
placeholder
=
"Enter Email"
onChange
=
{
e
=>
setEmail
(
e
.
target
.
value
)
}
/>
</
Form
.
Group
>
<
br
/>
<
Form
.
Group
controlId
=
"formPassword"
>
<
Form
.
Group
>
<
Form
.
Label
>
Passwort
</
Form
.
Label
>
<
Form
.
Control
id
=
"inputPassword"
type
=
"password"
name
=
"pass"
placeholder
=
"Enter password"
onChange
=
{
e
=>
setPassword
(
e
.
target
.
value
)
}
/>
</
Form
.
Group
>
<
br
/>
</>
</
div
>
:
<>
<
Form
.
Group
controlId
=
"formUsername"
>
<
div
>
<
Form
.
Group
>
<
Form
.
Label
>
E-Mail
</
Form
.
Label
>
<
Form
.
Control
id
=
"inputEmail"
type
=
"text"
name
=
"Email"
placeholder
=
"Enter Email"
onChange
=
{
e
=>
setEmail
(
e
.
target
.
value
)
}
/>
</
Form
.
Group
>
<
br
/>
<
Form
.
Group
controlId
=
"formPassword"
>
<
Form
.
Group
>
<
Form
.
Label
>
Passwort
</
Form
.
Label
>
<
Form
.
Control
id
=
"inputPassword"
type
=
"password"
name
=
"pass"
placeholder
=
"Enter password"
onChange
=
{
e
=>
setPassword
(
e
.
target
.
value
)
}
/>
</
Form
.
Group
>
<
br
/>
</
>
</
div
>
}
{
message
!==
""
&&
...
...
@@ -136,16 +139,16 @@ export default function LoginDialog({show, onHide}: LoginDialogProps){
</
Modal
.
Body
>
<
Modal
.
Footer
style
=
{
{
display
:
"
flex
"
}
}
>
{
registrieren
?
<>
<
div
>
<
Button
variant
=
"success"
onClick
=
{
doRegistration
}
>
Registrieren
</
Button
>
<
Button
variant
=
"secondary"
onClick
=
{
hideRegistration
}
>
Cancel
</
Button
>
</>
</
div
>
:
<>
<
div
>
<
Button
variant
=
"success"
onClick
=
{
showRegistration
}
>
Noch keinen Account? Hier Registrieren!
</
Button
>
<
Button
variant
=
"secondary"
onClick
=
{
hideRegistration
}
>
Cancel
</
Button
>
<
Button
id
=
"okButton"
variant
=
"primary"
onClick
=
{
doLogin
}
>
OK
</
Button
>
</>
</
div
>
}
</
Modal
.
Footer
>
</
form
>
...
...
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
register
or
sign in
to comment