예제 #1
0
 static function getInstance()
 {
     if (self::$_instance instanceof self) {
         return self::$_instance;
     }
     return self::$_instance = new self();
 }
예제 #2
0
 public function render()
 {
     //set locale acoording to model input
     if ($this->model !== null) {
         $locale = $this->model->__get('lang');
         $_COOKIE['locale'] = $locale;
         //reload header-menu
         echo "<script>\n                    \$(function() {\n                        \$('.top-nav').html(\"" . get_top_menu() . "\");\n                    });\n                </script>";
         $langs = "<li role='presentation' class='dropdown'><a class='dropdown-toggle' data-toggle='dropdown' href='#' role='button' aria-haspopup='true' aria-expanded='false'><img src='/myshop/images/flags/" . $_COOKIE['locale'] . ".png' /></a><ul class='dropdown-menu'>";
         foreach ($this->model->__get('languages') as $locale => $lang) {
             if ($this->model instanceof Product) {
                 $langs .= "<li class='lang'><a href='/myshop/" . $locale . "/" . Trans::_fd("product", $locale) . "/" . $lang . "'><img src='/myshop/images/flags/" . $locale . ".png' />" . Trans::_($locale) . "</a></li>";
             } else {
                 $langs .= "<li class='lang'><a href='/myshop/" . $locale . "/" . $lang . "'><img src='/myshop/images/flags/" . $locale . ".png' />" . Trans::_($locale) . "</a></li>";
             }
         }
         $langs .= "</ul></li>";
         echo "<script>\n                    \$(function() {\n                        \$('.langselect').html(\"" . $langs . "\");\n                    });\n                </script>";
     } else {
         echo "<script>\n                    \$(function() {\n                        \$('.top-nav').html(\"" . get_top_menu() . "\");\n                    });\n                </script>";
         $langs = "<li role='presentation' class='dropdown'><a class='dropdown-toggle' data-toggle='dropdown' href='#' role='button' aria-haspopup='true' aria-expanded='false'><img src='/myshop/images/flags/" . Trans::getDomain() . ".png' /></a><ul class='dropdown-menu'>";
         foreach (Trans::getAllDomains() as $lang) {
             if (strpos(RouteController::getCurrentRoute(), Trans::getDomain()) !== false) {
                 $langs .= "<li class='lang'><a href='/myshop" . str_replace(Trans::getDomain(), $lang, RouteController::getCurrentRoute()) . "'><img src='/myshop/images/flags/" . $lang . ".png' />" . Trans::_($lang) . "</a></li>";
             } else {
                 $langs .= "<li class='lang'><a href='/myshop/" . $lang . "'><img src='/myshop/images/flags/" . $lang . ".png' />" . Trans::_($lang) . "</a></li>";
             }
         }
         $langs .= "</ul></li>";
         echo "<script>\n                    \$(function() {\n                        \$('.langselect').html(\"" . $langs . "\");\n                    });\n                </script>";
     }
 }
예제 #3
0
 public function __construct(Route $model)
 {
     $this->model = $model;
     // get all the parameters from the page uri
     $uriGetParam = isset($_GET['uri']) ? "/" . $_GET['uri'] : '/';
     self::$currentRoute = $uriGetParam;
     foreach (Trans::getAllDomains() as $value) {
         if (strpos($uriGetParam, $value) !== false) {
             Trans::setDomain($value);
         }
         $uriGetParam = str_replace("/" . $value, "", $uriGetParam);
     }
     $uriView = explode("/", $uriGetParam);
     if (isset($uriView[1])) {
         $this->uriView = "/" . $uriView[1];
     } else {
         $this->uriView = "/" . $uriView[0];
     }
     $this->additionalParam = explode("/", $uriGetParam);
     setNewLangInCookie();
 }
예제 #4
0
파일: plan.php 프로젝트: bitcalc/allspark
<?php 
require HTMLView::pathForTemplate('layout.head');
?>

<body>
	<div class="container">
		<h1>Choose Plan</h1>
		<?php 
if (!empty($plans) && is_array($plans)) {
    echo '<form method="post">';
    CSRFPRotection::generateHTMLTag();
    echo '<table style="width: 100%; text-align: center;"><tr><th>Name</th><th>Cycle / Interval</th><th>Amount</th><th>Actions</th></tr>';
    foreach ($plans as $plan) {
        // Create Row HTML
        printf('<tr><td>%s</td><td>%d %s</td><td>%s %s</td><td><input type="radio" name="plan" value="%s"></td></tr>', $plan['name'], $plan['interval_count'], $plan['interval'], number_format($plan['amount'] / 100, 2), strtoupper($plan['currency']), $plan['id']);
    }
    echo '</table>';
    echo '<p><label>Coupon:</label> <input type="text" style="width: 150px" name="coupon"></p>';
    echo '<p style="text-align: right;"><button type="submit">Select</button></p>';
    echo '</form>';
}
?>
		<p><a href="<?php 
