Alex Trofimov 7 年之前
父节点
当前提交
43fc824f1b
共有 5 个文件被更改,包括 113 次插入 和 5 次删除
  1. 16 1
      index.php
  2. 19 2
      member.php
  3. 29 0
      template/mobile_apps_js.html
  4. 20 1
      template/scripts/BxBaseServiceLogin.php
  5. 29 1
      template/scripts/BxBaseServiceMobileApps.php

+ 16 - 1
index.php

@@ -26,12 +26,27 @@ if (!file_exists("./inc/header.inc.php")) {
 require_once('./inc/header.inc.php');
 require_once(BX_DIRECTORY_PATH_INC . "profiles.inc.php");
 
+$_GET['i'] = 'home';
+
+if (!isLogged() && false !== strpos($_SERVER['HTTP_USER_AGENT'], 'UNAMobileApp')) {
+
+    require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
+    
+    $sLoginForm = BxDolService::call('system', 'login_form', array('ajax_form'), 'TemplServiceLogin');
+
+    $oTemplate = BxDolTemplate::getInstance();
+    $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
+    $oTemplate->setPageContent ('page_main_code', DesignBoxContent('', $sLoginForm, BX_DB_PADDING_NO_CAPTION)); 
+    $oTemplate->getPageCode();
+    
+    exit;
+}
+
 if (!isLogged() && getParam('sys_site_splash_enabled')) {
     require_once("./splash.php");
     exit;
 }
 
-$_GET['i'] = 'home';
 require_once("./page.php");
 
 /** @} */

+ 19 - 2
member.php

@@ -25,8 +25,25 @@ if (isset($_POST['ID'])) { // login form is submitted
     $bAjxMode = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') ? true : false;
     if ($bAjxMode) {
 
-        header( 'Content-type: text/html; charset=utf-8' );
-        echo $bLoginSuccess ? 'OK' : $oForm->getLoginError();
+        if ($bLoginSuccess) {
+            $s = 'OK';
+            $oAccount = BxDolAccount::getInstance(trim($oForm->getCleanValue('ID')));
+            $aAccount = bx_login($oAccount->id(), ($oForm->getCleanValue('rememberMe') ? true : false));
+        }
+        else {
+            $s = $oForm->getLoginError();
+        }
+
+        if (isset($_SERVER['HTTP_ACCEPT'])) {
+            if (false !== strpos($_SERVER['HTTP_ACCEPT'], 'application/json') || false !== strpos($_SERVER['HTTP_ACCEPT'], 'text/javascript')) {
+                header('Content-type: application/json; charset=utf-8');
+                echo json_encode(['res' => $s, 'form' => $oForm->getCode()]);
+                exit;
+            }
+        }
+
+        header('Content-type: text/html; charset=utf-8');
+        echo $s;
         exit;
 
     } 

+ 29 - 0
template/mobile_apps_js.html

@@ -0,0 +1,29 @@
+<script>
+    function bx_mobile_apps_show_main_menu () {
+        if ($('.cd-side-nav').size())
+            $([$('.cd-side-nav'), $('.cd-nav-trigger')]).toggleClass('nav-is-visible');
+        else
+            bx_menu_slide_inline('#bx-sliding-menu-sys_site', null, 'site');
+    }
+
+    function bx_mobile_apps_show_profile_menu () {
+        bx_menu_slide_inline('#bx-sliding-menu-account', null, 'site');
+    }
+
+    function bx_mobile_apps_show_add_menu () {
+        bx_menu_slide_inline('#bx-sliding-menu-sys_add_content', null, 'site');
+    }
+
+    function bx_mobile_apps_home () {
+        if (window.history.length > 1)
+            window.history.go(-(window.history.length - 1));
+    }
+
+    console.log('Navigation History:' + window.history.length);
+    var sMsg = JSON.stringify(__msg__);
+    console.log(sMsg);
+    if ('undefined' !== typeof(window.ReactNativeWebView))
+        window.ReactNativeWebView.postMessage(sMsg);
+    else
+        window.postMessage(sMsg, '*');
+</script>

+ 20 - 1
template/scripts/BxBaseServiceLogin.php

@@ -101,7 +101,26 @@ class BxBaseServiceLogin extends BxDol
         if (strpos($sParams, 'no_auth_buttons') === false)
             $sAuth = $this->serviceMemberAuthCode();
 
-        return $sCustomHtmlBefore . $sAuth . $sFormCode . $sCustomHtmlAfter . $sJoinText;
+        $sAjaxForm = '';
+        if (strpos($sParams, 'ajax_form') !== false)
+            $sAjaxForm = "<script>
+                (bx_login_init_ajax_form = function () {
+                    $('#sys-form-login').ajaxForm({
+                        dataType: 'json',
+                        success: function (oData) {
+                            if ('undefined' !== typeof(oData['res']) && 'OK' == oData['res']) {
+                                location.reload();
+                            }
+                            else if ('undefined' !== typeof(oData['form'])) {
+                                $('#sys-form-login').replaceWith(oData['form']);
+                                bx_login_init_ajax_form();
+                            }
+                        }
+                    });
+                })();
+            </script>";
+        
+        return $sCustomHtmlBefore . $sAuth . $sFormCode . $sCustomHtmlAfter . $sJoinText . $sAjaxForm;
 
     }
     

+ 29 - 1
template/scripts/BxBaseServiceMobileApps.php

@@ -26,7 +26,35 @@ class BxBaseServiceMobileApps extends BxDol
         if (false === strpos($_SERVER['HTTP_USER_AGENT'], 'UNAMobileApp')) 
             return '';
 
-        return BxDolTemplate::getInstance()->parseHtmlByName('mobile_apps_styles.html', array());
+        $this->mobileRedirects();
+
+        $s  = BxDolTemplate::getInstance()->parseHtmlByName('mobile_apps_styles.html', array());
+        $s .= BxDolTemplate::getInstance()->parseHtmlByName('mobile_apps_js.html', array(
+            'msg' => json_encode(array(
+                'loggedin' => isLogged(),
+            ))
+        ));
+        return $s;
+    }
+
+    protected function mobileRedirects()
+    {
+        $bLoggedIn = isLogged() ? 1 : 0;
+        $i = bx_get('i');
+
+        // only several pages are available for guest, for other pages user is redirected to login page        
+        $aI = array('forgot-password' => 1, 'create-account' => 1, 'terms' => 1, 'privacy' => 1, 'contact' => 1, 'about' => 1, 'home' => 1);
+        if (!$bLoggedIn && !preg_match('/searchKeyword.php$/', $_SERVER['PHP_SELF']) && !preg_match('/member.php$/', $_SERVER['PHP_SELF']) && !isset($aI[$i])) {
+            header("Location: " . BX_DOL_URL_ROOT);
+            exit;
+        }
+        
+        // for logged in members some pages aren't available as well
+        $aI = array('forgot-password' => 1, 'create-account' => 1, 'login' => 1);
+        if ($bLoggedIn && isset($aI[$i])) {
+            header("Location: " . BX_DOL_URL_ROOT);
+            exit;
+        }
     }
 }