Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DBMS inventory manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Shrey Patel
DBMS inventory manager
Commits
da726690
Commit
da726690
authored
1 year ago
by
Sarthak Shrivastava
Browse files
Options
Downloads
Patches
Plain Diff
Added token support for myorgs instead of using user email.
parent
4c074987
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/example/accessingdatamysql/myorg/OrgRosterController.java
+19
-5
19 additions, 5 deletions
...example/accessingdatamysql/myorg/OrgRosterController.java
with
19 additions
and
5 deletions
src/main/java/com/example/accessingdatamysql/myorg/OrgRosterController.java
+
19
−
5
View file @
da726690
package
com.example.accessingdatamysql.myorg
;
import
com.example.accessingdatamysql.User
;
import
com.example.accessingdatamysql.UserRepository
;
import
com.example.accessingdatamysql.auth.AuthController
;
import
com.example.accessingdatamysql.org.Organization
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Optional
;
@CrossOrigin
@RestController
// This means that this class is a Controller
...
...
@@ -19,6 +23,8 @@ public class OrgRosterController {
@Autowired
private
MyOrgRosterRepository
myOrgRosterRepository
;
@Autowired
private
UserRepository
userRepository
;
@GetMapping
(
path
=
"/all"
)
public
@ResponseBody
Iterable
<
OrganizationRoster
>
getOrgs
()
{
...
...
@@ -29,14 +35,22 @@ public class OrgRosterController {
public
@ResponseBody
Map
<
String
,
Object
>
getUsersOrgs
(
@RequestBody
Map
<
String
,
String
>
json
)
{
Map
<
String
,
Object
>
response
=
new
HashMap
<>();
// System.out.println(json.entrySet());
if
(
json
.
containsKey
(
"email"
))
User
found
=
new
User
();
AuthController
au
=
new
AuthController
();
Map
<
String
,
String
>
res
=
au
.
verify
(
json
);
// if the jwt token could not be verified
if
(
res
.
containsKey
(
"login"
)
&&
res
.
get
(
"login"
).
equals
(
"failed"
))
{
response
.
put
(
"result"
,
"failed = bad token or bad request"
);
return
response
;
}
Optional
<
User
>
usr
=
userRepository
.
findById
(
res
.
get
(
"user"
));
if
(!
usr
.
isPresent
())
{
response
.
put
(
"result"
,
"success"
);
response
.
put
(
"data"
,
myOrgRosterRepository
.
findUserOrgs
(
json
.
get
(
"email"
)));
response
.
put
(
"result"
,
"failed = user not found"
);
return
response
;
}
response
.
put
(
"result"
,
"failure - bad request"
);
response
.
put
(
"result"
,
"success"
);
response
.
put
(
"data"
,
myOrgRosterRepository
.
findUserOrgs
(
res
.
get
(
"user"
)));
return
response
;
}
}
...
...
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