symfony 1.4 not picking up subdirectory in routing? - symfony-1.4

I have one symfony 1.4 project where I can happily access the symfony app in a subdirectory www.olddomain.com/clients/
I have tried to achieve the same with another seperate project.
www.newdomain.com/clients/ but the routing won't work fully.
I can access www.newdomain.com/clients/ and it picks up the app and displays the login or content as it should BUT the login form submits to /login, NOT /clients/login as happens with the www.olddomain.com/clients/ project
, I have compared the two and cannot see any difference in the setup.
I have set the WebDir:
$this->setWebDir($this->getRootDir().'/content/clients/');
no_script_name is set to true
I have everything that would be in the web root (index.php, .htaccess, css js etc in /clients/.)
.htaccess in both cases contains
RewriteBase /clients/
If I access www.newdomain.com/clients/login it picks up the need to show the login form fine so that indicates my setup is OK BUT the login form which points to route #login is submitting the form to "/login" not "/clients/login".
I've tried dumping the route on both projects when I directly access /clients/login (see below) and have noticed that on the one that works there are a lot more variables in the 'context' including [ prefix: '/clients'] which would seem to be the key. All of this extra context information except the host variable is missing for www.newdomain.com/clients/login.
Can anyone help me understand what this means and how I might address it? How can I get this 'prefix' paramater set.
DOES WORK (www.olddomain.com/clients/login)
object(sfRoute)[31]
protected 'isBound' => boolean true
protected 'context' =>
array
'path_info' => string '/login' (length=6)
'prefix' => string '/clients' (length=8)
'method' => string 'GET' (length=3)
'format' => null
'host' => string 'www.olddomain.com'
'is_secure' => boolean false
'request_uri' => string 'http:/www.olddomain.com/clients/login'
protected 'parameters' =>
array
'module' => string 'sfGuardAuth' (length=11)
........
DOESN'T WORK (www.newdomain.com/clients/login)
object(sfRoute)[47]
protected 'isBound' => boolean true
protected 'context' =>
array
'host' => string 'www.newdomain.com'
protected 'parameters' =>
array
'module' => string 'sfGuardAuth' (length=11)
.....

Related

Silex token authentication

I create my first app with silex. Only logged in users can use the app. In the first page i create a login form, so the user can authenticate. My security provider look like:
$app->register(new Silex\Provider\SecurityServiceProvider(), array(
'security.firewalls' => array(
'secure_area_edison' => array(
'pattern' => '^/admin/',
'form' => array('login_path' => '/', 'check_path' => '/admin/login_check'),
'logout' => array('logout_path' => '/admin/logout', 'invalidate_session' => true),
'users' => function () use ($app) {
return new App\Services\UserProvider($app['db']);
},
),
)
));
Every url after '/admin' require that the user was successfull authenticated. Everything works fine and now i want to extend my app with an API. I create a new controller which retrieves data from database and return a JSON reponse, this work also fine.
But how can the user authenticate for this API? Should i create a new column in my user table like "hash" or "token"? Users which will retrieve the JSON Response must send the token in every get request, is this the correct way?
The url can look:
/admin/api/allProducts/token/<TOKEN>
you should use token base authentication instead of passing token in every get request.
refer : https://github.com/thcolin/silex-simpleuser-jwt

Laravel Cashier fake user subscription for tests

