package org.dromara.web.service;

import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.model.ForgotLoginBody;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.system.service.ISysUserService;
import org.springframework.stereotype.Service;


@RequiredArgsConstructor
@Service
public class ForgotPasswordService {

    private final ISysUserService userService;


    public boolean forgotPasswordService(ForgotLoginBody loginBody) {
        String verificationCode = StringUtils.isNotBlank(loginBody.getSmsCode())
            ? loginBody.getSmsCode()
            : loginBody.getCode();
        return userService.resetPasswordByVerificationCode(
            loginBody.getUsername(), verificationCode, loginBody.getPassword());
    }
}
