Fix fatal error while twice installations

pull/151/head
johnniang 2019-05-10 11:28:27 +08:00
parent 8c05ea1ad5
commit 9d3f409fb6
3 changed files with 15 additions and 6 deletions

View File

@ -16,24 +16,22 @@ import run.halo.app.model.entity.BaseComment;
import run.halo.app.model.entity.Category;
import run.halo.app.model.entity.Post;
import run.halo.app.model.entity.User;
import run.halo.app.model.enums.AttachmentType;
import run.halo.app.model.enums.LogType;
import run.halo.app.model.enums.PostStatus;
import run.halo.app.model.params.*;
import run.halo.app.model.properties.*;
import run.halo.app.model.properties.BlogProperties;
import run.halo.app.model.properties.PrimaryProperties;
import run.halo.app.model.properties.PropertyEnum;
import run.halo.app.model.support.BaseResponse;
import run.halo.app.model.support.CreateCheck;
import run.halo.app.service.*;
import run.halo.app.utils.ValidationUtils;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import static run.halo.app.model.support.HaloConst.DEFAULT_THEME_ID;
/**
* Installation controller.
*
@ -196,6 +194,8 @@ public class InstallController {
return userService.getCurrentUser().map(user -> {
// Update this user
installParam.update(user);
// Set password manually
userService.setPassword(user, installParam.getPassword());
// Update user
return userService.update(user);
}).orElseGet(() -> userService.createBy(installParam));

View File

@ -125,4 +125,12 @@ public interface UserService extends CrudService<User, Integer> {
* @return true if the given password is match the user password; false otherwise
*/
boolean passwordMatch(@NonNull User user, @Nullable String plainPassword);
/**
* Set user password.
*
* @param user user must not be null
* @param plainPassword plain password must not be blank
*/
void setPassword(@NonNull User user, @NonNull String plainPassword);
}

View File

@ -252,7 +252,8 @@ public class UserServiceImpl extends AbstractCrudService<User, Integer> implemen
return updatedUser;
}
private void setPassword(@NonNull User user, @NonNull String plainPassword) {
@Override
public void setPassword(@NonNull User user, @NonNull String plainPassword) {
Assert.notNull(user, "User must not be null");
Assert.hasText(plainPassword, "Plain password must not be blank");