Centre de Ressources Informatiques Université Paul Verlaine - Metz Ile du Saulcy BP 80794 57012 Metz Cedex 1
Accès rapide
Avoir un compte
23 : 10 [CriNET] OUVERT Intervention switch sale123
4:3 wheezy (page systèmes verouillée)
22 : 11 [CriNET] INFO Intervention tickets de support
21 : 11 [CriNET] FERME Maintenance proxy Metz
S'abonner au flux RSS
Impossible de charger http://factuel.univ-lorraine.fr/feed/rss-breves.xml
Rechargez cette page
Tickets CRINet
Intervention switch sale123
Intervention tickets de support
coupure réseau
Maintenance proxy Metz


This test application aims to manage a meeting. Users can register by asking a login than they can choose a hotel.

# jifty app --name YvesTestApp
Can't guess application root from current path ...
Creating new application YvesTestApp
Creating directory lib
Creating directory lib/YvesTestApp
Creating directory bin
Creating directory etc
Creating directory doc
Creating directory log
Creating directory var
Creating directory var/mason
Creating directory share
Creating directory share/po
Creating directory share/web
Creating directory share/web/templates
Creating directory share/web/static
Creating directory lib/YvesTestApp/Model
Creating directory lib/YvesTestApp/Action
Creating directory t
Creating configuration file YvesTestApp/etc/config.yml


We will write models for our data

# cd YvesTestApp
# jifty model --name User
Writing file  lib/YvesTestApp/Model/User.pm
Writing file  t/00-model-User.t
# jifty model --name Hotel
# jifty model --name Inscrit

We will use Login plugin for user
in lib/YvesTestApp/Model/User.pm
use strict;
use warnings;
package YvesTestApp::Model::User;
use base qw/Jifty::Plugin::Login::Model::User/;

# Your model-specific methods go here.