I'm using Laravel's Cashier for billing which is great. I'm trying to be good and keep my code tested but I'm having trouble "faking" a user with a subscription.
I've tried:
$user = App\Models\User::create([
'first_name' => $this->faker->firstName,
'last_name' => $this->faker->lastName,
'email' => $this->faker->email,
'password' => 'password1234',
'stripe_plan' => 'name_of_plan',
'stripe_active' => 1
]);
$this->be($user);
But if I then check $user->onPlan('name_of_plan') I get false :(
Is there a way to do this? As I'm sure you can appreciate I don't really want to launch the payment system until I've got tests to back it up!
Check that 'stripe_plan' and 'stripe_active' are defined as fillable for User. If they aren't then it may not be actually setting those values in User::create() which is why your test fails.
class User extends Model implements AuthenticatableContract, CanResetPasswordContract, BillableContract {
use Authenticatable, CanResetPassword, Billable;
protected $table = 'users';
protected $fillable = [
'first_name',
'last_name',
'email',
'password',
'stripe_plan',
'stripe_active'
];
}

laravel development environment sqlite database does not exist

Trying to use sqlite in development environment. It seems to detect the environment correctly but when I try to migrate to development.sqlite I get exception thrown "database does not exist"
artisan command
php artisan migrate --env=development
bootstrap/start.php
$env = $app->detectEnvironment(array(
'development' => array('localhost'),
));
app/config/development/database.php
<?php
return array(
'default' => 'sqlite',
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/development.sqlite',
'prefix' => '',
)
)
);
As far as I know laravel is supposed to create the file if it does not exist but since it didn't I tried manually creating the file and still get the exception thrown.
UPDATE: Maybe something not right with the env because the same thing happens if I try ':memory' for the database.
UPDATE 2: I tried running the sample unit test but add to TestCase.php
/**
* Default preparation for each test
*
*/
public function setUp()
{
parent::setUp(); // Don't forget this!
$this->prepareForTests();
}
/**
* Creates the application.
*
* #return Symfony\Component\HttpKernel\HttpKernelInterface
*/
public function createApplication()
{
$unitTesting = true;
$testEnvironment = 'testing';
return require __DIR__.'/../../bootstrap/start.php';
}
/**
* Migrates the database and set the mailer to 'pretend'.
* This will cause the tests to run quickly.
*
*/
private function prepareForTests()
{
Artisan::call('migrate');
Mail::pretend(true);
}
And this too gives the same exception though the testing env is already shipped with laravel. So I'll see if I can find any new issues on that.
Wow, typos and wrong paths.
Copying the sqlite array from config/database.php into config/development/database.php I forgot to change the path to the development.sqlite file from
__DIR__.'/../database/development.sqlite'
to
__DIR__.'/../../database/development.sqlite'
And for the in memory test it should have been
':memory:'
instead of
':memory'
I noticed that my database.php file had the following
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
I changed it to read the following, and it worked just fine.
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path('database.sqlite'),
'prefix' => '',
],
One of the problem which I faced was I use "touch storage/database.sqlite" in terminal, so database is created in Storage folder instead of database folder.
in my config/database.php path is database_path('database.sqlite')
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path('database.sqlite'),
'prefix' => '',
],
than I use command "php artisan migrate" which gave me error "Database (/Applications/MAMP/htdocs/FOLDER_NAME/database/database.sqlite) does
not exist."
so it's obvious database file is not in database folder as It was generated in Storage folder, so copy "database.sqlite" from storage folder or run command "touch database/database.sqlite"
Hope that helps.!!
Well, my answer is kinda outdated, but anyway. I faced the same problem, but with Laravel 5, I am using Windows 7 x64. First I manually created SQLite database called 'db' and placed it into storage directory, then fixed my .env file like this:
APP_ENV=local
APP_DEBUG=true
APP_KEY=oBxQMkpqbENPb07bLccw6Xv7opAiG3Jp
DB_HOST=localhost
DB_DATABASE='db'
DB_USERNAME=''
DB_PASSWORD=''
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null`
I thought it would fix my problems, but the command line keeps telling me that database doesn't exist. And then I just checked the path to db in my database.php file and this is why I put database file into storage directory. But nothing changed. And finally I checked db's extension and it was .db, not .sqlite as default extension you see in your sqlite block in database.php. So this is how I reconfigured sqlite piece:
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path().'/db.db',
'prefix' => '',
],
And of course don't forget to set sqlite as default database in your database.php file. Good luck!
For me it was that path to database had to be '/var/www/html' + location to the database in your project. In my case database was stored in database/db.sqlite so DB_DATABASE='/var/www/html/database/db.sqlite'
I had the same error while running a GitHub action test workflow.
For me the solution was to define the relative path to the database archive into the workflow file:
on:
...
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
jobs:
laravel-tests:
...
I think that the previous answers reduce the importance of the config and most likely the developers wanted to get the database file like this:
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => database_path(env('DB_DATABASE', 'database').'.sqlite'), // <- like this
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
Tested on Laravel 9.x

Silex: Set firewalls session lifetime

I'm trying to extend the default lifetime once a user logs in. For the login I'm using the security service provider as follows:
$app = $this->_app;
$this->_app->register(new Silex\Provider\SecurityServiceProvider(), array(
'security.firewalls' => array(
'default' => array(
'pattern' => '^.*$',
'anonymous' => true, // Needed as the login path is under the secured area
'form' => array('login_path' => '/signup/', 'check_path' => 'login_check', 'failure_path' => 'login_failure'),
'logout' => array('logout_path' => '/logout/'), // url to call for logging out
'users' => $this->_app->share(function() use ($app)
{
// Specific class App\User\UserProvider is described below
return new UserProvider($app['db']);
}),
),
),
'security.access_rules' => array(
array('^/restricted/$', 'ROLE_USER'),
)
));
I've tried setting up with the sessions lifetime (cookie) like this:
$this->_app->register(new Silex\Provider\SessionServiceProvider(), array(
'session.storage.options' => array('cookie_lifetime' => (60 * 60 * 12)), // 12 hours
));
But still nothing. Session removes itself after like 15 minutes or so.
How can I extend the login security firewall lifetime to 12 hours?
I think I finally got it working:
Saving sessions in database seemed to solve the problem.
SQL:
CREATE TABLE `session` (
`session_id` varchar(255) NOT NULL,
`session_value` text NOT NULL,
`session_time` int(11) NOT NULL,
PRIMARY KEY (`session_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
PHP:
/* SESSION IN DB */
$this->_app->register(new Silex\Provider\SessionServiceProvider());
$this->_app['session.db_options'] = array(
'db_table' => 'session',
'db_id_col' => 'session_id',
'db_data_col' => 'session_value',
'db_time_col' => 'session_time',
);
$this->_app['session.storage.handler'] = $this->_app->share(function ()
{
return new PdoSessionHandler(
$this->_app['db']->getWrappedConnection(), $this->_app['session.db_options'], $this->_app['session.storage.options']
);
});
Here is a solution if you don't want to store sessions in DB: just increase session.gc_maxlifetime in php.ini.
When sessions are being stored in files, they (by default) get put to /var/lib/php/sessions/ directory. It's clear that this directory has to be cleared from time to time. In order to achieve this, there is a cron job configured at /etc/cron.d/php5 that fires script /usr/lib/php5/sessionclean every 30 minutes. This script takes php config and gets session.gc_maxlifetime from there and then removes files that are older than what is specified in this variable.
The problem is: by default session.gc_maxlifetime equals to 1440 seconds or 24 minutes. You can increase it to whatever value suits you, for instance to 24 hours (and limit your sessions by session cookie lifetime).

