|
|
|
|
@ -69,17 +69,17 @@ class User extends Base {
|
|
|
|
|
}
|
|
|
|
|
public function changeNoFee($id) {
|
|
|
|
|
$field = array('name' => 'no_fees', 'type' => 'i', 'value' => !$this->isNoFee($id));
|
|
|
|
|
$this->log->log("warn", $this->getUserName($id)." changed no_fees to ".$this->isNoFee($id)." from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("warn", $this->getUserName($id)." changed no_fees to ".$this->isNoFee($id));
|
|
|
|
|
return $this->updateSingle($id, $field);
|
|
|
|
|
}
|
|
|
|
|
public function setLocked($id, $value) {
|
|
|
|
|
$field = array('name' => 'is_locked', 'type' => 'i', 'value' => $value);
|
|
|
|
|
$this->log->log("warn", $this->getUserName($id)." changed is_locked to $value from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("warn", $this->getUserName($id)." changed is_locked to $value");
|
|
|
|
|
return $this->updateSingle($id, $field);
|
|
|
|
|
}
|
|
|
|
|
public function changeAdmin($id) {
|
|
|
|
|
$field = array('name' => 'is_admin', 'type' => 'i', 'value' => !$this->isAdmin($id));
|
|
|
|
|
$this->log->log("warn", $this->getUserName($id)." changed is_admin to ".$this->isAdmin($id)." from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("warn", $this->getUserName($id)." changed is_admin to ".$this->isAdmin($id));
|
|
|
|
|
return $this->updateSingle($id, $field);
|
|
|
|
|
}
|
|
|
|
|
public function setUserFailed($id, $value) {
|
|
|
|
|
@ -149,7 +149,7 @@ class User extends Base {
|
|
|
|
|
$this->updateLoginTimestamp($uid);
|
|
|
|
|
$getIPAddress = $this->getUserIp($uid);
|
|
|
|
|
if ($getIPAddress !== $_SERVER['REMOTE_ADDR']) {
|
|
|
|
|
$this->log->log("warn", "$username has logged in with a different IP [".$_SERVER['REMOTE_ADDR']."] saved is [$getIPAddress]");
|
|
|
|
|
$this->log->log("warn", "$username has logged in with a different IP, saved is [$getIPAddress]");
|
|
|
|
|
}
|
|
|
|
|
$setIPAddress = $this->setUserIp($uid, $_SERVER['REMOTE_ADDR']);
|
|
|
|
|
$this->createSession($username, $getIPAddress, $lastLoginTime);
|
|
|
|
|
@ -178,13 +178,13 @@ class User extends Base {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->setErrorMessage("Invalid username or password");
|
|
|
|
|
$this->log->log("info", "$username failed login from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log('error', "Authentication failed for $username");
|
|
|
|
|
if ($id = $this->getUserId($username)) {
|
|
|
|
|
$this->incUserFailed($id);
|
|
|
|
|
// Check if this account should be locked
|
|
|
|
|
if (isset($this->config['maxfailed']['login']) && $this->getUserFailed($id) >= $this->config['maxfailed']['login']) {
|
|
|
|
|
$this->setLocked($id, 1);
|
|
|
|
|
$this->log->log("warn", "$username locked via failed logins from [".$_SERVER['REMOTE_ADDR']."] saved is [".$this->getUserIp($this->getUserId($username))."]");
|
|
|
|
|
$this->log->log("warn", "$username locked due to failed logins, saved is [".$this->getUserIp($this->getUserId($username))."]");
|
|
|
|
|
if ($token = $this->token->createToken('account_unlock', $id)) {
|
|
|
|
|
$aData['token'] = $token;
|
|
|
|
|
$aData['username'] = $username;
|
|
|
|
|
@ -213,12 +213,12 @@ class User extends Base {
|
|
|
|
|
$this->setUserPinFailed($userId, 0);
|
|
|
|
|
return ($pin_hash === $row_pin);
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("info", $this->getUserName($userId)." incorrect pin from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log('info', $this->getUserName($userId).' incorrect pin');
|
|
|
|
|
$this->incUserPinFailed($userId);
|
|
|
|
|
// Check if this account should be locked
|
|
|
|
|
if (isset($this->config['maxfailed']['pin']) && $this->getUserPinFailed($userId) >= $this->config['maxfailed']['pin']) {
|
|
|
|
|
$this->setLocked($userId, 1);
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userId)." was locked via incorrect pins from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userId)." was locked due to incorrect pins");
|
|
|
|
|
if ($token = $this->token->createToken('account_unlock', $userId)) {
|
|
|
|
|
$username = $this->getUserName($userId);
|
|
|
|
|
$aData['token'] = $token;
|
|
|
|
|
@ -247,16 +247,16 @@ class User extends Base {
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param('sis', $newpin, $userID, $current) && $stmt->execute()) {
|
|
|
|
|
if ($stmt->errno == 0 && $stmt->affected_rows === 1) {
|
|
|
|
|
if ($this->mail->sendMail('pin/reset', $aData)) {
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." was sent a pin reset from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("info", "$username was sent a pin reset e-mail");
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." request a pin reset but the mailing failed from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("warn", "$username request a pin reset but failed to send mail");
|
|
|
|
|
$this->setErrorMessage('Unable to send mail to your address');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." incorrect pin reset attempt from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("warn", "$username incorrect pin reset attempt");
|
|
|
|
|
$this->setErrorMessage( 'Unable to generate PIN, current password incorrect?' );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@ -341,16 +341,16 @@ class User extends Base {
|
|
|
|
|
default:
|
|
|
|
|
$aData['subject'] = '';
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." was sent a $strType token from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("info", $aData['username']." was sent a $strType token e-mail");
|
|
|
|
|
if ($this->mail->sendMail('notifications/'.$strType, $aData)) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
$this->setErrorMessage('Failed to send the notification');
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." requested a $strType token but the mailing failed from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("warn", $aData['username']." requested a $strType token but sending mail failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." attempted to request multiple $strType tokens from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." attempted to request multiple $strType tokens");
|
|
|
|
|
$this->setErrorMessage('A request has already been sent to your e-mail address. Please wait an hour for it to expire.');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@ -380,15 +380,15 @@ class User extends Base {
|
|
|
|
|
$tValid = $this->token->isTokenValid($userID, $strToken, 6);
|
|
|
|
|
if ($tValid) {
|
|
|
|
|
if ($this->token->deleteToken($strToken)) {
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." deleted change password token from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." deleted change password token");
|
|
|
|
|
// token deleted, continue
|
|
|
|
|
} else {
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." change password token failed to delete from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." failed to delete the change password token");
|
|
|
|
|
$this->setErrorMessage('Token deletion failed');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." attempted to use an invalid change password token from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("error", $this->getUserName($userID)." attempted to use an invalid change password token");
|
|
|
|
|
$this->setErrorMessage('Invalid token');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@ -398,12 +398,12 @@ class User extends Base {
|
|
|
|
|
$stmt->bind_param('sis', $new, $userID, $current);
|
|
|
|
|
$stmt->execute();
|
|
|
|
|
if ($stmt->errno == 0 && $stmt->affected_rows === 1) {
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." updated password from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." updated password");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
$stmt->close();
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." incorrect password update attempt from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." incorrect password update attempt");
|
|
|
|
|
$this->setErrorMessage( 'Unable to update password, current password wrong?' );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@ -473,15 +473,15 @@ class User extends Base {
|
|
|
|
|
$tValid = $this->token->isTokenValid($userID, $strToken, 5);
|
|
|
|
|
if ($tValid) {
|
|
|
|
|
if ($this->token->deleteToken($strToken)) {
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." deleted account update token for [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." deleted account update token");
|
|
|
|
|
} else {
|
|
|
|
|
$this->setErrorMessage('Token deletion failed');
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." updated their account details but token deletion failed from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." updated their account details but failed to delete token");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->setErrorMessage('Invalid token');
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." attempted to use an invalid token account update token from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." attempted to use an invalid token account update token");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -489,7 +489,7 @@ class User extends Base {
|
|
|
|
|
// We passed all validation checks so update the account
|
|
|
|
|
$stmt = $this->mysqli->prepare("UPDATE $this->table SET coin_address = ?, ap_threshold = ?, donate_percent = ?, email = ?, is_anonymous = ? WHERE id = ?");
|
|
|
|
|
if ($this->checkStmt($stmt) && $stmt->bind_param('sddsii', $address, $threshold, $donate, $email, $is_anonymous, $userID) && $stmt->execute()) {
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." updated their account details from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." updated their account details");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// Catchall
|
|
|
|
|
@ -717,7 +717,7 @@ class User extends Base {
|
|
|
|
|
}
|
|
|
|
|
if (!$this->token->deleteToken($strToken)) {
|
|
|
|
|
$this->setErrorMessage('Unable to remove used token');
|
|
|
|
|
$this->log->log("warn", "$username tried to register but the token failed to delete [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->log->log("warn", "$username tried to register but failed to delete the invitation token");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -839,9 +839,9 @@ class User extends Base {
|
|
|
|
|
$aData['username'] = $this->getUserName($this->getUserId($username, true));
|
|
|
|
|
$aData['subject'] = 'Password Reset Request';
|
|
|
|
|
if ($_SERVER['REMOTE_ADDR'] !== $this->getUserIp($this->getUserId($username, true))) {
|
|
|
|
|
$this->log->log("warn", "$username requested password reset from [".$_SERVER['REMOTE_ADDR']."] saved is [".$this->getUserIp($this->getUserId($username, true))."]");
|
|
|
|
|
$this->log->log("warn", "$username requested password reset, saved IP is [".$this->getUserIp($this->getUserId($username, true))."]");
|
|
|
|
|
} else {
|
|
|
|
|
$this->log->log("info", "$username requested password reset from [".$_SERVER['REMOTE_ADDR']."] saved is [".$this->getUserIp($this->getUserId($username, true))."]");
|
|
|
|
|
$this->log->log("info", "$username requested password reset, saved IP is [".$this->getUserIp($this->getUserId($username, true))."]");
|
|
|
|
|
}
|
|
|
|
|
if ($this->mail->sendMail('password/reset', $aData)) {
|
|
|
|
|
return true;
|
|
|
|
|
@ -861,17 +861,21 @@ class User extends Base {
|
|
|
|
|
**/
|
|
|
|
|
public function isAuthenticated($logout=true) {
|
|
|
|
|
$this->debug->append("STA " . __METHOD__, 4);
|
|
|
|
|
if (@$_SESSION['AUTHENTICATED'] == true &&
|
|
|
|
|
!$this->isLocked($_SESSION['USERDATA']['id']) &&
|
|
|
|
|
$this->getUserIp($_SESSION['USERDATA']['id']) == $_SERVER['REMOTE_ADDR'] &&
|
|
|
|
|
(!$this->config['protect_session_state'] || ($this->config['protect_session_state'] && $_SESSION['STATE'] == md5($_SESSION['USERDATA']['username'].$_SESSION['USERDATA']['id'].@$_SERVER['HTTP_USER_AGENT'])))
|
|
|
|
|
if ( @$_SESSION['AUTHENTICATED'] == true &&
|
|
|
|
|
!$this->isLocked($_SESSION['USERDATA']['id']) &&
|
|
|
|
|
$this->getUserIp($_SESSION['USERDATA']['id']) == $_SERVER['REMOTE_ADDR'] &&
|
|
|
|
|
( ! $this->config['protect_session_state'] ||
|
|
|
|
|
(
|
|
|
|
|
$this->config['protect_session_state'] && $_SESSION['STATE'] == md5($_SESSION['USERDATA']['username'].$_SESSION['USERDATA']['id'].@$_SERVER['HTTP_USER_AGENT'])
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
) return true;
|
|
|
|
|
// Catchall
|
|
|
|
|
$this->log->log("warn", "Forcing logout, user is locked or IP changed mid session from [".$_SERVER['REMOTE_ADDR']."] [hijack attempt?]");
|
|
|
|
|
$this->log->log('warn', 'Forcing logout, user is locked or IP changed mid session [hijack attempt?]');
|
|
|
|
|
if ($logout == true) $this->logoutUser();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convenience function to get IP address, no params is the same as REMOTE_ADDR
|
|
|
|
|
* @param trustremote bool must be FALSE to checkclient or checkforwarded
|
|
|
|
|
|