A self hosted chat application with end-to-end encrypted messaging.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

60 lines
1.6 KiB

package org.ros.chatto.controller;
import java.util.Optional;
import org.ros.chatto.model.ChatUser;
import org.ros.chatto.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.server.ResponseStatusException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Controller
@RequestMapping("/admin")
@Slf4j
@RequiredArgsConstructor
public class AdminController {
@Autowired
private final UserService userService;
@GetMapping()
public String home() {
return "admin/home";
}
@GetMapping("/change-passphrase")
public String changePassphrase(Model model) {
model.addAttribute("userNames", userService.getAllRegularUsers());
return "admin/change-passphrase";
}
@GetMapping("/users")
public String usersPage(@RequestParam Optional<String> mode) {
if (mode.isPresent()) {
switch (mode.get()) {
case "new":
return "admin/new-user";
}
}
return "admin/users";
}
@GetMapping("/users/{userName}")
public String userProfile(@PathVariable String userName) {
Optional<ChatUser> maybeUser = userService.getUser(userName);
if (!maybeUser.isPresent()) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND,
"Requested user does not exist");
}
return "admin/user-profile";
}
}