Exemplo n.º 1
0
function userCheck($username, $password)
{
    $log = new Log("log");
    $array = fileOpen();
    print_r($array);
    $true = false;
    $_SESSION['is-logged-in'] = $true;
    for ($i = 0; $i < count($array); $i++) {
        if (Auth::attempt($username, $password, $array[$i]["password"])) {
            $true = true;
            $log->logMessage("SWEET", "That password for {$username} was correct!, Logging {$username} in!");
            $sessionuname = $array[$i]["username"];
            $_SESSION["username"] = $sessionuname;
            break;
        } else {
            $true = false;
            $log->logMessage("HEY!", "That password for {$username} was incorrect!");
            $sessionuname = "Guest";
            $_SESSION["username"] = $sessionuname;
        }
    }
    if ($true == true) {
        return "You did it {$sessionuname}!";
    } else {
        return "You didn't say the magic word!";
    }
}
Exemplo n.º 2
0
 private function logStripeException($exception, $identifier)
 {
     $response = $exception->getJsonBody();
     // Log the Error
     $log = new Log(STRIPE_LOG);
     $log->setFatal(true);
     $log->logMessage(sprintf("Stripe Exception (%s) [%s]: %s (identifier: %s), HTTP Status: %d", get_class($exception), $response['error']['type'], $response['error']['message'], $identifier, $exception->getHttpStatus()));
     // Show a Friendly Error Page
     $view = new HTMLView();
     $view->includeTemplate('error.fatal', ['app_name' => AppConfig::getValue('app_name')]);
     $view->render(true);
     exit;
     // die now!
 }
Exemplo n.º 3
0
 public function send()
 {
     // Don't send in development...
     if (isTrue(AppConfig::getValue('development'))) {
         (new Log(INFO_LOG))->logMessage('email (' . $this->mailer->Subject . ') sent to ' . (count($this->mailer->getToAddresses()) > 1 ? print_r($this->mailer->getToAddresses(), true) : $this->mailer->getToAddresses()[0][0]) . ', body: ' . $this->mailer->Body);
         return true;
     }
     // Test the Outcome (log errors)
     if (($status = $this->mailer->send()) === false) {
         $log = new Log(ERROR_LOG);
         $log->logMessage(__METHOD__ . ' failed, ' . $this->mailer->ErrorInfo);
         return false;
     } else {
         (new Log(INFO_LOG))->logMessage('email (' . $this->mailer->Subject . ') sent to ' . (count($this->mailer->getToAddresses()) > 1 ? print_r($this->mailer->getToAddresses(), true) : $this->mailer->getToAddresses()[0][0]) . ', body: ' . $this->mailer->Body);
         return true;
     }
 }
Exemplo n.º 4
0
 public function validateToken($token)
 {
     // Can't protect when on localhost, so turn off...
     if (COOKIE_DOMAIN === 'localhost') {
         return true;
     }
     if (self::isValidToken($token) && $token === $this->cookie_token) {
         return true;
         // token is valid
     } else {
         // Log the Error
         $log = new Log(SECURITY_LOG);
         $log->logMessage("Possible CSRF attack detected, warning the user...");
         // Display a Warning
         $this->displayWarning();
     }
 }
Exemplo n.º 5
0
<?php

require_once 'Log.php';
$log = new Log('cli');
$log->info("This is an info level message");
$log->error("This is an error!");
$log->logMessage("WARNING", "This is a warning message.");
<?php

require_once "Log.php";
$log = new Log();
$log->filename = 'log-' . date('Y-m-d') . '.log';
$log->info('User logged in successfully');
$log->error('You do not have permission to view this file');
$log->logMessage('error', '404 page not found');
Exemplo n.º 7
0
<?php

require_once 'log.php';
$logger = new Log();
// $logger is an object (instance) of the class log
$logger->logMessage("info", "Today is");
// the object $logger is calling a  method, which is defined in the class Log
$logger->logMessage("error", "Try again");
<?php

class Log
{
    public $handle;
    public $filename;
    public function __construct($prefix = 'log')
    {
        // Set the $filename property of the class to $prefix-YYYY-MM-DD.log.
        $this->filename = $prefix . date('Y-m-d') . '.log';
        //Open the $filename for appending and assign the file pointer to the property $handle.
        $this->handle = fopen($this->filename, 'a');
    }
    public function logMessage($logLevel, $message)
    {
        $stringToWrite = PHP_EOL . "[{$logLevel}] {$message}";
        fwrite($this->handle, $stringToWrite);
    }
    public function __destruct()
    {
        fclose($this->handle);
    }
}
// procedural code
$log = new Log();
$log->logMessage('INFO', 'this info message is working');
unset($log);
Exemplo n.º 9
0
require_once 'Log.php';
$correctName = Input::get('username', '');
$correctPassword = Input::get('password', '');
if (Auth::check()) {
    header('Location: /php/authorize.php');
    die;
} else {
    if (Auth::attempt($correctName, $correctPassword)) {
        $logFile = new Log();
        $logFile->logMessage('loggedIN', 'user has logged in successfully');
        header('Location: /php/authorize.php');
        die;
    } else {
        if (input::has('username') && input::has('password')) {
            $logFile = new Log();
            $logFile->logMessage('Failed', 'user failed to input correct username or password');
            echo "Please enter the correct username or password.";
        }
    }
}
?>
 <!DOCTYPE html>
 <html>
     <head>
         <link rel="stylesheet" href="/css/">
         <meta charset="utf-8">
         <title></title>
     </head>
     <body>
         <form method="post">
             <label for="username">Username</label>
Exemplo n.º 10
0
<?php

require_once "../log.php";
$log = new Log(07734);
$log->logMessage("HELLO", "I hope this works!");
$log->logInfo();
Exemplo n.º 11
0
<?php

require_once 'Log.php';
$log = new Log();
// $log->filename = 'log-YYYY-MM-DD.log';
$log->logMessage('error', 'There was an error') . PHP_EOL;
$log->info('Awesome, done successfully ' . PHP_EOL);
$log->error('You do not have permission to view this ' . PHP_EOL);
Exemplo n.º 12
0
<?php

require_once "Log.php";
$logFile = new Log();
$logFile->logMessage('info', 'This is some info');
Exemplo n.º 13
0
<?php

require_once "log.php";
$log = new Log();
$log->logInfo('User logged in successfutlly');
$log->logError('You do not have permission to view this file');
$log->logMessage('ERROR', '404 page not found');
Exemplo n.º 14
0
<?php

// Update log_test.php; pass the prefix 'cli' to the class and do not manually set the $filename property. Test from the command line.
// At the top of log_test.php, be sure to require_once 'Log.php';
require_once 'Log.php';
// Create an instance of the Log class
$logTest = new Log('cli');
// Set the $filename property in the class; use the format log-YYYY-MM-DD.log.
// $logTest->filename = "log-".date('Y-m-d').".log";
// Call the methods logMessage(), info(), and error() with to test the functionality of each.
$logTest->logMessage("INFO", "This message called by logMessage().");
$logTest->info("This message called by info().");
$logTest->error("This message called by error().");
// Use log_test.php to test your class by calling it from the command line.