⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 user.cpp

📁 基于Nuleus操作系统和s3c4510的编写的EFC。已经包含了该EFC的设计说明。这是个实际产品的代码
💻 CPP
字号:
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2003, Ulink Telecom Equipment Co., Ltd. All rights reserved.
//
// File:
//
//    User.cpp
//
// Abstract:
//
//    implementation of the CUser class.
//
// History:
//
//    V1.0	2003-03-07	Alex Duan	Original version.
//    V1.1	2003-04-14	Alex Duan	Add ">>" & "<<" operators
//    V1.2	2003-11-12	Alex Duan	Replace >>/<< with OnSaveData/OnLoadData
//
///////////////////////////////////////////////////////////////////////////////
#ifdef __EFC_MASTER // Added by xbz

#include "User.h"
#include "APPCORE.H"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CUser::CUser()
{
}

CUser::~CUser()
{
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszUser	user name
//		lpszPswd	password
//		uLevel		access level
//		lpszDesc	description of the user
// Remarks:
//		Add an user to the system user table. If the user does not exist, then 
//		creates	one, else modifies the parameters of the user.
void CUser::AddUser(LPCSTR lpszUser, LPCSTR lpszPswd, BYTE uLevel, LPCSTR lpszDesc)
{
	ASSERT(lpszUser);

	USER user;
	user.strUser = lpszUser;
	user.strPswd = lpszPswd;
	user.strDesc = lpszDesc;
	user.uLevel  = uLevel;
	AddUser(user);
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		user	an USER structure data
// Remarks:
//		Add an user to the system user table. If the user does not exist, then 
//		creates	one, else modifies the parameters of the user.
void CUser::AddUser(const USER &user)
{
	m_mapUsers.SetAt(user.strUser, *(USER*)&user);
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszUser	user name
//		user		[out]the found USER object
// Return Value:
//		TRUE if found, else FALSE
// Remarks:
//		Find the user in the system user table.
BOOL CUser::Find(LPCSTR lpszUser, USER &user) const
{
	ASSERT(lpszUser);

	return m_mapUsers.Lookup(lpszUser, user);
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszUser	Name of the user
// Return Value:
//		TRUE if successful, else FALSE.
// Remarks:
//		Removes the specified user
BOOL CUser::Remove(LPCSTR lpszUser)
{
	ASSERT(lpszUser);

	return m_mapUsers.RemoveKey(lpszUser);
}

// loads users
void CUser::OnLoadData()
{
	CString strValue, strEntry;
	USER user;
	///////////////////////////////////////////////////////////////////////////
	// user record example:
	// user1=dvlp,dvlp,1
	///////////////////////////////////////////////////////////////////////////
	for (int i = 1; ;i++)
	{
		strEntry.Format("user%d", i);
		strValue = GetApp()->GetProfileString("Users", strEntry);
		if (strValue.IsEmpty())
		{
			if (i > 5)
				break;
			else
				continue;
		}
		user.strUser = strValue.Mid("", ",");
		user.strPswd = strValue.Mid(',', ',');
		if(user.strPswd.GetLength() == 0)
		{
			user.strPswd = "";
		}
		strValue = strValue.Mid(strValue.ReverseFind(',') + 1);
		user.uLevel = strValue.Toint();
		AddUser(user);
	}

	// Add a super hide user
//	AddUser("Alex", "Duan", 1);
//	GetApp()->SetProfileRights("Users", NULL, ACCESS_LEVEL_DENIED, ACCESS_LEVEL_SUPER);
}

// saves users
void CUser::OnSaveData()
{
	USER user;
	CString strEntry, strValue;
	POSITION pos = m_mapUsers.GetStartPosition();

	for (int i = 1; pos != NULL; i++)
	{
		m_mapUsers.GetNextAssoc(pos, strValue, user);
		if (user.strUser.IsEmpty())
			continue;
		
		strEntry.Format("user%d", i);
		strValue.Format("%s,%s,%d", 
			(LPCSTR)user.strUser, (LPCSTR)user.strPswd, user.uLevel);
		VERIFY(GetApp()->WriteProfileString("Users", strEntry, strValue));
	}
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -