Skip to content

Commit

Permalink
close #27, import Vecni as app.
Browse files Browse the repository at this point in the history
  • Loading branch information
b4oshany committed Dec 14, 2014
1 parent 97603d0 commit fe03313
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
4 changes: 4 additions & 0 deletions app/libs/vecni/Vecni.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class Vecni extends Object

private $vars = array();
private static $app_route = array();

public function __construct($file){
self::init($file);
}

public static function init($file)
{
Expand Down
6 changes: 3 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
session_start();
require_once "app/libs/vecni/Autoloader.php";
use libs\vecni\Vecni;
Vecni::init(__FILE__);
use libs\vecni\Vecni as app;
app::init(__FILE__);
include "main.ini.php";
Vecni::get_route();
app::get_route();
?>
50 changes: 25 additions & 25 deletions main.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
# define package usage
use libs\vecni\http\Response;
use libs\vecni\http\Request;
use libs\vecni\Vecni;
use libs\vecni\Vecni as app;
use controller\user\User;

User::start_session();

Response::init();

// Set the default title of website.
Vecni::$twig->addGlobal("title", Vecni::$BRAND_NAME);
app::$twig->addGlobal("title", app::$BRAND_NAME);
if(User::is_login()){
Vecni::$twig->addGlobal("user", User::get_current_user());
app::$twig->addGlobal("user", User::get_current_user());
}

/**
Expand All @@ -21,19 +21,19 @@
This function is the default fall back function that
have been registered in the system by default.
*/
Vecni::set_route("/", "welcome");
Vecni::set_route("/home", "welcome");
app::set_route("/", "welcome");
app::set_route("/home", "welcome");
function welcome(){
if(User::is_login()){
return Vecni::$twig->render("demo/vecni_docs.html",
return app::$twig->render("demo/vecni_docs.html",
array(
"html_class"=>"welcome"
));
}else{
return Vecni::$twig->render('demo/vecni_docs.html',
return app::$twig->render('demo/vecni_docs.html',
array(
"html_class"=>"welcome",
"title"=>Vecni::$BRAND_NAME
"title"=>app::$BRAND_NAME
)
);
}
Expand All @@ -42,9 +42,9 @@ function welcome(){
/**
* Sign in page for users
*/
Vecni::set_route("/user/signin", "signin_require");
app::set_route("/user/signin", "signin_require");
function signin_require($message=""){
return Vecni::$twig->render('user_signin.html',
return app::$twig->render('user_signin.html',
array(
"html_class"=>"signin",
"title"=>"Signin Required",
Expand All @@ -57,7 +57,7 @@ function signin_require($message=""){
/**
* Sign in processing for users
*/
Vecni::set_route("/user/signin/process", "process_login");
app::set_route("/user/signin/process", "process_login");
function process_login(){
if(!empty($_POST['email']) && !empty($_POST['password'])){
$email = $_POST['email'];
Expand All @@ -71,7 +71,7 @@ function process_login(){
}
}else{
if($status){
Vecni::nav_back();
app::nav_back();
}else{
signin_require();
}
Expand All @@ -83,12 +83,12 @@ function process_login(){
/**
* Registration page for users
*/
Vecni::set_route("/user/registration", "reg_request");
app::set_route("/user/registration", "reg_request");
function reg_request($message=""){
if(User::is_login()){
Vecni::redirect();
app::redirect();
}
return Vecni::$twig->render('user_registration.html',
return app::$twig->render('user_registration.html',
array("html_class"=>"user-registration",
"title"=>"Registration",
)
Expand All @@ -98,7 +98,7 @@ function reg_request($message=""){
/**
* Registration processing for users
*/
Vecni::set_route("/user/registration/process", "register");
app::set_route("/user/registration/process", "register");
function register(){
global $user;
if(($first_name = Request::POST('first_name')) &&
Expand All @@ -123,21 +123,21 @@ function register(){
}
}else{
if($status){
Vecni::redirect();
app::redirect();
}else{
Vecni::redirect();
app::redirect();
}
}
}
}

Vecni::set_route("/facebooklogin", "login_with_social_network");
Vecni::set_route("/googleplus", "login_with_social_network");
Vecni::set_route("/twitter", "login_with_social_network");
app::set_route("/facebooklogin", "login_with_social_network");
app::set_route("/googleplus", "login_with_social_network");
app::set_route("/twitter", "login_with_social_network");
function login_with_social_network(){
global $user;
if(User::is_login()){
Vecni::redirect();
app::redirect();
}
if(!empty($_POST['first_name']) && !empty($_POST['last_name']) && !empty($_POST['social_network']) && !empty($_POST['social_network_id']) && !empty($_POST['email'])){
$new_user = new User();
Expand Down Expand Up @@ -166,13 +166,13 @@ function login_with_social_network(){
* Log out users out of Tattle Tale
* @redirect page welcome
*/
Vecni::set_route("/logout", "log_out");
app::set_route("/logout", "log_out");
function log_out(){
if(User::is_login()){
User::log_out();
Vecni::$twig->addGlobal("user", new User());
app::$twig->addGlobal("user", new User());
}
Vecni::redirect();
app::redirect();
}

?>
Expand Down

0 comments on commit fe03313

Please sign in to comment.