mirror of https://github.com/halo-dev/halo
Prevent to create one more users
parent
4e5694cef0
commit
4635357269
|
@ -5,8 +5,11 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
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.event.logger.LogEvent;
|
||||||
import run.halo.app.exception.BadRequestException;
|
import run.halo.app.exception.BadRequestException;
|
||||||
import run.halo.app.model.entity.*;
|
import run.halo.app.model.entity.*;
|
||||||
|
@ -72,6 +75,7 @@ public class InstallController {
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@CacheLock
|
||||||
public BaseResponse<String> installBlog(@RequestBody @Valid InstallParam installParam) {
|
public BaseResponse<String> installBlog(@RequestBody @Valid InstallParam installParam) {
|
||||||
// TODO Install blog.
|
// TODO Install blog.
|
||||||
// Check is installed
|
// Check is installed
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import run.halo.app.cache.StringCacheStore;
|
import run.halo.app.cache.StringCacheStore;
|
||||||
|
import run.halo.app.cache.lock.CacheLock;
|
||||||
import run.halo.app.event.logger.LogEvent;
|
import run.halo.app.event.logger.LogEvent;
|
||||||
import run.halo.app.exception.BadRequestException;
|
import run.halo.app.exception.BadRequestException;
|
||||||
import run.halo.app.exception.NotFoundException;
|
import run.halo.app.exception.NotFoundException;
|
||||||
|
@ -202,6 +203,17 @@ public class UserServiceImpl extends AbstractCrudService<User, Integer> implemen
|
||||||
return create(user);
|
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
|
@Override
|
||||||
public User update(User user) {
|
public User update(User user) {
|
||||||
User updatedUser = super.update(user);
|
User updatedUser = super.update(user);
|
||||||
|
|
Loading…
Reference in New Issue