echo RouteController::fqURL('index');
?>
">back to home</a></p>
	</div>
</body>

</html>
예제 #5
0
<?php 
require HTMLView::pathForTemplate('layout.head');
?>

<body>
	<div class="container">
		<h1>Register</h1>
		<form method="post" style="text-align: center;">
			<?php 
if (isset($alert)) {
    $alert->renderHTML();
}
?>
			<?php 
CSRFPRotection::generateHTMLTag();
?>
			<p><input type="text" name="email" placeholder="Email Address" value="<?php 
postVar('email');
?>
"></p>
			<p><input type="password" name="password" placeholder="Password"></p>
			<p><button type="submit">Submit</button></p>
		</form>
		<p><a href="<?php 
echo RouteController::fqURL('user.login');
?>
">Login</a></p>
	</div>
</body>

</html>
예제 #6
0
 public function isUserAuthenticated($auth_required = true)
 {
     // Cached Result... (if checked before, return the result)
     if ($this->authentication != self::AUTH_UNKNOWN) {
         return $this->authentication == self::AUTH_PASSED;
     }
     // Check Token Validity -- Avoid DB Overhead
     if (self::isSessionIDValid($this->id)) {
         $db = Database::getConnection();
         $query = $db->query("SELECT user_id, update_timestamp, persistent FROM " . self::TABLE_NAME . " WHERE (id=:id) AND (expiry_timestamp > :now)", array(":id" => $this->id, ":now" => Carbon::now()));
     } else {
         if (!$auth_required) {
             return false;
         }
     }
     // Check Query Result (and that it was executed)
     if (isset($query) && $query && $query->rowCount()) {
         $db_row = $query->fetch(PDO::FETCH_ASSOC);
         $this->user_id = $db_row['user_id'];
         // only set here, force people to call this function first before being allowed to look at the ID
         // We need to renew sessions on a regular basis in order for us to determine when sessions become inactive...
         if (Carbon::parse($db_row['update_timestamp'])->diffInSeconds(Carbon::now()) > self::SESSION_RENEWAL_PERIOD_SECONDS) {
             $this->create($db_row['user_id'], isTrue($db_row['persistent']));
         }
         // renew
         $this->authentication = self::AUTH_PASSED;
         return true;
     } else {
         if ($auth_required) {
             // Determine the Current Target/Action
             $request = RequestModel::currentRequest();
             $router = RouteController::getController();
             $route = $router->findRouteForURL($request->url());
             // Add Query Params?
             $url = $router->urlForAction($route->action(), $route->extractArgs($request->url()));
             if (count($request->queryArgArray())) {
                 $url = addQueryParams($url, $request->queryArgArray());
             }
             // Request a Login
             AppController::requestUserLogin($url);
             // we need to extract and re-inject any args or we lose context...
         } else {
             $this->authentication = self::AUTH_FAILED;
             return false;
         }
     }
 }
예제 #7
0
 public static function requestUserLogin($redirect)
 {
     self::redirect(RouteController::fqURL('user.login'), array("redirect" => $redirect));
 }
예제 #8
0
 public static function fqURL($action, $args = null)
 {
     return RouteController::getController()->urlForAction($action, $args);
 }
예제 #9
0
파일: login.php 프로젝트: bitcalc/allspark
<body>
	<div class="container">
		<h1>Login</h1>
		<form method="post" style="text-align: center;">
			<?php 
if (isset($alert)) {
    $alert->renderHTML();
}
?>
			<?php 
CSRFPRotection::generateHTMLTag();
?>
			<p><input type="text" name="email" placeholder="Email Address" value="<?php 
postVar('email');
?>
"></p>
			<p><input type="password" name="password" placeholder="Password"></p>
			<p><button type="submit">Submit</button></p>
		</form>
		<p><a href="<?php 
echo RouteController::fqURL('user.register');
?>
">Register</a></p>
		<p><a href="<?php 
echo RouteController::fqURL('resetPassword');
?>
">Reset Password</a></p>
	</div>
</body>

</html>
예제 #10
0
<?php

