Login page and collection entries fields filtering


#1

Hello world! Im junior frontend developer and Im bad with backend. Im trying to do a Vue app using Cockpit CMS and I have 2 questions:

  1. What is the simplest way to create login page different fron index page, becouse I want to mount my app in index page. For example, one page like login.php for auth and other incorrect urls will be redirected to index page.
  2. Can I change collection entries text fields using php script before they will be inserted to database? For example, I want to unshort short links.
    P.S. Sorry for ma engleas

#2

Hey @bulich,

not sure if got your first point! But if you are trying to build a vue.js app, believe you are using Cockpit merely as a headless system, so completely isolated from your cockpit code!

You have some event hooks you can apply for collections and change the data before its saved in the database, you can use:

$app->on('collections.save.before.collectionname', function($name, &$entry) use($app) {
  // access entry array and change according to your needs
});

“collectioname” is the name of your collection

you can put that code in an addon (e.g. addons/youraddon/bootstrap.php) or in config/bootstrap.php


#3

Thanks for the answer @pauloamgomes. I mean if I mount my app in index.php this way:
index

So defualt auth/dashboard route doesn’t work anymore so I just can’t login to backend.


#4

But why not have your FE app completely separated from cockpit?

If you still need to do that way, you should create a new route and rebind the admin route to it:

$app->on('admin.init', function() {
    $this->bind('/', function(){
        return $this->invoke('MyAddon\\Controller\\Admin', 'index');
    });
    $this->bind('/cockpit/dashboard', function(){
        return $this->invoke('MyAddon\\Controller\\Admin', 'index');
    });
});

and you need to have:

MyAddon/Controller/Admin.php
<?php

namespace MyAddon\Controller;

use \Cockpit\AuthController;

class Admin extends AuthController {

  public function index() {
    return $this->render('myaddon:views/index.php', []);
  }
}

and on MyAddon/views/index.php you include the markup for your vue app


#5

Ok, I got it. I think its better to separate my app from cockpit. Thanks again @pauloamgomes !