Prevent to create one more users

pull/146/head
johnniang 2019-04-28 21:30:33 +08:00
parent 4e5694cef0
commit 4635357269
2 changed files with 18 additions and 2 deletions

View File

@ -5,8 +5,11 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import run.halo.app.cache.lock.CacheLock;
import run.halo.app.event.logger.LogEvent;
import run.halo.app.exception.BadRequestException;
import run.halo.app.model.entity.*;
@ -72,6 +75,7 @@ public class InstallController {
@PostMapping
@ResponseBody
@CacheLock
public BaseResponse<String> installBlog(@RequestBody @Valid InstallParam installParam) {
// TODO Install blog.
// Check is installed

View File

@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import run.halo.app.cache.StringCacheStore;
import run.halo.app.cache.lock.CacheLock;
import run.halo.app.event.logger.LogEvent;
import run.halo.app.exception.BadRequestException;
import run.halo.app.exception.NotFoundException;
@ -202,6 +203,17 @@ public class UserServiceImpl extends AbstractCrudService<User, Integer> implemen
return create(user);
}
@Override
@CacheLock
public User create(User user) {
// Check user
if (count() != 0) {
throw new BadRequestException("This blog already exists a blogger");
}
return super.create(user);
}
@Override
public User update(User user) {
User updatedUser = super.update(user);