mirror of
https://github.com/HangarMC/Hangar.git
synced 2025-01-30 14:30:08 +08:00
change user tagline
This commit is contained in:
parent
496b2cf85d
commit
8225bf30ed
@ -1,11 +1,13 @@
|
||||
package me.minidigger.hangar.controller;
|
||||
|
||||
import me.minidigger.hangar.util.AlertUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
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.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
@ -16,7 +18,6 @@ import me.minidigger.hangar.config.HangarConfig;
|
||||
import me.minidigger.hangar.db.dao.HangarDao;
|
||||
import me.minidigger.hangar.db.dao.UserDao;
|
||||
import me.minidigger.hangar.db.model.UsersTable;
|
||||
import me.minidigger.hangar.model.viewhelpers.UserData;
|
||||
import me.minidigger.hangar.service.AuthenticationService;
|
||||
import me.minidigger.hangar.service.UserService;
|
||||
|
||||
@ -112,16 +113,19 @@ public class UsersController extends HangarController {
|
||||
}
|
||||
|
||||
@RequestMapping("/{user}")
|
||||
public Object showProjects(@PathVariable String user) {
|
||||
public ModelAndView showProjects(@PathVariable String user) {
|
||||
UsersTable dbUser = userDao.get().getByName(user);
|
||||
return showProjects(dbUser);
|
||||
}
|
||||
|
||||
private ModelAndView showProjects(UsersTable dbUser) {
|
||||
if (dbUser == null) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
ModelAndView mav = new ModelAndView("users/projects");
|
||||
mav.addObject("u", userService.getUserData(dbUser));
|
||||
mav.addObject("o", null);
|
||||
return fillModel(mav); // TODO implement showProjects request controller
|
||||
return fillModel(mav);
|
||||
}
|
||||
|
||||
@RequestMapping("/{user}/settings/apiKeys")
|
||||
@ -134,9 +138,18 @@ public class UsersController extends HangarController {
|
||||
return null; // TODO implement setLocked request controller
|
||||
}
|
||||
|
||||
@RequestMapping("/{user}/settings/tagline")
|
||||
public Object saveTagline(@PathVariable Object user) {
|
||||
return null; // TODO implement saveTagline request controller
|
||||
@RequestMapping(value = "/{user}/settings/tagline", method = RequestMethod.POST)
|
||||
public ModelAndView saveTagline(@PathVariable String user, @RequestParam("tagline") String tagline) {
|
||||
if (tagline.length() > hangarConfig.getMaxTaglineLen()) {
|
||||
ModelAndView mav = showProjects(user);
|
||||
AlertUtil.showAlert(mav, AlertUtil.ERROR, "error.tagline.tooLong"); // TODO pass length param to key
|
||||
return showProjects(user);
|
||||
}
|
||||
// TODO user action log
|
||||
UsersTable usersTable = userDao.get().getByName(user);
|
||||
usersTable.setTagline(tagline);
|
||||
usersTable = userDao.get().update(usersTable);
|
||||
return showProjects(usersTable);
|
||||
}
|
||||
|
||||
@RequestMapping("/{user}/sitemap.xml")
|
||||
|
@ -25,6 +25,10 @@ public interface UserDao {
|
||||
@GetGeneratedKeys
|
||||
UsersTable insert(@BindBean UsersTable user);
|
||||
|
||||
@SqlUpdate("UPDATE users SET full_name = :fullName, name = :name, email = :email, tagline = :tagline, read_prompts = :readPrompts, is_locked = :isLocked, language = :language WHERE id = :id")
|
||||
@GetGeneratedKeys
|
||||
UsersTable update(@BindBean UsersTable user);
|
||||
|
||||
@SqlQuery("select * from users where id = :id")
|
||||
UsersTable getById(long id);
|
||||
|
||||
|
@ -117,6 +117,10 @@ public class UsersTable implements Serializable {
|
||||
return isLocked;
|
||||
}
|
||||
|
||||
public boolean getIsLocked() {
|
||||
return isLocked;
|
||||
} // Apparently the userDao didn't like not having this?
|
||||
|
||||
public void setIsLocked(boolean isLocked) {
|
||||
this.isLocked = isLocked;
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import java.util.Map;
|
||||
|
||||
public class AlertUtil {
|
||||
|
||||
public static final String ERROR = "error";
|
||||
|
||||
public static ModelAndView showAlert(ModelAndView mav, String alertType, String alertMessage) {
|
||||
Map<String, String> alerts = (Map<String, String>) mav.getModelMap().getAttribute("alerts");
|
||||
if (alerts == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user