define('OFIS', true);
//для организации доступа чз index.php
header("Content-Type:text/html;charset=utf-8");
require 'config.php';
set_include_path(get_include_path() . PATH_SEPARATOR . CONTROLLER . PATH_SEPARATOR . MODEL);
function __autoload($class_name)
{
    include_once $class_name . '.php';
}
$ofis = RouteController::getInstance();
$ofis->route();
예제 #11
0
 public function resetPassword()
 {
     $this->view = new HTMLView();
     if ($this->request->isPOST()) {
         $post = $this->request->postData();
         $user = new UserModel();
         if ($this->request->isQueryArgSet('token')) {
             if ($user->getUserForPasswordResetToken($this->request->queryArgValue('token'))) {
                 $user->password = @$post['password'];
                 if ($user->save()) {
                     $user->deletePasswordResetTokens();
                     $alert = new Alert(Alert::SUCCESS);
                     $alert->addMessage('Password Set, Please Login');
                 } else {
                     $alert = new Alert(Alert::ERROR);
                     $alert->addMessageArray($user->getErrors());
                 }
                 $this->view->includeTemplate('auth.reset-password.password', ['app_name' => AppConfig::getValue('app_name'), 'alert' => $alert]);
             } else {
                 AppController::redirect(RouteController::fqURL('resetPassword'), ['status' => 'token-expired']);
             }
         } else {
             if ($post['email'] && $user->find($post['email'], 'email')) {
                 $token = $user->getPasswordResetTokenData();
                 if ($token['last_email_timestamp'] <= Carbon::now()->subMinutes(pow(2, $token['email_attempts']))) {
                     $user->incrementPasswordResetEmailCount();
                     $link = addQueryParams(RouteController::fqURL('resetPassword'), ['token' => $token['token']]);
                     // Send Email
                     $mailer = new Mailer();
                     $mailer->setSubject('Password Reset Token');
                     $mailer->addAddress($user->email);
                     $mailer->includeHTMLTemplate('email.reset-password', ['link' => $link]);
                     $mailer->send();
                     // errors handled within
                     // Show Message
                     $alert = new Alert(Alert::SUCCESS);
                     $alert->addMessage('Email Sent');
                 } else {
                     $alert = new Alert(Alert::ERROR);
                     $alert->addMessage('Too Many Attempts, Please Try Again Later');
                 }
                 $this->view->includeTemplate('auth.reset-password.email', ['app_name' => AppConfig::getValue('app_name'), 'alert' => $alert]);
             } else {
                 $alert = new Alert(Alert::ERROR);
                 $alert->addMessage('Email is Invalid/Non-Existent');
                 $this->view->includeTemplate('auth.reset-password.email', ['app_name' => AppConfig::getValue('app_name'), 'alert' => $alert]);
             }
         }
     } else {
         if ($this->request->isQueryArgSet('token')) {
             $user = new UserModel();
             if ($user->getUserForPasswordResetToken($this->request->queryArgValue('token'))) {
                 $this->view->includeTemplate('auth.reset-password.password', ['app_name' => AppConfig::getValue('app_name')]);
             } else {
                 AppController::redirect(RouteController::fqURL('resetPassword'), ['status' => 'token-expired']);
             }
         } else {
             if ($this->request->isQueryArgSet('status') && $this->request->queryArgValue('status') == 'token-expired') {
                 $alert = new Alert(Alert::ERROR);
                 $alert->addMessage('Token is Invalid/Expired, Please Request a New One');
             }
             $this->view->includeTemplate('auth.reset-password.email', ['app_name' => AppConfig::getValue('app_name'), 'alert' => isset($alert) ? $alert : null]);
         }
     }
     $this->view->render(true);
 }
예제 #12
0
 private function getCustomer(UserModel $user)
 {
     // Redirect to Start... (not a customer)
     if (!$user->isStripeCustomer()) {
         AppController::redirect(RouteController::fqURL('subscription.manage'));
     }
     try {
         \Stripe\Stripe::setApiKey(AppConfig::getValue('stripe_secret_api_key'));
         // Attempt to Fetch Customer...
         $customer = \Stripe\Customer::retrieve($user->getStripeData()->customer_id);
         // Exisitng, Deleted?
         if ($customer->deleted) {
             $user->stripe_customer_id = null;
             $user->setStripeData(null);
             $user->save();
             // Redirect to Start...
             AppController::redirect(RouteController::fqURL('subscription.manage'));
         } else {
             return $customer;
         }
     } catch (\Stripe\Error\Card $exception) {
         $this->logStripeException($exception, $customer->id);
     } catch (\Stripe\Error\InvalidRequest $exception) {
         $this->logStripeException($exception, $customer->id);
     } catch (\Stripe\Error\Authentication $exception) {
         $this->logStripeException($exception, $customer->id);
     } catch (\Stripe\Error\ApiConnection $exception) {
         $this->logStripeException($exception, $customer->id);
     } catch (\Stripe\Error\Base $exception) {
         $this->logStripeException($exception, $customer->id);
     }
 }