<?php
function user_change_email ($password1,$new_email,$user_name) {
global $feedback,$hidden_hash_var;
if (validate_email($new_email)) {
$hash=md5($new_email.$hidden_hash_var);
file://改變數據庫中確認用的無序碼值,但不改變email
file://發出一個帶有新認證碼的確認email
$user_name=strtolower($user_name);
$password1=strtolower($password1);
$sql="UPDATE user SET confirm_hash='$hash' WHERE user_name='$user_name' AND password='". md5($password1) ."'";
$result=db_query($sql);
if (!$result || db_affected_rows($result) < 1) {
$feedback .= ' ERROR - Incorrect User Name Or Password ';
return false;
} else {
$feedback .= ' Confirmation Sent ';
user_send_confirm_email($new_email,$hash);
return true;
}
} else {
$feedback .= ' New Email Address Appears Invalid ';
return false;
}
}
function user_confirm($hash,$email) {
/*
用戶點擊認證email的相關連接時,連到一個確認的頁面,該頁面會調用這個函數,
*/
global $feedback,$hidden_hash_var;
file://verify that they didn't tamper with the email address
$new_hash=md5($email.$hidden_hash_var);
if ($new_hash && ($new_hash==$hash)) {
file://在數據庫中找出這個記錄
$sql="SELECT * FROM user WHERE confirm_hash='$hash'";
$result=db_query($sql);
if (!$result || db_numrows($result) < 1) {
$feedback .= ' ERROR - Hash Not Found ';
return false;
} else {
file://確認email,并且設置帳號為已經激活
$feedback .= ' User Account Updated - You Are Now Logged In ';
user_set_tokens(db_result($result,0,'user_name'));
$sql="UPDATE user SET email='$email',is_confirmed='1' WHERE confirm_hash='$hash'";
$result=db_query($sql);
return true;
}
} else {
$feedback .= ' HASH INVALID - UPDATE FAILED ';
return false;
}
}
function user_send_confirm_email($email,$hash) {
/*
這個函數在首次注冊或者改變email地址時使用
*/
$message = "Thank You For Registering at Company.com".
"nSimply follow this link to confirm your registration: ".
"nnhttp://www.company.com/account/confirm.php?hash=$hash&email=". urlencode($email). "nnOnce you confirm, you can use the services on PHPBuilder.";
mail ($email,'Registration Confirmation',$message,'From: noreply@company.com');
}
?>


