| 2 |
* |
* |
| 3 |
* $Revision$ |
* $Revision$ |
| 4 |
* $Log$ |
* $Log$ |
| 5 |
|
* Revision 1.10 2004/11/26 07:57:42 youi |
| 6 |
|
* updateAccount, deleteAccountを定義. |
| 7 |
|
* mysql_query失敗時はstderrへエラーコードとエラーメッセージを出力. |
| 8 |
|
* |
| 9 |
* Revision 1.9 2004/11/26 07:38:02 aga |
* Revision 1.9 2004/11/26 07:38:02 aga |
| 10 |
* ・FAILUE -> FAILURE. |
* ・FAILUE -> FAILURE. |
| 11 |
* |
* |
| 42 |
#include <stdlib.h> |
#include <stdlib.h> |
| 43 |
#include <string.h> |
#include <string.h> |
| 44 |
#include <mysql.h> |
#include <mysql.h> |
| 45 |
|
#include <errmsg.h> |
| 46 |
#include <string> |
#include <string> |
| 47 |
using namespace std; |
using namespace std; |
| 48 |
|
|
| 153 |
* アカウント削除 |
* アカウント削除 |
| 154 |
* |
* |
| 155 |
* @param |
* @param |
| 156 |
* @return |
* @return RES_OK | RES_NO_SUCH_SESSION | RES_DB_QUERY_ERROR |
| 157 |
* |
* |
| 158 |
*/ |
*/ |
| 159 |
result_t deleteAccount( sessionid_t sid, userid_t uid ) |
result_t deleteAccount( sessionid_t sid, userid_t uid ) |
| 160 |
{ |
{ |
| 161 |
return RES_ERROR; |
if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION; |
| 162 |
|
|
| 163 |
|
string sql; |
| 164 |
|
sql = "DELETE FROM " + dbprefix + "_users "; |
| 165 |
|
sql += "WHERE uid = " + string( unsignedIntToString( uid ) ); |
| 166 |
|
if( mysql_query( mysql, sql.c_str( ) ) ){ |
| 167 |
|
fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) ); |
| 168 |
|
return RES_DB_QUERY_ERROR; |
| 169 |
|
} |
| 170 |
|
|
| 171 |
|
sql = "DELETE FROM " + dbprefix + "_vpaccount_users "; |
| 172 |
|
sql += "WHERE uid = " + string( unsignedIntToString( uid ) ); |
| 173 |
|
if( mysql_query( mysql, sql.c_str( ) ) ){ |
| 174 |
|
fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) ); |
| 175 |
|
return RES_DB_QUERY_ERROR; |
| 176 |
|
} |
| 177 |
|
|
| 178 |
|
return RES_OK; |
| 179 |
} |
} |
| 180 |
|
|
| 181 |
/** |
/** |
| 209 |
* アカウント登録 |
* アカウント登録 |
| 210 |
* |
* |
| 211 |
* @param sid セッション |
* @param sid セッション |
| 212 |
* @param |
* @param account 登録するアカウント情報 |
| 213 |
* @return |
* @return RES_OK | RES_NO_SUCH_SESSION | RES_DB_QUERY_ERROR | RES_ERROR |
| 214 |
* |
* |
| 215 |
*/ |
*/ |
| 216 |
result_t insertAccount( sessionid_t sid, const account_t* account ) |
result_t insertAccount( sessionid_t sid, const account_t* account ) |
| 217 |
{ |
{ |
| 218 |
// if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION; |
if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION; |
| 219 |
|
|
| 220 |
string sql; |
string sql; |
| 221 |
string tmp; |
string tmp; |
| 222 |
char buf[ 12 ]; |
char buf[ 12 ]; |
| 264 |
sql += "'" + string( addSlashes( account -> getUserIntrest( ) ) ) + "', "; |
sql += "'" + string( addSlashes( account -> getUserIntrest( ) ) ) + "', "; |
| 265 |
snprintf( buf, 12, "%d", account -> getUserMailok( ) ); |
snprintf( buf, 12, "%d", account -> getUserMailok( ) ); |
| 266 |
sql += string( buf ) + ")"; |
sql += string( buf ) + ")"; |
|
fprintf( stderr, "%s\n", sql.c_str( ) ); |
|
| 267 |
if( mysql_query( mysql, sql.c_str( ) ) ){ |
if( mysql_query( mysql, sql.c_str( ) ) ){ |
| 268 |
|
fprintf( stderr, "%s\n", sql.c_str( ) ); |
| 269 |
|
fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) ); |
| 270 |
return RES_DB_QUERY_ERROR; |
return RES_DB_QUERY_ERROR; |
| 271 |
} |
} |
| 272 |
|
|
| 277 |
} |
} |
| 278 |
|
|
| 279 |
//vpaccountのユーザテーブルに残りの情報を書き込む |
//vpaccountのユーザテーブルに残りの情報を書き込む |
| 280 |
sql = "INSERT INTO " + dbprefix + "_vpaccount_users (uid, activate, address, institute, tel, organization, country, zipcode, fax, base_url, notice_mail, datetime) VALUES ("; |
sql = "INSERT INTO " + dbprefix + "_vpaccount_users (uid, activate, address, institute, tel, organization, country, zipcode, fax, base_url, notice_mail, notice_mail_since) VALUES ("; |
| 281 |
snprintf( buf, 12, "%d", uid ); |
snprintf( buf, 12, "%d", uid ); |
| 282 |
sql += string( buf ) + ", "; |
sql += string( buf ) + ", "; |
| 283 |
if( account -> getActivate() ){ |
if( account -> getActivate() ){ |
| 297 |
sql += string( buf ) + ", "; |
sql += string( buf ) + ", "; |
| 298 |
snprintf( buf, 12, "%d", account -> getNoticeMailSince( ) ); |
snprintf( buf, 12, "%d", account -> getNoticeMailSince( ) ); |
| 299 |
sql += string( buf ) + ")"; |
sql += string( buf ) + ")"; |
|
fprintf( stderr, "%s\n", sql.c_str( ) ); |
|
| 300 |
if( mysql_query( mysql, sql.c_str( ) ) ){ |
if( mysql_query( mysql, sql.c_str( ) ) ){ |
| 301 |
|
fprintf( stderr, "%s\n", sql.c_str( ) ); |
| 302 |
|
fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) ); |
| 303 |
//xoops_usersへinsertしたレコードを削除する |
//xoops_usersへinsertしたレコードを削除する |
| 304 |
sql = "DELETE FROM " + dbprefix + "_users where uid="; |
sql = "DELETE FROM " + dbprefix + "_users where uid="; |
| 305 |
snprintf( buf, 12, "%d", uid ); |
snprintf( buf, 12, "%d", uid ); |
| 306 |
sql += string( buf ); |
sql += string( buf ); |
| 307 |
|
mysql_query( mysql, sql.c_str( ) ); |
| 308 |
return RES_DB_QUERY_ERROR; |
return RES_DB_QUERY_ERROR; |
| 309 |
} |
} |
| 310 |
|
|
| 316 |
* アカウント変更 |
* アカウント変更 |
| 317 |
* |
* |
| 318 |
* @param |
* @param |
| 319 |
* @return |
* @return RES_OK | RES_NO_SUCH_SESSION | RES_DB_QUERY_ERROR |
| 320 |
* |
* |
| 321 |
*/ |
*/ |
| 322 |
result_t updateAccount( sessionid_t sid, const account_t* account ) |
result_t updateAccount( sessionid_t sid, const account_t* account ) |
| 323 |
{ |
{ |
| 324 |
return RES_ERROR; |
if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION; |
| 325 |
|
|
| 326 |
|
string sql; |
| 327 |
|
string tmp; |
| 328 |
|
char buf[ 12 ]; |
| 329 |
|
|
| 330 |
|
//xoopsのユーザテーブルに書き込む |
| 331 |
|
sql = "UPDATE " + dbprefix + "_users SET "; |
| 332 |
|
sql += "uname='" + string( addSlashes( account -> getUname( ) ) ) + "', "; |
| 333 |
|
sql += "name='" + string( addSlashes( account -> getName( ) ) ) + "', "; |
| 334 |
|
sql += "email='" + string( addSlashes( account -> getEmail( ) ) ) + "', "; |
| 335 |
|
sql += "url='" + string( addSlashes( account -> getURL( ) ) ) + "', "; |
| 336 |
|
sql += "user_avatar='" + string( addSlashes( account -> getUserAvatar( ) ) ) + "', "; |
| 337 |
|
sql += "user_regdate=" + string( intToString( account -> getUserRegdate( ) ) ) + ", "; |
| 338 |
|
sql += "user_icq='" + string( addSlashes( account -> getUserIcq( ) ) ) + "', "; |
| 339 |
|
sql += "user_from='" + string( addSlashes( account -> getUserFrom( ) ) ) + "', "; |
| 340 |
|
sql += "user_sig='" + string( addSlashes( account -> getUserSig( ) ) ) + "', "; |
| 341 |
|
sql += "user_viewemail=" + string( intToString( account -> getUserViewemail( ) ) ) + ", "; |
| 342 |
|
sql += "actkey='" + string( addSlashes( account -> getActkey( ) ) ) + "', "; |
| 343 |
|
sql += "user_aim='" + string( addSlashes( account -> getUserAim( ) ) ) + "', "; |
| 344 |
|
sql += "user_yim='" + string( addSlashes( account -> getUserYim( ) ) ) + "', "; |
| 345 |
|
sql += "user_msnm='" + string( addSlashes( account -> getUserMsnm( ) ) ) + "', "; |
| 346 |
|
sql += "pass='" + string( account -> getPass( ) ) + "', "; |
| 347 |
|
sql += "posts=" + string( intToString( account -> getPosts( ) ) ) + ", "; |
| 348 |
|
sql += "attachsig=" + string( intToString( account -> getAttachsig( ) ) ) + ", "; |
| 349 |
|
sql += "rank=" + string( intToString( account -> getRank( ) ) ) + ", "; |
| 350 |
|
sql += "level=" + string( intToString( account -> getLevel( ) ) ) + ", "; |
| 351 |
|
sql += "theme='" + string( addSlashes( account -> getTheme( ) ) ) + "', "; |
| 352 |
|
snprintf( buf, 12, "%.2f", account -> getTimezoneOffset( ) ); |
| 353 |
|
sql += "timezone_offset=" + string( buf ) + ", "; |
| 354 |
|
sql += "last_login=" + string( unsignedIntToString( account -> getLastLogin( ) ) ) + ", "; |
| 355 |
|
sql += "umode='" + string( account -> getUmode( ) ) + "', "; |
| 356 |
|
sql += "uorder=" + string( intToString( account -> getUorder( ) ) ) + ", "; |
| 357 |
|
sql += "notify_method=" + string( intToString( account -> getNotifyMethod( ) ) ) + ", "; |
| 358 |
|
sql += "notify_mode=" + string( intToString( account -> getNotifyMode( ) ) ) + ", "; |
| 359 |
|
sql += "user_occ='" + string( addSlashes( account -> getUserOcc( ) ) ) + "', "; |
| 360 |
|
sql += "bio='" + string( addSlashes( account -> getBio( ) ) ) + "', "; |
| 361 |
|
sql += "user_intrest='" + string( addSlashes( account -> getUserIntrest( ) ) ) + "', "; |
| 362 |
|
sql += "user_mailok=" + string( intToString( account -> getUserMailok( ) ) ); |
| 363 |
|
sql += " WHERE uid = " + string( intToString( account -> getUID( ) ) ); |
| 364 |
|
|
| 365 |
|
if( mysql_query( mysql, sql.c_str( ) ) ){ |
| 366 |
|
fprintf( stderr, "%s\n", sql.c_str( ) ); |
| 367 |
|
fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) ); |
| 368 |
|
return RES_DB_QUERY_ERROR; |
| 369 |
|
} |
| 370 |
|
|
| 371 |
|
//vpaccountのユーザテーブルに残りの情報を上書きする |
| 372 |
|
sql = "UPDATE " + dbprefix + "_vpaccount_users SET "; |
| 373 |
|
sql += "activate="; |
| 374 |
|
if( account -> getActivate() ){ |
| 375 |
|
sql += "1, "; |
| 376 |
|
}else{ |
| 377 |
|
sql += "0, "; |
| 378 |
|
} |
| 379 |
|
sql += "address='" + string( addSlashes( account -> getAddress() ) ) + "', "; |
| 380 |
|
sql += "institute='" + string( addSlashes( account -> getInstitute() ) ) + "', "; |
| 381 |
|
sql += "tel='" + string( addSlashes( account -> getTel() ) ) + "', "; |
| 382 |
|
sql += "organization='" + string( addSlashes( account -> getOrganization() ) ) + "', "; |
| 383 |
|
sql += "country='" + string( addSlashes( account -> getCountry() ) ) + "', "; |
| 384 |
|
sql += "zipcode='" + string( addSlashes( account -> getZipcode() ) ) + "', "; |
| 385 |
|
sql += "fax='" + string( addSlashes( account -> getFax() ) ) + "', "; |
| 386 |
|
sql += "base_url='" + string( addSlashes( account -> getBaseURL() ) ) + "', "; |
| 387 |
|
sql += "notice_mail=" + string( intToString( account -> getNoticeMail( ) ) ) + ", "; |
| 388 |
|
sql += "notice_mail_since=" + string( intToString( account -> getNoticeMailSince( ) ) ); |
| 389 |
|
sql += " WHERE uid = " + string( intToString( account -> getUID( ) ) ); |
| 390 |
|
|
| 391 |
|
if( mysql_query( mysql, sql.c_str( ) ) ){ |
| 392 |
|
fprintf( stderr, "%s\n", sql.c_str( ) ); |
| 393 |
|
fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) ); |
| 394 |
|
return RES_DB_QUERY_ERROR; |
| 395 |
|
} |
| 396 |
|
|
| 397 |
|
return RES_OK; |
| 398 |
} |
} |
| 399 |
|
|
| 400 |
/** |
/** |
| 609 |
if( uname == NULL ) return RES_ERROR; |
if( uname == NULL ) return RES_ERROR; |
| 610 |
|
|
| 611 |
string uname2 = addSlashes( uname ); |
string uname2 = addSlashes( uname ); |
| 612 |
sql = "SELECT uid FROM " + dbprefix + "_users WHERE uname='" + uname2 + "'"; |
sql = "SELECT uid FROM " + dbprefix + "_users WHERE uname='" + uname2 + "';"; |
| 613 |
if( mysql_query( mysql, sql.c_str( ) ) ){ |
if( mysql_query( mysql, sql.c_str( ) ) ){ |
| 614 |
|
fprintf( stderr, "%d %s\n", mysql_errno(mysql), mysql_error(mysql) ); |
| 615 |
return RES_DB_QUERY_ERROR; |
return RES_DB_QUERY_ERROR; |
| 616 |
} |
} |
| 617 |
MYSQL_RES* result = mysql_use_result( mysql ) ; |
MYSQL_RES* result = mysql_store_result( mysql ) ; |
| 618 |
MYSQL_ROW row = mysql_fetch_row(result); |
MYSQL_ROW row = mysql_fetch_row(result); |
| 619 |
if( row ){ |
if( row ){ |
| 620 |
*uid = atoi( row[0] ); |
*uid = atoi( row[0] ); |
| 672 |
// uname, passwd -> uid |
// uname, passwd -> uid |
| 673 |
string escUname = addSlashes( uname ); |
string escUname = addSlashes( uname ); |
| 674 |
string escPasswd = addSlashes( passwd ); |
string escPasswd = addSlashes( passwd ); |
| 675 |
sql = "SELECT uid FROM " + dbprefix + "_users WHERE uname='" + escUname + "' and paswd=md5('" + escPasswd + "')"; |
sql = "SELECT uid FROM " + dbprefix + "_users WHERE uname='" + escUname + "' and pass=md5('" + escPasswd + "')"; |
| 676 |
if( 0 == mysql_query( mysql, sql.c_str( ) ) ){ |
if( 0 == mysql_query( mysql, sql.c_str( ) ) ){ |
| 677 |
MYSQL_RES* result = mysql_store_result( mysql ); |
MYSQL_RES* result = mysql_store_result( mysql ); |
| 678 |
if( result ){ |
if( result ){ |
| 702 |
* @return なし |
* @return なし |
| 703 |
* |
* |
| 704 |
*/ |
*/ |
| 705 |
void logoutUser( sessionid_t sid ){ |
void logoutUser( sessionid_t sid ) |
| 706 |
|
{ |
| 707 |
result_t ret; |
result_t ret; |
| 708 |
string sql; |
string sql; |
| 709 |
|
|
| 710 |
sql = "DELETE FROM " + dbprefix + "_vpaccount_session WHERE sid=" + intToString((int)sid); |
sql = "DELETE FROM " + dbprefix + "_vpaccount_session WHERE sid=" + intToString((int)sid); |
| 711 |
if ( 0 == mysql_query( mysql, sql.c_str() ) ){ |
if ( 0 == mysql_query( mysql, sql.c_str() ) ){ |
| 712 |
if ( mysql_affected_rows(mysql) == 1 ){ |
if ( mysql_affected_rows(mysql) == 1 ){ |
| 823 |
char buf[ 12 ]; |
char buf[ 12 ]; |
| 824 |
snprintf( buf, 12, "%d", sid ); |
snprintf( buf, 12, "%d", sid ); |
| 825 |
|
|
| 826 |
sql = "SELECT * FROM " + dbprefix + "_vpaccount_session WHERE session_id=" + string( buf ); |
sql = "SELECT * FROM " + dbprefix + "_vpaccount_session WHERE sid=" + string( buf ); |
| 827 |
if( mysql_query( mysql, sql.c_str( ) ) ){ |
if( mysql_query( mysql, sql.c_str( ) ) ){ |
| 828 |
return false; |
return false; |
| 829 |
} |
} |
| 830 |
MYSQL_RES* result = mysql_use_result( mysql ) ; |
MYSQL_RES* result = mysql_store_result( mysql ) ; |
| 831 |
MYSQL_ROW row = mysql_fetch_row(result); |
MYSQL_ROW row = mysql_fetch_row(result); |
| 832 |
if( row ){ |
if( row ){ |
| 833 |
return true; |
return true; |