class UserServiceImpl implements UserService {

    @Transactional(readOnly = true)
    @Override
    public User authenticate(String email, String password) throws UserNotFoundException, PasswordNotMatchedException {
        User user = findByEmail(email);
        if (user == null) {
            throw new UserNotFoundException("未找到邮箱为 [" + email + "] 的用户");
        }

        String encPassword = DigestUtils.md5Hex(password);
        if (!encPassword.equalsIgnoreCase(user.getPassword())) {
            throw new PasswordNotMatchedException("用户 [" + email + "] 输入的密码错误");
        }
        return user;
    }

}