禁止同一用户 多次登录

void startupPost()
{
    int         counter;
    int         maxUserSessions = 1;
    int         maxAdminSessions = 4;
    int         num = 0;
    int         maxSessions = Info::licensedUsersTotal();
    xSession    session;
    UserInfo    userInfo;
    UserId      currentUserId;
    UserGroupList   UserGroupList;
    FormRun         formRun;
    ;
    currentUserId = curuserid();
    if (currentUserId == 'Admin')
        return;
    for(counter = 1; counter < maxSessions;counter++ )
    {
        session = new xSession(counter, true);
        if(session && session.userId())
        {
            select firstOnly userInfo
                where userInfo.id == session.userId();
            if (userInfo && (currentUserId == session.userId()))
                num++ ;
        }
    }

    while select userGroupList
        where userGroupList.userId == currentUserId
        && userGroupList.groupId == 'Admin'
        maxUserSessions = maxAdminSessions;

    if (num > maxUserSessions)
        {
        box::stop(strfmt("The same user id can't log in more than %1.", maxUserSessions));
        infolog.shutDown(true);
        }

    if(curuserid() == "MF" || (curuserid() == "AAL"))
    {
        if(!WinAPI::isControlButtonDown() &&
        DEV_AxAssistFunc::checkActiveXRegistered())
        {
            formRun = new MenuFunction(menuItemDisplayStr(DEV_AxAssistForm),MenuItemType::Display).create();
            if(formRun)
            {
                formRun.run();
                formRun.detach();
            }
        }
    }

    if(!WinAPI::isShiftButtonDown())
    {
        // check for user ID
        if(curUserId()=="MF") // <- change to your loginname
        {
            // actually run tabax
            TreeNode::findNode(@'\\Forms\\'+formStr(Tabax)).AOTrun();
        }
    }

}

posted @ 2012-03-01 11:45  perock  阅读(371)  评论(0编辑  收藏  举报