package com.casic.missiles.handler;

import com.casic.missiles.core.application.handler.LoginHandler;
import com.casic.missiles.core.model.auth.AuthUser;
import org.apache.shiro.authc.LockedAccountException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class LoginCheckHandler implements LoginHandler {
    @Value("${smartcity.leaderRoleName}")
    private String leaderRoleName;
    @Value("${smartcity.memberRoleName}")
    private String memberRoleName;
    @Value("${smartcity.appRoleName}")
    private String appRoleName;


    @Override
    public Boolean handle(AuthUser authUser) {
        if (authUser.getIsAppLogin()) {
            if (!authUser.getRoleTips().contains(leaderRoleName) && !authUser.getRoleTips().contains(memberRoleName) && !authUser.getRoleTips().contains(appRoleName)) {
                throw new LockedAccountException("当前用户未授权，请联系管理员");
            }
        }
        return true;
    }

}
