Last change
on this file since 62bba0c was 57e58a3, checked in by ste08 <sjovanoska@…>, 4 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | package com.example.skychasemk.controller;
|
---|
2 |
|
---|
3 | import org.springframework.http.HttpStatus;
|
---|
4 | import org.springframework.http.ResponseEntity;
|
---|
5 | import org.springframework.web.bind.annotation.*;
|
---|
6 |
|
---|
7 | @RestController
|
---|
8 | @RequestMapping("/api/admin")
|
---|
9 | public class AdminController {
|
---|
10 |
|
---|
11 | @PostMapping("/login")
|
---|
12 | public ResponseEntity<String> login(@RequestBody LoginRequest loginRequest) {
|
---|
13 | String adminUsername = "admin";
|
---|
14 | String adminPassword = "$2a$10$P5S8cnJUlD4lY8dScpmBr.xM4z8rhqI.IVQ/Rz7Ys3AmwPkdMFt8i";
|
---|
15 |
|
---|
16 | // Validate username and password
|
---|
17 | if (adminUsername.equals(loginRequest.getUsername())) {
|
---|
18 | return ResponseEntity.ok("Login successful");
|
---|
19 | }
|
---|
20 |
|
---|
21 | // Authentication failed
|
---|
22 | return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Invalid credentials");
|
---|
23 | }
|
---|
24 |
|
---|
25 | // Class to map the login request body
|
---|
26 | public static class LoginRequest {
|
---|
27 | private String username;
|
---|
28 | private String password;
|
---|
29 |
|
---|
30 | // Getters and Setters
|
---|
31 | public String getUsername() {
|
---|
32 | return username;
|
---|
33 | }
|
---|
34 |
|
---|
35 | public void setUsername(String username) {
|
---|
36 | this.username = username;
|
---|
37 | }
|
---|
38 |
|
---|
39 | public String getPassword() {
|
---|
40 | return password;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public void setPassword(String password) {
|
---|
44 | this.password = password;
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.