in lib/YvesTestApp/Model/Hotel.pm
use YvesTestApp::Record schema {



       column name =>
           type is 'text',
           label is 'Nom',
           is mandatory;
       column address =>
           label is 'Adresse',
           render_as 'Textarea',
           type is 'text';
      column maxrooms =>
           type is 'integer',
           label is 'Nombre de chambres';

to allow all registred user to see hotels datas, we will override current_user_can function.
=head2 current_user_can ACTION

Let everybody read. 
Only allow logged-in users to create and edit. 
Otherwise, allow anyone.


sub current_user_can {
    my $self = shift;
    my $type = shift;

    if ($type eq 'create' || $type eq 'update') {
        return 0 if
           && !$self->current_user->id;
        return 1;
    } elsif($type eq 'read') {
        return 1;

    return $self->SUPER::current_user_can($type, @_);

in lib/YvesTestApp/Model/Inscrit.pm
we make foreign keys between User and Hotel models
use YvesTestApp::Model::User;
use YvesTestApp::Model::Hotel;

use YvesTestApp::Record schema {
       column user =>
               refers_to YvesTestApp::Model::User;
       column hotel =>
              refers_to YvesTestApp::Model::Hotel;


=head2 current_user_can ACTION

Let everybody read. 
Only allow logged-in users to create and edit. 
Otherwise, allow anyone.


sub current_user_can {
    my $self = shift;
    my $type = shift;

    if ($type eq 'create' || $type eq 'update') {
        return 0 if
           && !$self->current_user->id;
        return 1;
    } elsif($type eq 'read') {
        return 1;

    return $self->SUPER::current_user_can($type, @_);


# jifty schema --setup
INFO - Generating SQL for application YvesTestApp...
INFO - Using YvesTestApp::Model::inscrit
INFO - Using YvesTestApp::Model::user
INFO - Using Jifty::Model::Metadata
INFO - Using Jifty::Model::Session
INFO - Using YvesTestApp::Model::hotel
INFO - Set up version v0.0.1, jifty version 0.609120

To use plugins:

# vi etc/config.yml

   - Login: {}
   - EditInPlace: {}

# jifty server        
INFO - You can connect to your server at http://localhost:8888/

Trouble :
This error message appears on some servers :
Application schema version in database (1e-06) doesn't match application schema version (0.0.1)
# sqlite3 yvestestapp
sqlite> update _jifty_metadata set value='v0.0.1' where id='1';
sqlite> .exit

View / Action

This view is only for registred users (Jifty->web->current_user->id)

create file share/web/templates/register
my $user= Jifty->web->current_user->id;

unless ($user) {
    Jifty->web->tangent(url => '/login/');

my $record = YvesTestApp::Model::Inscrit->new();

my $action_class =  ($record->id)?'UpdateInscrit':'CreateInscrit';

my $action = Jifty->web->new_action(class=>$action_class, record => $record);

<&|/_elements/wrapper, title => "Hôtel" &>
Choisissez votre hôtel :

<‰ Jifty->web->form->start() ‰>


<‰ Jifty->web->form->submit(
    label    => ($record->id)?'Update':'Create') ‰>

<‰ Jifty->web->form->end() ‰>


Actions UpdateInscrit or CreateInscrit are automagically overload from model.
To protect a directory and all other sub pages or sub directory, we can use mason powerfull autohandler or work with controller/dispatcher.


Copy element/nav in your application
cp /usr/share/perl5/auto/Jifty/web/templates/_elements/nav share/web/templates/_elements/

Or use EditInPlace ('Page Info' in bottom of all pages)
to edit and change nav
Here my nav element with submenu subhome and subnav. See a bug in subhome where I need to force SERVER_NAME (??)
my $top = Jifty->web->navigation;
my $subhome=$top->child(Home       => url => "/", sort_order => 1);
   $subhome->child( Book  => url => ($ENV{SERVER_PORT} != 80)
       ? "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/register"
       : "http://$ENV{SERVER_NAME}/register", 
       label=>"Reserver un hotel", sort_order => 5) ;
my $subnav=$top->child(Identification       => url => "/login", sort_order => 2);
   $subnav->child(Quitter       => url => "/logout", sort_order => 3) if    
$top->child(Admin       => url => "/admin/", sort_order => 998);

 if (Jifty->config->framework('AdminMode') ) {
    $top->child(Administration => url => "/__jifty/admin/", sort_order => 998);
    $top->child(OnlineDocs => url => "/__jifty/online_docs/", 
               label => 'Online docs',  sort_order => 999);


To choose your language
in etc/config.yml
    PoDir: share/po
    Lang: fr

You can put your plugin po file in share/po
cp /usr/share/perl5/auto/Jifty/Plugin/Login/po/fr.po share/po/fr.po


in t/00-model-Hotel.t
change $o->create() with  

in t/00-model-Inscrit.t
change $o->create() with  

# cd lib
# prove ../t
All tests successful.
Files=3, Tests=33,  5 wallclock secs ( 4.54 cusr +  0.20 csys =  4.74 CPU)


use of fastCGI
in /etc/apache/conf.d/vhost.conf

# not allow in virtualhost ! (but as many FastCgiServer as you need)
FastCgiServer /var/www/YvesTestApp/bin/jifty -initial-env JIFTY_COMMAND=fastcgi -processes 3

<VirtualHost test.univ-metz.fr>
  ServerName test.univ-metz.fr
  AddHandler fastcgi-script fcgi
  DocumentRoot /var/www/YvesTestApp/share/web/templates
  ScriptAlias /  /var/www/YvesTestApp/bin/jifty/

 <Directory /var/www/YvesTestApp/bin/>
    SetHandler fastcgi-script
    Options +ExecCGI

CustomLog /var/www/YvesTestApp/log/access_log combined
ErrorLog /var/www/YvesTestApp/log/error_log

FastCgiServer /var/www/YvesTestApp2/bin/jifty -initial-env JIFTY_COMMAND=fastcgi -processes 3 
<VirtualHost test2.univ-metz.fr>
  ServerName test2.univ-metz.fr
  AddHandler fastcgi-script fcgi
  DocumentRoot /var/www/YvesTestApp2/share/web/templates
  ScriptAlias /  /var/www/YvesTestApp/bin2/jifty/


Trouble with mysql and fastcgi :
$ FastCGI: server ".... TestApp/bin/jifty" stderr: DBD::mysql::st execute failed:
MySQL server has gone away at /usr/share/perl5/Jifty/DBI/Handle.pm line 485. $
Answer : see mysql_auto_reconnect in etc/config.yml
    Database: 'yvestestapp'
    Driver: mysql
    mysql_auto_reconnect: 1
    Host: localhost

mod_perl handler


Sending mail
in etc/config.yml
  AdminEmail: 'agostini@univ-metz.fr'
  Mailer: 'SMTP'
  MailerArgs: []

this use Net::SMTP

There's a bug with actual Email::MIME 1.855
1.852 works fine