Change prefix of tables once platform is installed

I'm working on a new website. A friend of mine configured Drupal 7 on our hosting service and we started to work. Unfortunately he forgot to add, during the setting phase, a prefix to Drupal standard tables.
Is it possible to change this configuration after having installed Drupal (in order to dont loose the work we have already done after the installation)?
I could do it via SQL code, but I guess that the platform will crash in this way because the code is generated according to the initial settings, right?
(PS: I dont have so much experience with Drupal).
Thanks!
I have similar issue, I found it is very easy to do this in phpmyadmin.
I assume your table prefix is "drupal_", and the target prefix is "new_"
step 1: login to phpmyadmin, chose your database;
step 2: under table list bottom , click "check all" checkbox;
step 3: select action "Replace table prefix";
step 4: Type "drupal_" into "From" and "new_" to "To", click "Go"
You can see the prefix was change to new_tablename
enjoy : )
oh, don't forget to change your settings.php:
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'databasename',
'username' => 'username',
'password' => 'password',
'host' => 'localhost',
'prefix' => 'new_', // <-- add your prefix here
);
If you change the table names via SQL commands (add the prefix), you can set the prefix in your site's settings.php file. Assuming you have just one site, your settings.php file would be in your sites/default/ directory.
Look for your database configurations that would look something like the following and add your desired prefix:
$databases['default']['default'] = array(
'driver' => 'mysql',
'database' => 'databasename',
'username' => 'username',
'password' => 'password',
'host' => 'localhost',
'prefix' => '', // <-- add your prefix here
);

Resources