Home  >  Article  >  Backend Development  >  BBS design based on mysql (3)_PHP tutorial

BBS design based on mysql (3)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:03:261096browse

4. User module design
For the underlying database, the C API function of mysql is called to modify the database, and
certain state variables are saved internally (such as user name, or is it left to the upper layer?), and the upper layer is , then provide
user management interface.
Class UserManage {
private:
char myuserid[20]; // The user’s id, which is empty before logging in
time logintime; // The user’s login time is used to calculate the stay time
char loginhost[20]; //Site location.

public:
int NewUser( char *userid, char *passwd );
Create a new user and determine whether it already exists. Other information is temporarily empty.
Firstlogintime, permissions, etc. are set to be blank. Save value.
int UserLogin( char *userid, char *passwd );
User login, verify password,
int ChangePasswd( char *oldpasswd, char *newpasswd );
Modify the password, the original password is required to be consistent.
int ChangePriData( char *newname, char *newemail,
char *newaddr );
Change basic data, name, email, address. . . .
int ModifyNumData( int addlogin, int addpost );
Modify the number of articles, the number of visits to the site, and other data. . . . Pay attention to the calling object.
int UserLogout();
User logout, modify lastlogin, staytime, loginhost, etc.

// Ordinary query command
int QueryCommonData( const char * userid, int& loginnum,
char * username, int& postnum,
time& lastlogin, char *lasthost );
Query basic information of netizens.

// Privilege instruction, the function first determines the permissions before completing the function.
int QueryPriData( const char * userid, char *email,
char *addr );
Query basic information, ordinary people can only check themselves, and those with privileges can check other people.
int ModifyUserLevel( BOOL isAdd, unsigned long level);
Modify user permissions,
int ModifyUserId( char *oldid, char *newid );
char *newemail, char *newaddr );
Modify the user’s basic data.
int ModifyUserNumdata(char *userid, int addlogin, int addpost);
Modify the user’s number of articles and other data.
int ModifyUserPasswd(char *userid, char *newpasswd);
Modify the user's password.
}
Each of the above functions is not difficult. They all execute corresponding sql statements and access the mysql database.
Should general instructions be classified as privileged instructions? Should the permission check be placed at this level or the previous level?
This is more about the focus of consideration, whether it is the clarity of the program or the simplicity of the code. It may be
Look at the code. After all, the number of visits must be considered. In addition, whether the upper service layer should also consider permissions. Check
What about the problem?

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316256.htmlTechArticle4. User module design For the underlying database, the C API function of mysql is called to modify the database, and certain state variables (such as user names) are stored internally, which is left to the upper layer to complete...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn