]> jfr.im git - z_archive/KronOS.git/commitdiff
Moved Core (models -> libraries); changed more things to Json lib
authorJohn Runyon <redacted>
Tue, 16 Oct 2012 10:42:21 +0000 (13:42 +0300)
committerJohn Runyon <redacted>
Tue, 16 Oct 2012 10:42:21 +0000 (13:42 +0300)
application/config/autoload.php
application/controllers/backend.php
application/libraries/Core.php [moved from application/models/core.php with 92% similarity]
application/models/user.php
application/views/main_view.php
public/js/application.js

index bd602bd8d62d36134c319e07cb64be3352e7927e..9cc812f152d5f684d69306803f7b3b776759a93e 100644 (file)
@@ -52,7 +52,7 @@ $autoload['packages'] = array();
 |      $autoload['libraries'] = array('database', 'session', 'xmlrpc');
 */
 
-$autoload['libraries'] = array('database', 'json');
+$autoload['libraries'] = array('database', 'json', 'core');
 
 
 /*
index 700f3a60d6dba868d849533ba90a05cc9e78d205..0d89764a45aa5ca78375fca5d10999fc307c25e0 100644 (file)
@@ -5,7 +5,6 @@ class Backend extends CI_Controller {
        public function __construct() {
                parent::__construct();
 
-               $this->load->model('core');
                $this->load->model('user');
        }
 
@@ -13,7 +12,7 @@ class Backend extends CI_Controller {
        }
 
        public function logged_in() {
-               print json_encode($this->user->is_logged_in());
+               $this->json->reply($this->user->is_logged_in());
        }
 
        public function login_modal() {
@@ -21,7 +20,7 @@ class Backend extends CI_Controller {
        }
 
        public function get_menu() {
-               print json_encode($this->core->get_menu());
+               $this->json->reply($this->core->get_menu());
        }
 }
 ?>
similarity index 92%
rename from application/models/core.php
rename to application/libraries/Core.php
index 487a3d8278a2755b42f80b7c6939307cd8509ab9..86879efdcddd1497b906b5032d2d63a904a83b40 100644 (file)
@@ -1,11 +1,11 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php // if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
-class Core extends CI_Model {
+class Core {
        public function get_menu() {
                $menu = array(
                        'Desktop'       => '#',
                        'App'           => '#',
-                       'Test'          => '#',
+                       'Logout'        => 'javascript:logout();void(0);',
                        'GitHub'        => 'https://github.com/mustis/WebOsProject'
                );
                return $menu;
index 5d4ea8055db913ffe8268c6c9ddcbdf6a058603f..6c9a3cadbb2e1d68aca565e7d8844250e026cddc 100644 (file)
@@ -40,6 +40,8 @@ class User extends CI_Model {
                $this->db->insert('sessions', $sdata);
                $this->sid($this->db->insert_id());
 
+               $this->input->set_cookie('session_id', $this->sid());
+
                return TRUE;
        }
 
@@ -53,7 +55,8 @@ class User extends CI_Model {
                if (isset($this->cached_sid)) {
                        return $this->cached_sid;
                } else {
-                       return FALSE; // FIXME should we fetch SID somehow?
+                       // FIXME needs IP-lock checking...
+                       return $this->cached_sid = $this->input->cookie('session_id');
                }
        }
        public function uid($new=NULL) {
index 97b1e024df3bd5448ddad4286c1f75e4f50f7147..aa3d228e84f71c988bc0d3b1bc188b4ddc175b57 100644 (file)
                                        <a class="brand" href="#">WebOS Dev</a>\r
                                        <div class="nav-collapse collapse menudiv">\r
                                        <p class="navbar-text pull-right">\r
-                                               Logged in as <a href="#" class="navbar-link" id="username">Username</a>\r
+                                               Logged in as <a href="#" class="navbar-link" id="username"><em>unauthenticated</em></a>\r
                                        </p>\r
                                        </div>\r
                                </div>\r
                        </div>\r
                </div>\r
-               <div class="container-fluid">\r
+               <div id="desktop" class="container-fluid">\r
                        <div class="row">\r
                        </div>\r
                </div>\r
index e08ffd46bd70f0c166a8d6d9ca790c469ff1bd42..1a9895b22f283ade24d6774d6a9c242beb47cf79 100644 (file)
@@ -1,10 +1,11 @@
 var state
 
 function loadDefaults() {
-       jQuery.getJSON("/backend/logged_in", function(data) {
-               if (!data) {
+       jQuery.getJSON("/backend/logged_in", function(resp) {
+               if (!resp.contents) {
                        loadLoginModal();
                } else {
+                       loadUsername();
                        loadMenu();
                        loadBackground();
                }
@@ -32,16 +33,24 @@ function loadLoginModal() {
 
 }
 
+function loadUsername() {
+       jQuery("#username").html(state.name);
+}
+
 function loadMenu() {
-       jQuery.getJSON("/backend/get_menu", function(data) {
-               var menuitems = []
-               jQuery.each(data, function(key, val) {
-                       menuitems.push('<li><a href="' + val + '">' + key + '</li>');
-               });
-               jQuery('<ul/>', {
-                       'class': 'nav',
-                       html: menuitems.join('')
-               }).appendTo('.menudiv');
+       jQuery.getJSON("/backend/get_menu", function(resp) {
+               if (resp.success) {
+                       var menuitems = []
+                       jQuery.each(resp.contents, function(key, val) {
+                               menuitems.push('<li><a href="' + val + '">' + key + '</li>');
+                       });
+                       jQuery('<ul/>', {
+                               'class': 'nav',
+                               html: menuitems.join('')
+                       }).appendTo('.menudiv');
+               } else {
+                       throwError(resp.error, 'error', '#desktop');
+               }
        });
 
 }
@@ -57,23 +66,30 @@ function submitLogin() {
                                state[key] = resp.data[key]
                        }
                        jQuery('#loginModal').modal('hide');
+                       loadUsername();
                        loadMenu();
                        loadBackground();
                } else {
-                       var n = jQuery(".alert").length;
-                       if (n>2) {
-                               jQuery(".alert").first().remove();
-                       }
                        throwError(resp.error, 'error', '.messagebody');
                }
        }, "json");
 }
 
 function throwError(e, t, c) {
+       var n = jQuery(".alert").length;
+       if (n>2) {
+               jQuery(".alert").first().remove();
+       }
+
        error = '<div class="alert alert-block alert-' + t + '"><button type="button" class="close" data-dismiss="alert">&times;</button>' + e + '</div>'
        jQuery(c).append(error);
 }
 
+function logout() {
+       state = {}
+       loadDefaults();
+}
+
 jQuery(function () {
        state = {}