Skip to content

Commit 70b2efa

Browse files
authored
Merge pull request #1 from jaiakash/restApi
userController added for login and token verification
2 parents fa8baec + c5599c3 commit 70b2efa

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.akash.springboot.jwt;
2+
3+
import org.springframework.http.ResponseEntity;
4+
import org.springframework.web.bind.annotation.*;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
9+
@RestController
10+
@RequestMapping("/users")
11+
public class UserController {
12+
13+
private Map<String, String> users = new HashMap<>();
14+
15+
@PostMapping("/login")
16+
public ResponseEntity<?> login(@RequestBody Map<String, String> user) {
17+
String username = user.get("username");
18+
String password = user.get("password");
19+
users.put(username, password);
20+
21+
// TODO: Generate JWT token
22+
23+
Map<String, String> response = new HashMap<>();
24+
response.put("token", "demo-token");
25+
26+
return ResponseEntity.ok(response);
27+
}
28+
29+
30+
@PostMapping("/tokenAuthentication")
31+
public ResponseEntity<?> tokenAuthentication(@RequestBody Map<String, String> request) {
32+
String token = request.get("token");
33+
34+
//TODO: Validate token
35+
boolean isValid = true;
36+
37+
Map<String, Boolean> response = new HashMap<>();
38+
response.put("isValid", isValid);
39+
40+
return ResponseEntity.ok(response);
41+
}
42+
}

0 commit comments

Comments
 (0)