Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
frag.jetzt SWTP 2022
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Privacy
Imprint
Contact
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Marc Tröll
frag.jetzt SWTP 2022
Commits
49f69df0
There was an error fetching the commit references. Please try again later.
Verified
Commit
49f69df0
authored
7 years ago
by
Lukas Maximilian Kimpel
Browse files
Options
Downloads
Patches
Plain Diff
Refactor AuthenticationService to return ClientAuthentication Observables
parent
a1ba1748
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/authentication.service.ts
+27
-14
27 additions, 14 deletions
src/app/authentication.service.ts
with
27 additions
and
14 deletions
src/app/authentication.service.ts
+
27
−
14
View file @
49f69df0
...
...
@@ -6,6 +6,10 @@ import { UserRole } from './user-roles.enum';
import
{
DataStoreService
}
from
'
./data-store.service
'
;
import
{
HttpClient
,
HttpHeaders
}
from
'
@angular/common/http
'
;
import
{
AuthProvider
}
from
'
./auth-provider
'
;
import
{
NotificationService
}
from
'
./notification.service
'
;
import
{
catchError
,
tap
}
from
'
rxjs/operators
'
;
import
{
ErrorHandlingService
}
from
'
./error-handling.service
'
;
import
{
ClientAuthentication
}
from
'
./client-authentication
'
;
// TODO: connect to API
// TODO: persist user data (shouldn't get lost on page refresh)
...
...
@@ -16,9 +20,12 @@ export class AuthenticationService {
private
apiBaseUrl
=
'
https://arsnova-staging.mni.thm.de/api
'
;
private
apiAuthUrl
=
'
/auth
'
;
private
apiLoginUrl
=
'
/login
'
;
private
httpHeaders
=
new
HttpHeaders
({
});
private
httpOptions
=
{
headers
:
new
HttpHeaders
({
'
Content-Type
'
:
'
application/vnd.de.thm.arsnova.v3+json
'
,
'
charset
'
:
'
UTF-8
'
})
};
constructor
(
private
dataStoreService
:
DataStoreService
,
private
http
:
HttpClient
)
{
...
...
@@ -28,19 +35,20 @@ export class AuthenticationService {
}
}
login
(
email
:
string
,
password
:
string
,
role
:
UserRole
):
Observable
<
boolean
>
{
this
.
user
=
new
User
(
'
userId1
'
,
'
loginId1
'
,
AuthProvider
.
ARSNOVA
,
'
TOKEN
'
,
role
);
// Store user data in local storage to retain the data when the user reloads the page
this
.
dataStoreService
.
set
(
this
.
STORAGE_KEY
,
JSON
.
stringify
(
this
.
user
));
return
of
(
true
);
login
(
email
:
string
,
password
:
string
):
Observable
<
ClientAuthentication
>
{
// ToDo: Replace with actual ARSnova details
return
of
({
'
userId
'
:
email
,
'
loginId
'
:
email
+
password
,
'
authProvider
'
:
AuthProvider
.
ARSNOVA
,
'
token
'
:
password
+
email
+
password
}
as
ClientAuthentication
);
}
guestLogin
()
{
this
.
http
.
post
<
string
>
(
this
.
apiBaseUrl
+
this
.
apiAuthUrl
+
this
.
apiLoginUrl
+
'
/guest
'
,
this
.
httpHeaders
).
subscribe
(
result
=>
{
this
.
user
=
new
User
(
result
[
'
userId
'
],
result
[
'
loginId
'
],
result
[
'
authProvider
'
],
result
[
'
token
'
],
UserRole
.
PARTICIPANT
);
});
return
of
(
false
);
guestLogin
():
Observable
<
ClientAuthentication
>
{
const
connectionUrl
:
string
=
this
.
apiBaseUrl
+
this
.
apiAuthUrl
+
this
.
apiLoginUrl
+
'
/guest
'
;
return
this
.
http
.
post
<
ClientAuthentication
>
(
connectionUrl
,
null
,
this
.
httpOptions
);
}
register
(
email
:
string
,
password
:
string
):
Observable
<
boolean
>
{
...
...
@@ -61,6 +69,11 @@ export class AuthenticationService {
return
this
.
user
;
}
setUser
(
user
:
User
):
void
{
this
.
user
=
user
;
this
.
dataStoreService
.
set
(
this
.
STORAGE_KEY
,
JSON
.
stringify
(
this
.
user
));
}
isLoggedIn
():
boolean
{
return
this
.
user
!==
undefined
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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