|
|
|
|
@ -69,23 +69,17 @@ class User extends Base {
|
|
|
|
|
}
|
|
|
|
|
public function changeNoFee($id) {
|
|
|
|
|
$field = array('name' => 'no_fees', 'type' => 'i', 'value' => !$this->isNoFee($id));
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogWarn($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)." from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
return $this->updateSingle($id, $field);
|
|
|
|
|
}
|
|
|
|
|
public function setLocked($id, $value) {
|
|
|
|
|
$field = array('name' => 'is_locked', 'type' => 'i', 'value' => $value);
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogWarn($this->getUserName($id)." changed is_locked to $value from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("warn", $this->getUserName($id)." changed is_locked to $value from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
return $this->updateSingle($id, $field);
|
|
|
|
|
}
|
|
|
|
|
public function changeAdmin($id) {
|
|
|
|
|
$field = array('name' => 'is_admin', 'type' => 'i', 'value' => !$this->isAdmin($id));
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogWarn($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)." from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
return $this->updateSingle($id, $field);
|
|
|
|
|
}
|
|
|
|
|
public function setUserFailed($id, $value) {
|
|
|
|
|
@ -154,10 +148,8 @@ class User extends Base {
|
|
|
|
|
$lastLoginTime = $this->getLastLogin($uid);
|
|
|
|
|
$this->updateLoginTimestamp($uid);
|
|
|
|
|
$getIPAddress = $this->getUserIp($uid);
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
if ($getIPAddress !== $_SERVER['REMOTE_ADDR']) {
|
|
|
|
|
$this->log->LogWarn("$username has logged in with a different IP [".$_SERVER['REMOTE_ADDR']."] saved is [$getIPAddress]");
|
|
|
|
|
}
|
|
|
|
|
if ($getIPAddress !== $_SERVER['REMOTE_ADDR']) {
|
|
|
|
|
$this->log->log("warn", "$username has logged in with a different IP [".$_SERVER['REMOTE_ADDR']."] saved is [$getIPAddress]");
|
|
|
|
|
}
|
|
|
|
|
$setIPAddress = $this->setUserIp($uid, $_SERVER['REMOTE_ADDR']);
|
|
|
|
|
$this->createSession($username, $getIPAddress, $lastLoginTime);
|
|
|
|
|
@ -186,17 +178,13 @@ class User extends Base {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->setErrorMessage("Invalid username or password");
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogInfo("$username failed login from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("info", "$username failed login from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
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);
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogWarn("$username locked via failed logins from [".$_SERVER['REMOTE_ADDR']."] saved is [".$this->getUserIp($this->getUserId($username))."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("warn", "$username locked via failed logins from [".$_SERVER['REMOTE_ADDR']."] saved is [".$this->getUserIp($this->getUserId($username))."]");
|
|
|
|
|
if ($token = $this->token->createToken('account_unlock', $id)) {
|
|
|
|
|
$aData['token'] = $token;
|
|
|
|
|
$aData['username'] = $username;
|
|
|
|
|
@ -225,16 +213,12 @@ class User extends Base {
|
|
|
|
|
$this->setUserPinFailed($userId, 0);
|
|
|
|
|
return ($pin_hash === $row_pin);
|
|
|
|
|
}
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogInfo($this->getUserName($userId)." incorrect pin from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("info", $this->getUserName($userId)." incorrect pin from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$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);
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogWarn($this->getUserName($userId)." was locked via incorrect pins from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userId)." was locked via incorrect pins from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
if ($token = $this->token->createToken('account_unlock', $userId)) {
|
|
|
|
|
$username = $this->getUserName($userId);
|
|
|
|
|
$aData['token'] = $token;
|
|
|
|
|
@ -263,22 +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)) {
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogInfo($this->getUserName($userID)." was sent a pin reset from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." was sent a pin reset from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogWarn($this->getUserName($userID)." request a pin reset but the mailing failed from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." request a pin reset but the mailing failed from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->setErrorMessage('Unable to send mail to your address');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogWarn($this->getUserName($userID)." incorrect pin reset attempt from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." incorrect pin reset attempt from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->setErrorMessage( 'Unable to generate PIN, current password incorrect?' );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@ -353,22 +331,16 @@ class User extends Base {
|
|
|
|
|
default:
|
|
|
|
|
$aData['subject'] = '';
|
|
|
|
|
}
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogInfo($this->getUserName($userID)." was sent a $strType token from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." was sent a $strType token from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
if ($this->mail->sendMail('notifications/'.$strType, $aData)) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
$this->setErrorMessage('Failed to send the notification');
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogWarn($this->getUserName($userID)." requested a $strType token but the mailing failed from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." requested a $strType token but the mailing failed from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogWarn($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 from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->setErrorMessage('A request has already been sent to your e-mail address. Please wait an hour for it to expire.');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@ -398,21 +370,15 @@ class User extends Base {
|
|
|
|
|
$tValid = $this->token->isTokenValid($userID, $strToken, 6);
|
|
|
|
|
if ($tValid) {
|
|
|
|
|
if ($this->token->deleteToken($strToken)) {
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogInfo($this->getUserName($userID)." deleted change password token from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." deleted change password token from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
// token deleted, continue
|
|
|
|
|
} else {
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogWarn($this->getUserName($userID)." change password token failed to delete from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." change password token failed to delete from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->setErrorMessage('Token deletion failed');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogWarn($this->getUserName($userID)." attempted to use an invalid change password token from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." attempted to use an invalid change password token from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
$this->setErrorMessage('Invalid token');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@ -422,16 +388,14 @@ class User extends Base {
|
|
|
|
|
$stmt->bind_param('sis', $new, $userID, $current);
|
|
|
|
|
$stmt->execute();
|
|
|
|
|
if ($stmt->errno == 0 && $stmt->affected_rows === 1) {
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogInfo($this->getUserName($userID)." updated password from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." updated password from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
$stmt->close();
|
|
|
|
|
}
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogWarn($this->getUserName($userID)." incorrect password update attempt from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->log->log("warn", $this->getUserName($userID)." incorrect password update attempt from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
|
|
|
|
|
$this->setErrorMessage( 'Unable to update password, current password wrong?' );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@ -501,21 +465,15 @@ class User extends Base {
|
|
|
|
|
$tValid = $this->token->isTokenValid($userID, $strToken, 5);
|
|
|
|
|
if ($tValid) {
|
|
|
|
|
if ($this->token->deleteToken($strToken)) {
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogInfo($this->getUserName($userID)." deleted account update token for [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." deleted account update token for [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
} else {
|
|
|
|
|
$this->setErrorMessage('Token deletion failed');
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogWarn($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 token deletion failed from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->setErrorMessage('Invalid token');
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogWarn($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 from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -523,9 +481,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()) {
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogInfo($this->getUserName($userID)." updated their account details from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("info", $this->getUserName($userID)." updated their account details from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// Catchall
|
|
|
|
|
@ -587,6 +543,9 @@ class User extends Base {
|
|
|
|
|
$_SESSION['AUTHENTICATED'] = '1';
|
|
|
|
|
// $this->user from checkUserPassword
|
|
|
|
|
$_SESSION['USERDATA'] = $this->user;
|
|
|
|
|
if ($this->config['protect_session_state']) {
|
|
|
|
|
$_SESSION['STATE'] = md5($_SESSION['USERDATA']['username'].$_SESSION['USERDATA']['id'].$_SERVER['HTTP_USER_AGENT']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -741,6 +700,7 @@ class User extends Base {
|
|
|
|
|
$invitation = new Invitation();
|
|
|
|
|
$invitation->setMysql($this->mysqli);
|
|
|
|
|
$invitation->setDebug($this->debug);
|
|
|
|
|
$invitation->setLog($this->log);
|
|
|
|
|
$invitation->setUser($this);
|
|
|
|
|
$invitation->setConfig($this->config);
|
|
|
|
|
if (!$invitation->setActivated($aToken['id'])) {
|
|
|
|
|
@ -749,6 +709,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']."]");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -869,12 +830,10 @@ class User extends Base {
|
|
|
|
|
}
|
|
|
|
|
$aData['username'] = $this->getUserName($this->getUserId($username, true));
|
|
|
|
|
$aData['subject'] = 'Password Reset Request';
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
if ($_SERVER['REMOTE_ADDR'] !== $this->getUserIp($this->getUserId($username, true))) {
|
|
|
|
|
$this->log->LogWarn("$username requested password reset from [".$_SERVER['REMOTE_ADDR']."] saved is [".$this->getUserIp($this->getUserId($username, true))."]");
|
|
|
|
|
} else {
|
|
|
|
|
$this->log->LogInfo("$username requested password reset from [".$_SERVER['REMOTE_ADDR']."] saved is [".$this->getUserIp($this->getUserId($username, true))."]");
|
|
|
|
|
}
|
|
|
|
|
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))."]");
|
|
|
|
|
} else {
|
|
|
|
|
$this->log->log("info", "$username requested password reset from [".$_SERVER['REMOTE_ADDR']."] saved is [".$this->getUserIp($this->getUserId($username, true))."]");
|
|
|
|
|
}
|
|
|
|
|
if ($this->mail->sendMail('password/reset', $aData)) {
|
|
|
|
|
return true;
|
|
|
|
|
@ -896,12 +855,11 @@ 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->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
|
|
|
|
|
if ($this->config['logging']['enabled'] && $this->config['logging']['level'] > 0) {
|
|
|
|
|
$this->log->LogWarn("Forcing logout, user is locked or IP changed mid session from [".$_SERVER['REMOTE_ADDR']."]");
|
|
|
|
|
}
|
|
|
|
|
$this->log->log("warn", "Forcing logout, user is locked or IP changed mid session from [".$_SERVER['REMOTE_ADDR']."] [hijack attempt?]");
|
|
|
|
|
if ($logout == true) $this->logoutUser();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|