Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GitBull
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
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
EIP
Labrador
GitBull
Merge requests
!4
Resolve "Move functionality from frontend to backend"
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
Resolve "Move functionality from frontend to backend"
30-move-functionality-from-frontend-to-backend
into
cleanup
Overview
0
Commits
19
Pipelines
12
Changes
36
Merged
Resolve "Move functionality from frontend to backend"
Elena Uleia
requested to merge
30-move-functionality-from-frontend-to-backend
into
cleanup
Sep 28, 2023
Overview
0
Commits
19
Pipelines
12
Changes
36
Closes
#30 (closed)
0
0
Merge request reports
Compare
cleanup
version 10
1e4c398b
Oct 18, 2023
version 9
0fafabc8
Oct 12, 2023
version 8
4544ba3e
Oct 12, 2023
version 7
69df26aa
Oct 11, 2023
version 6
5f42eed2
Oct 10, 2023
version 5
923c32d6
Oct 10, 2023
version 4
7f9c6233
Oct 9, 2023
version 3
e87286a8
Oct 8, 2023
version 2
51d87faa
Oct 7, 2023
version 1
73cc6dda
Oct 2, 2023
cleanup (base)
and
latest version
latest version
4146d0b1
19 commits,
Oct 19, 2023
version 10
1e4c398b
16 commits,
Oct 18, 2023
version 9
0fafabc8
15 commits,
Oct 12, 2023
version 8
4544ba3e
14 commits,
Oct 12, 2023
version 7
69df26aa
13 commits,
Oct 11, 2023
version 6
5f42eed2
12 commits,
Oct 10, 2023
version 5
923c32d6
9 commits,
Oct 10, 2023
version 4
7f9c6233
8 commits,
Oct 9, 2023
version 3
e87286a8
6 commits,
Oct 8, 2023
version 2
51d87faa
5 commits,
Oct 7, 2023
version 1
73cc6dda
4 commits,
Oct 2, 2023
36 files
+
2842
−
940
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
36
backend/src/main/java/server/controller/AccountController.java
0 → 100644
+
87
−
0
View file @ 4146d0b1
Edit in single-file editor
Open in Web IDE
package
server.controller
;
import
nl.tudelft.labracore.lib.security.user.AuthenticatedPerson
;
import
nl.tudelft.labracore.lib.security.user.Person
;
import
org.gitlab4j.api.GitLabApi
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.*
;
import
server.service.AccountService
;
import
server.service.InstanceMappingService
;
@Controller
@RequestMapping
(
"account"
)
public
class
AccountController
{
@Autowired
private
AccountService
accountService
;
@Autowired
private
InstanceMappingService
instanceMappingService
;
@GetMapping
()
public
String
getAccount
(
Model
model
,
@AuthenticatedPerson
Person
person
)
{
String
netId
=
person
.
getUsername
();
GitLabApi
gitLabApi
=
instanceMappingService
.
getInstance
(
netId
);
if
(
gitLabApi
==
null
)
{
model
.
addAttribute
(
"message"
,
"You do not have any key."
);
}
else
{
model
.
addAttribute
(
"message"
,
"You already have a key."
);
}
return
"account"
;
}
/**
* POST endpoint to add a GitLab API key to an existing user.
*
* @param apiKey String containing the key to be added.
*/
@PostMapping
(
"/addKey"
)
public
String
addKey
(
@AuthenticatedPerson
Person
person
,
Model
model
,
@RequestParam
(
value
=
"apiKey"
)
String
apiKey
)
{
//String currentUser = gitBullSecurity.getCurrentUsername(apiKeyDTO.getSecret());
String
netId
=
person
.
getUsername
();
if
(
apiKey
==
null
)
{
model
.
addAttribute
(
"message"
,
"You need to enter a key first."
);
return
"redirect:/account"
;
}
accountService
.
addAPIKey
(
netId
,
apiKey
);
instanceMappingService
.
addInstance
(
netId
,
apiKey
);
model
.
addAttribute
(
"message"
,
"The key was added. You may go back."
);
return
"redirect:/account"
;
}
// TODO : look into override a get method with a delete
/**
* GET endpoint to remove the GitLab API key of an existing user.
*
*/
@GetMapping
(
"/removeKey"
)
public
String
removeKey
(
@AuthenticatedPerson
Person
person
,
Model
model
)
{
//String currentUser = gitBullSecurity.getCurrentUsername(apiKeyDTO.getSecret());
String
netId
=
person
.
getUsername
();
GitLabApi
gitLabApi
=
instanceMappingService
.
getInstance
(
netId
);
if
(
gitLabApi
==
null
)
return
"redirect:/account"
;
accountService
.
removeAPIKey
(
netId
);
instanceMappingService
.
removeInstance
(
netId
);
model
.
addAttribute
(
"message"
,
"Key successfully deleted."
);
return
"redirect:/account"
;
}
}
Loading