246 lines
5.8 KiB
C++
246 lines
5.8 KiB
C++
#include "StdAfx.h"
|
|
#include ".\userinfoparser.h"
|
|
#include "UserInfo.h"
|
|
#include "AccessInfoParser.h"
|
|
|
|
UserInfoParser::UserInfoParser(void)
|
|
{
|
|
m_XMLParser.Init();
|
|
m_mapUserInfo.clear();
|
|
m_ObjKeyGenerator.Create( 1, 1000 );
|
|
}
|
|
|
|
UserInfoParser::~UserInfoParser(void)
|
|
{
|
|
UnLoad();
|
|
}
|
|
|
|
VOID UserInfoParser::UnLoad()
|
|
{
|
|
UserInfo * pUserInfo = NULL;
|
|
for( USER_INFO_MAP_ITER it = m_mapUserInfo.begin(); it != m_mapUserInfo.end(); ++it )
|
|
{
|
|
pUserInfo = it->second;
|
|
|
|
if( pUserInfo )
|
|
{
|
|
delete pUserInfo;
|
|
pUserInfo = NULL;
|
|
}
|
|
}
|
|
|
|
m_mapUserInfo.clear();
|
|
}
|
|
|
|
BOOL UserInfoParser::Load( char* pszFileName )
|
|
{
|
|
if( !m_XMLParser.Load( pszFileName ) )
|
|
return FALSE;
|
|
|
|
long nUserNum = 0;
|
|
NODELISTPtr pUserNodeList = m_XMLParser.FindNodeList( L"//USER", nUserNum );
|
|
if( pUserNodeList == NULL )
|
|
return FALSE;
|
|
|
|
DWORD dwGUID = 0;
|
|
std::string strID, strPass, strIP;
|
|
BYTE byGrade = 0;
|
|
|
|
for( int i = 0; i < nUserNum; i++ )
|
|
{
|
|
NODEPtr pUserNode = m_XMLParser.FindNode( pUserNodeList, i );
|
|
if( pUserNode == NULL ) continue;
|
|
|
|
dwGUID = 0;
|
|
strID.clear();
|
|
strPass.clear();
|
|
byGrade = 0;
|
|
strIP.clear();
|
|
|
|
if( !m_XMLParser.GetAttriDataDWORD( pUserNode, L"GUID", dwGUID ) ) continue;
|
|
if( !m_XMLParser.GetAttriDataStr( pUserNode, L"ID", strID ) ) continue;
|
|
if( !m_XMLParser.GetAttriDataStr( pUserNode, L"PASSWORD", strPass ) ) continue;
|
|
if( !m_XMLParser.GetAttriDataBYTE( pUserNode, L"RIGHT", byGrade ) ) continue;
|
|
if( !m_XMLParser.GetAttriDataStr( pUserNode, L"IP", strIP ) ) continue;
|
|
|
|
if( GetUserInfo( strID.c_str() ) )
|
|
{
|
|
FASSERT( !"데이터에 오류가 있습니다." );
|
|
return FALSE;
|
|
}
|
|
|
|
// 유저계정을 추가한다.
|
|
UserInfo *pUserInfo = new UserInfo;
|
|
pUserInfo->SetUserGUID( dwGUID );
|
|
pUserInfo->SetUserID( strID.c_str() );
|
|
pUserInfo->SetUserPassWord( strPass.c_str() );
|
|
pUserInfo->SetUserGrade( byGrade );
|
|
pUserInfo->SetUserIP( strIP.c_str() );
|
|
|
|
m_ObjKeyGenerator.ReserveKey( dwGUID );
|
|
|
|
m_mapUserInfo.insert( std::make_pair( strID.c_str(), pUserInfo ) );
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL UserInfoParser::AddNewUser( const char* pszID, const char* pszPass, BYTE byGrade, const char* pszIP )
|
|
{
|
|
if( !pszID || !pszPass || !pszIP || byGrade >= USER_GRADE_MAX || byGrade <= USER_GRADE_NONE )
|
|
return FALSE;
|
|
|
|
//새로운 유저 생성
|
|
UserInfo *pNewUser = new UserInfo;
|
|
pNewUser->SetUserID( pszID );
|
|
pNewUser->SetUserPassWord( pszPass );
|
|
pNewUser->SetUserGrade( byGrade );
|
|
pNewUser->SetUserIP( pszIP );
|
|
|
|
DWORD dwGUID = m_ObjKeyGenerator.GetKey();
|
|
pNewUser->SetUserGUID( dwGUID );
|
|
|
|
// 파일에 추가
|
|
ELEMENTPtr pNewElem = m_XMLParser.InsertElement( L"//USER_INFO", L"USER" );
|
|
if( pNewElem )
|
|
{
|
|
if( !m_XMLParser.SetAttributeDWORD( pNewElem, L"GUID", pNewUser->GetUserGUID() ) ) return FALSE;
|
|
if( !m_XMLParser.SetAttributeStr( pNewElem, L"ID", pNewUser->GetUserID() ) ) return FALSE;
|
|
if( !m_XMLParser.SetAttributeStr( pNewElem, L"PASSWORD", pNewUser->GetUserPassWord() ) ) return FALSE;
|
|
if( !m_XMLParser.SetAttributeBYTE( pNewElem, L"RIGHT", pNewUser->GetUserGrade() ) ) return FALSE;
|
|
if( !m_XMLParser.SetAttributeStr( pNewElem, L"IP", pNewUser->GetUserIP() ) ) return FALSE;
|
|
}
|
|
|
|
m_XMLParser.Save();
|
|
|
|
m_mapUserInfo.insert( std::make_pair( pszID, pNewUser) );
|
|
|
|
// 유저가 추가되면 AccssInfoParser에 새로운 유저를 하나 추가해야 한다.
|
|
AccessInfoParser::Instance()->InsertUser( pNewUser->GetUserGUID() );
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
UserInfo * UserInfoParser::GetUserInfo( const char * pszID, const char* pszPass, const char* pszIP )
|
|
{
|
|
if( !pszID || !pszPass || !pszIP )
|
|
return NULL;
|
|
|
|
UserInfo* pUserInfo = GetUserInfo( pszID );
|
|
|
|
if( pUserInfo )
|
|
{
|
|
if( strcmp( pUserInfo->GetUserPassWord(), pszPass ) != 0 )
|
|
return NULL;
|
|
|
|
if( strcmp( pUserInfo->GetUserIP(), pszIP ) != 0 )
|
|
return NULL;
|
|
|
|
return pUserInfo;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|
|
UserInfo * UserInfoParser::GetUserInfo( const char * pszID )
|
|
{
|
|
USER_INFO_MAP_ITER iter = m_mapUserInfo.find( pszID );
|
|
if( iter != m_mapUserInfo.end() )
|
|
{
|
|
UserInfo* pUserInfo = iter->second;
|
|
if( pUserInfo )
|
|
return pUserInfo;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|
|
UserInfo* UserInfoParser::GetUserInfo( DWORD dwUserGuid )
|
|
{
|
|
USER_INFO_MAP_ITER iter = NULL;
|
|
for( iter = m_mapUserInfo.begin(); iter != m_mapUserInfo.end() ; ++iter )
|
|
{
|
|
UserInfo* pUserInfo = iter->second;
|
|
if( !pUserInfo ) continue;
|
|
|
|
if( pUserInfo->GetUserGUID() == dwUserGuid )
|
|
return pUserInfo;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|
|
VOID UserInfoParser::GetUserIDTotalInfo( USER_ID_TOTAL_INFO& TotalInfo )
|
|
{
|
|
TotalInfo.m_wCount = 0;
|
|
|
|
USER_INFO_MAP_ITER iter = NULL;
|
|
for( iter = m_mapUserInfo.begin(); iter != m_mapUserInfo.end() ; ++iter )
|
|
{
|
|
UserInfo* pUserInfo = iter->second;
|
|
if( !pUserInfo ) continue;
|
|
|
|
_tcsncpy( TotalInfo.m_szUserID[TotalInfo.m_wCount], (TCHAR*)pUserInfo->GetUserID(), MAX_USERID_SIZE );
|
|
TotalInfo.m_wCount++;
|
|
}
|
|
}
|
|
|
|
BOOL UserInfoParser::ModifyPassword( const TCHAR* pszID, const TCHAR* pszModifyPass )
|
|
{
|
|
UserInfo* pUserInfo = GetUserInfo( pszID );
|
|
if( !pUserInfo ) return FALSE;
|
|
|
|
//1. 메모리상의 값 변경
|
|
pUserInfo->SetUserPassWord( pszModifyPass );
|
|
|
|
return _ModifyPassword( pUserInfo->GetUserID(), pszModifyPass );
|
|
}
|
|
|
|
BOOL UserInfoParser::ModifyPassword( DWORD dwUserKey, const TCHAR* pszModifyPass )
|
|
{
|
|
UserInfo* pUserInfo = GetUserInfo( dwUserKey );
|
|
if( !pUserInfo ) return FALSE;
|
|
|
|
//1. 메모리상의 값 변경
|
|
pUserInfo->SetUserPassWord( pszModifyPass );
|
|
|
|
return _ModifyPassword( pUserInfo->GetUserID(), pszModifyPass );
|
|
}
|
|
|
|
BOOL UserInfoParser::_ModifyPassword( const TCHAR* pszID, const TCHAR* pszModifyPass )
|
|
{
|
|
//2. XML파일 변경
|
|
_variant_t varID, varPass;
|
|
varID.ChangeType( VT_BSTR );
|
|
varID.bstrVal = _com_util::ConvertStringToBSTR( pszID );
|
|
varPass.ChangeType( VT_BSTR );
|
|
varPass.bstrVal = _com_util::ConvertStringToBSTR( pszModifyPass );
|
|
|
|
if( !m_XMLParser.UpdateElement( "USER", "ID", varID, "PASSWORD", varPass ) )
|
|
return FALSE;
|
|
|
|
if( !m_XMLParser.Save() ) return FALSE;
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|