Thursday, July 10, 2014

Bitnami Moodle AWS Username and Password

While working on some software that integrates with popular LMS frameworks, I wanted to have a server which I could test Moodle on. I found a community image published by Bitnami and launched an EC2 image from it. When I went to login, I was not sure the login credentials.

After some searching, I realized that Bitnami had a page that listed all their images along with the default credentials for each one. I tried the one for Moodle and it worked.

The default credentials I was look for were:
username: user
password: bitnami

Thursday, April 17, 2014

Laravel 4: CSRF TokenMismatchException when using stored form values

One of my client's Laravel web sites was having issues with logging in users where the first time, they would get the TokenMismatchException (gracefully handled, of course) and then they could log in as expected.

My first thought was that for some reason the browser was storing the _token value along with their login credentials, so I wanted to force Laravel to regenerate the CSRF token and use one that had not already expired. While I could find no easy handle to regenerate the CSRF token, I did find that I could regenerate the session ID which would ultimately cause the same result.


Note: This problem only existed when users were not logged in, otherwise regenerating the session ID might have interrupted their session.

Monday, March 3, 2014

Google Maps API Controls Do Not Display with Bootstrap

Adding a Google Maps API control to a web page, I found that the controls were failing to render properly. They looked like this:

It happens that a generic style in my Bootstrap theme was causing the issue. By adding two additional CSS rules, we can override the Bootstrap changes, and restore our controls.

.gm-style img { max-width: none; }
.gm-style label { width: auto; display: inline; }

Wednesday, February 19, 2014

Laravel 4: Model Hydrate

While converting some older Laravel code, I ran into an issue where the hydrate method had been removed. My usage was similar to this:

$raw_result = DB::query(...);
$hydrated_models = Model::hydrate(new Model(), $data);

While the method may have been removed, there are other methods which can be used to achieve the same outcome. One such method is the newFromBuilder method which can be used as follows:

$raw_result = DB::select(...);
$collection = new \Illuminate\Database\Eloquent\Collection();
foreach ($raw_result as $raw_obj)
     $model = new Model();

If you would like to abstract this process into a static method on the model. You can do so by creating a BaseModel extending Eloquent in which other models you want to have the hydrate method can extend. 

For example: 

use Illuminate\Database\Eloquent\Collection;
class BaseModel extends Eloquent

     * Hydrate method
     * @param array $data
     * @return Illuminate\Database\Eloquent\Collection
    static public function hydrate($data)
        // get calling class so we can hydrate using that type
        $klass = get_called_class();
        // psuedo hydrate
        $collection = new Collection();
        foreach ($data as $raw_obj)
            $model = new $klass;
        return $collection;


class User extends BaseModel
    /* ... */

// Usage of hydrate
$user_collection = User::hydrate($data);

Along with Model::hydrate, the DB::query method no longer exists. See more changes happening when upgrading from Laravel 3 to Laravel 4.

Tuesday, February 4, 2014

TomatoCart: Changing text (Fixing maintenance mode message)

Working with a client, I noticed that the maintenance mode message shown when the store was in maintenance mode had misspelled the word "later" as "latter".

It was simple enough, I had to edit the English language file and edit the database stored English phrase.

  1. Fix the language file: includes/languages/en_US.xml
  2. Fix the stored database value: SELECT * FROM languages_definitions WHERE definition_value LIKE '%latter%';
  3. Clear the cache files in the admin. Start > Tools > Cache Control