Jump to content

nicolant

Members
  • Posts

    15
  • Joined

  • Last visited

Posts posted by nicolant

  1. Thank you, @AndZyk

    I can not understand, how to configure that module in order to retain original file names. If I set Filename Format to {$file->name} then dots become replaced by hyphens instead of underscores...
    I tried to dig into code of module, but it seems too complicated for me ?, because my field is inside repeater.

    The reason behind decision not to store files in templates directory is that these files are "blocks", like, for example, small HTML games, and I need to provide mehanism for upload them 

     

  2. Please help me to figure out, how to set modified timestamp for PageFiles inside hook. Specifically, I need to mark all files fields in a page and its children as updated on save of that page. $files->modified = time() doesn't work. The only way I have found to modify it is to call $file->install() method on each PageFile. It does the job but duplicates files...

  3. Thank you @mtwebit for that module! 

    But I have a trouble with processwire setup with two site folders: "site" and "site-users". Tasker module is installed  in site-users/modules folder.

    How to force processwire to load that modules instead of site/modules? Because runByCron.sh can't find Tasker module:

    require "index.php";
    
    if (!wire('modules')->isInstalled('Tasker')) {
    echo 'Tasker module is missing.';
    exit;
    }

     

     

    Nikolay.

     

     

    SOLVED: By addition of $_SERVER['HTTP_HOST']=$siteDomain; before index.php

  4. On 9/7/2018 at 12:42 PM, thomasaull said:

    while the wire('session')->login() should work for this request, it is likely the session is already destroyed on the next one. For this case it might be feasible to store the user id in the jwt payload (like you suggested). Since I'm going to have this case in an upcoming project, I gave it a try this morning. Please check the following commit for the changes I did: https://github.com/thomasaull/RestApiProfile-Src/commit/2dbdc79aa952bece6926dbee896de0a4f434bb6a

    I didn't test it with different domains though, so I'd be thankful if you could report back if it works for you! ?

    It remembers userId after login, but not on next reload of content, when   if(wire('user')->isGuest())  in Auth.php returns true.

    Instead in auth() it should again read userId from token, but since $decoded variable is available only in Router...

     

    EDIT:

    It seems that retrieved JWT should be kept in sessionStorage entirely client-side. In order to do that I'd have to use VuexPersist plugin.

    I'd have to move setting of authorization header (in my case, axios.defaults.headers.common['Authorization'] = 'Bearer ' + this.$store.state.jwt) from mutations.js to Content.vue. Not sure though that it's an elegant way.

    I forked your repo with modifications here:

    https://github.com/nicolant/RestApiProfile

     

  5. Thank you for the profile. 

    I'm trying to move client vue part to another domain. In order to do that, i had to make a few modifications:

     

    to Auth.php:

    public static function preflight() 
    {
    	return "OK";
    }

    to Router.php:

    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Headers: Authorization, Content-Type');
    .
    .
      $r->addGroup('/auth', function (\FastRoute\RouteCollector $r)
      {
        $r->addRoute('OPTIONS', '', Auth::class . '@preflight');
    .
    .
      $r->addGroup('/test', function (\FastRoute\RouteCollector $r)
      {
        $r->addRoute('OPTIONS', '', Auth::class . '@preflight');
    

    and change  axios.defaults.baseURL

    but after login it stays as "guest" (User logged in: guest)

    It seems that it's impossible to use session (wire('session')->login) in that situation.

     

    Could you advice how to pass and re-use, for example, user ID, bypassing processwire session (may be through encoding it with JWT)?

     

    Nikolay

     

     

     

  6. I'm trying to replace default templates for "templates" CKEditor plugin (in site folder) without any luck.

    My installation runs templates.js from "dialogs" folder (from wire folder).

     

    I have seen others have same problem:

     

    Please, help.

    Nikolay Antoshenkov

     

     

    P.S. Just have found solution:

    Added line 

    config.templates_files= ['/site/modules/InputfieldCKEditor/plugins/templates/default.js'];

    to config.js

    • Like 2
  7.  Ryan, thank you for your efforts. I wonder how do you find a time to answer all the questions!

    Another thing I want to mention is that it looks like you are doing a lot with facebook on every single request.

    You're right, but I'm planning to add separate "Share" button next to "Save" (or checkbox would even better, I think. By the way, could you direct please how to do that?), and in that case I may press and may not press it, and it would be strange to have a FB login page popping anyway beforehand ( I'm still in the beginning of learning facebook API, and it seems that I have to pass through login page before first manipulation with facebook).

  8. Ryan, thank you! That's the point!

    But now I have to move all the action to the init method. Is it possible to get there an object of page being edited or I have to save it in the session?

    Code now looks like this:

    <?php
    
    class MySocialIntegration extends WireData implements Module {
    
        public static function getModuleInfo() {
    
            return array(
                'title' => 'My Social Networks Integration module',
                'version' => 010,
                'summary' => 'An example module',
                'singular' => true,
                'autoload' => true,
            );
        }
    
        public function init() {
            require_once 'facebook-php-sdk/src/facebook.php';
            $this->facebook = new Facebook(array('appId' => 'xxxx','secret' => 'xxxx'));
            $user = $this->facebook->getUser();
            if ($user) {
                try {
                    $user_profile = $this->facebook->api('/me');
                } catch (FacebookApiException $e) {
                    error_log($e);
                    $user = null;
                }
            }
            $this->session->fb_user=$user;
            if ($user && $this->session->fb_action) {  $this->postToFacebook();  }
            $this->pages->addHookAfter('save', $this, 'afterSave');
        }
    
        function postToFacebook() {
          $this->session->remove('fb_action');
          $this->message("Facebook: post ");
        }
        
        public function afterSave($event) {
            $page = $event->arguments[0];
            if (($page->template == "portfolio-image") || ($page->template == "portfolio-video")) {
                if ($this->session->fb_user) {
                    $this->postToFacebook();
                } else {
                    $this->session->remove('fb_user');
                    $this->session->fb_action=1;
                    $loginUrl = $this->facebook->getLoginUrl();
                    $this->session->redirect($loginUrl);
                }
            }
        }
    
    }
    
     
    • Like 1
  9. Hi. I'm trying to implement ability to post to Facebook after saving a page like this:

    <?php
    
    class MySocialIntegration extends WireData implements Module {
    
        public static function getModuleInfo() {
    
            return array(
                'title' => 'My Social Networks Integration module',
                'version' => 010,
                'summary' => 'An example module',
                'singular' => true,
                'autoload' => true,
            );
        }
    
        public function init() {
            $this->pages->addHookAfter('save', $this, 'afterSave');
        }
    
        public function afterSave($event) {
            $page = $event->arguments[0];
            if (($page->template == "portfolio-image") || ($page->template == "portfolio-video")) {
                require 'facebook-php-sdk/src/facebook.php';
    
                // Create our Application instance (replace this with your appId and secret).
                $facebook = new Facebook(array(
                            'appId' => 'xxxxxxxxxxx',
                            'secret' => 'xxxxxxxxxxxxxxxxxxx',
                        ));
    
                // Get User ID
                $user = $facebook->getUser();
    
                // We may or may not have this data based on whether the user is logged in.
                //
                // If we have a $user id here, it means we know the user is logged into
                // Facebook, but we don't know if the access token is valid. An access
                // token is invalid if the user logged out of Facebook.
    
                if ($user) {
                    try {
                        // Proceed knowing you have a logged in user who's authenticated.
                        $user_profile = $facebook->api('/me');
                    } catch (FacebookApiException $e) {
                        error_log($e);
                        $user = null;
                    }
                }
    
                // Login  will be needed depending on current user state.
                if ($user) {
                    $this->message("Facebook: connected!");
                } else {
                    $this->message("Facebook: redirects...");
                    $loginUrl = $facebook->getLoginUrl();
                    $this->session->redirect($loginUrl);
                }
            }
        }
    
    }
     

    If I'm not logged, it's redirecting to facebook login page, and after successfull login redirects back, but $facebook->getUser() still returns 0 (and also on consequent executions). If I do the same in separate php file (changing $this->session->redirect to header('Location: '...), works lika a charm.

    Help, please!

    • Like 1
×
×
  • Create New...