[Catalyst] Create Issue with CRUD application
Hi, I'm new to the Catalyst architecture and have been working through some examples to learn the ropes. However, in the application I am working on, I am able to Update, but not Create a new record. I am using HTML::FormHandler and I believe that the inability to Create a new record has something to do with my setup of the Form Model. Each time I try to create a new record I get the following error. Caught exception in Signup::Web::Controller::users->add "Can't call method "resolve" on an undefined value at C:/strawberry/perl/site/lib/DBIx/Class/Row.pm line 1289."The error leads me to believe that the new_result is not working property with the Form, because if I remove the code and leave the "item" empty the form will generate but of course not allow the new record to be added. Data::Dumper shows that the Item variable looks like this: Item: $VAR1 = bless( {}, 'Signup::Web::Model::signup::User' ); Any idea where I have went wrong so that this error is created when adding new Records and not updates? HFH Form Objectpackage Signup::Web::Form::User; use HTML::FormHandler::Moose; use namespace::autoclean; extends 'HTML::FormHandler::Model::DBIC'; has '+item_class' => ( default =>'Signup::User' ); has_field 'alias'; has_field 'name_first' => ( type => 'Text', 'label' => 'First Name' ); has_field 'name_last' => ( type => 'Text', 'label' => 'Last Name' ); has_field 'email' => ( type => 'Text', required => 1 ); has_field 'submit' => ( type => 'Submit', value => 'Submit' ); __PACKAGE__->meta->make_immutable; 1; User Controller Outlining the "Add" actionpackage Signup::Web::Controller::users; use Moose; use namespace::autoclean; use Signup::Web::Form::User; BEGIN {extends 'Catalyst::Controller'; } =head1 NAME Signup::Web::Controller::users - Catalyst Controller =head1 DESCRIPTION Catalyst Controller. =head1 METHODS =cut =head2 index =cut sub index :Path('/users') :Args(0) { my ( $self, $c ) = @_; $c->load_status_msgs; my $users = [ $c->model('Signup::User')->all ]; my @columns = ( 'namelast', 'email' ); $c->stash( users => $users, columns => \@columns, template => 'users/list.tt2' ); } sub add : Local Args(0) { my ( $self, $c ) = @_; ## Store the empty record in the "record" variable ## for $self->form return $self->form( $c ); } sub edit : Local Args(1) { my ( $self, $c, $user_id ) = @_; ## Store the user that we are going to edit $c->stash( record => $c->model('Signup::User')->find($user_id) ); $c->log->debug("RECORD: edit"); return $self->form($c); } sub form : Private{ my ( $self, $c ) = @_; ## Check if a record is in the stash, if not create an empty result my $item = $c->stash->{record} || $c->model('Signup::User')->new_result({}); $c->log->debug( "Item: " . Data::Dumper->Dump([ $item ])); ## Create a new form object with the proper Item data my $form = Signup::Web::Form::User->new( item => $item ); $c->log->debug( "After new form" ); ## Set the output template and variables required $c->stash( template => 'users/form.tt2', form => $form ); $c->log->debug( "Before Process" ); ## Validate the form return unless $form->process( params => $c->req->parameters ); ## On Succcessfull Validation redirect to the index page $c->response->redirect($c->uri_for($self->action_for('index'), {mid => $c->set_status_msg("User Added")} )); } =head1 AUTHOR A clever guy =head1 LICENSE This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself. =cut __PACKAGE__->meta->make_immutable; 1; ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
RE: [Catalyst] Catalyst Roles With ACL
Sorry I missed that. I suppose it's possible that this call is the issue.. But it was working just fine before I tried to add ACL. sub authenticateOpenid :Path('openid') :Args(0) { my($self, $c) = @_; $c->log->debug( "authenticateOpenID" ); if ( $c->authenticate({}, 'openid') ){ ## Check if the user's profile already exists ## If not create a new one. if ( !$c->forward('userVerify') ){ $c->forward("/login/userCreate" );} $c->res->redirect( $c->uri_for('/') ); } else { # Show Login Form $c->stash('error' => "Sorry your login failed."); $c->res->redirect( $c->uri_for('/login') ); } } > Subject: Re: [Catalyst] Catalyst Roles With ACL > From: bobtf...@bobtfish.net > Date: Tue, 14 Aug 2012 19:12:23 +0100 > To: catalyst@lists.scsys.co.uk > > > On 14 Aug 2012, at 18:12, Blaine Everingham wrote: > > > > When I try and run my program I get > > Failed to load user data. You passed [ARRAY(0x39a8964)] to authenticate() > > but your user source (MyApp::User) only has these columns: > > [id,alias,name_first,name_last,email] Check your authenticate() call. > > > > Any idea on how I can load the roles? > > > You didn't show us the ->authenticate() call in your code that the error > message tells you is the problem. > > Before doing anything else, I'd like to see that call, to check it isn't the > source of the problem ;_) > > Cheers > t0m > > > ___ > List: Catalyst@lists.scsys.co.uk > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ > Dev site: http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Catalyst Roles With ACL
Hi, I am trying to get role based authorization going in my catalyst app. However, I'm encountering difficultly on what should be an easy task. My database basically has four tables for users User - Main User data with foren keys to User Account(has many) and UserToRole (has many) UserAccount - Data to store account login type (ie openid, facebook etc) UserToRole - Linkage table from user to user role UserRole - table with the role names. My Package config looks like: __PACKAGE__->config ( name => "Signup::Web", "Plugin::Authentication" => { default_realm => "facebook", realms => { facebook =>{ credential =>{ class => "FBConnect", api_key => __PACKAGE__->config->{facebookConnect}->{api_key}, secret => __PACKAGE__->config->{facebookConnect}->{secret}, app_name => __PACKAGE__->config->{facebookConnect}->{app_name} }, store => { class => 'DBIx::Class', user_model => 'MyApp::User', role_relation => 'user_to_roles', role_field => 'title' } }, ... more auth types }); When I try and run my program I get Failed to load user data. You passed [ARRAY(0x39a8964)] to authenticate() but your user source (MyApp::User) only has these columns: [id,alias,name_first,name_last,email] Check your authenticate() call. Any idea on how I can load the roles? ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
RE: [Catalyst] Authentication using OpenID
If you want to grab other user data then you have to use an extension openid => { credential => { class => "OpenID", store => { class => "OpenID", }, consumer_secret => "Don't bother setting", ua_class => "LWP::UserAgent", # whitelist is only relevant for LWPx::ParanoidAgent ua_args => { whitelisted_hosts => [qw/ 127.0.0.1 localhost /], }, extensions => [ 'http://openid.net/srv/ax/1.0' => {mode => 'fetch_request','type.nickname' => 'http://axschema.org/namePerson/friendly','type.email' => 'http://axschema.org/contact/email','type.fullname' => 'http://axschema.org/namePerson','type.firstname' => 'http://axschema.org/namePerson/first','type.lastname' => 'http://axschema.org/namePerson/last','type.dob' => 'http://axschema.org/birthDate','type.gender' => 'http://axschema.org/person/gender','type.country' => 'http://axschema.org/contact/country/home','type.language' => 'http://axschema.org/pref/language','type.timezone' => 'http://axschema.org/pref/timezone',required => 'nickname,fullname,email,firstname,lastname',if_available => 'dob,gender,country,language,timezone',} ], }, To: catalyst@lists.scsys.co.uk Subject: RE: [Catalyst] Authentication using OpenID Date: Fri, 10 Dec 2010 20:01:20 +0530 From: vi...@chhikara.org OK. I am able to use "Catalyst::Authentication::Credential::OpenID", and after authenticating with google, I get Catalyst::Plugin::Authentication::User::Hash object, but when i try to get the user details, $c->user->url $c->user->display I am getting exceptions related to method not found. Can we access used details say Name , Email etc using "Catalyst::Authentication::Credential::OpenID" or we have to use something else say oAuth to get details. Basically, I want to simplify the user registration to my app when somebody logs in for the first time. Vivek On Fri, 10 Dec 2010 14:14:38 +, Blaine Everingham wrote: Currently Facebook is not part of OpenID. Therefore you would need to have two different authentication credential modules. OpenID Catalyst::Authentication::Credential::OpenID Facebook Catalyst::Authentication::Credential::FBConnect Date: Fri, 10 Dec 2010 00:11:46 +0530 From: vi...@chhikara.org To: catalyst@lists.scsys.co.uk Subject: [Catalyst] Authentication using OpenID Hi, I want to have my users authenticated using openid. If users are logging in for the first time, I want to get the details, provided by say facebook, to be saved in my DB. Which Catalyst authentication Plug-in should be used in order to achieve this goal. Vivek ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ -- Vivek Chhikara ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
RE: [Catalyst] Authentication using OpenID
Currently Facebook is not part of OpenID. Therefore you would need to have two different authentication credential modules. OpenID Catalyst::Authentication::Credential::OpenID Facebook Catalyst::Authentication::Credential::FBConnect Date: Fri, 10 Dec 2010 00:11:46 +0530 From: vi...@chhikara.org To: catalyst@lists.scsys.co.uk Subject: [Catalyst] Authentication using OpenID Hi, I want to have my users authenticated using openid. If users are logging in for the first time, I want to get the details, provided by say facebook, to be saved in my DB. Which Catalyst authentication Plug-in should be used in order to achieve this goal. Vivek
RE: [Catalyst] Catalyst::Model::DBIC::Schema - Print Debug statement
Thanks Marilyn, You got me thinking that maybe it was a runtime issue with the Perl Interpreter running through Eclipse. Anyhow, when I run the myapp_server.pl from the windows command prompt I see the queries. Blaine Date: Wed, 1 Dec 2010 15:16:23 -0800 Subject: Re: [Catalyst] Catalyst::Model::DBIC::Schema - Print Debug statement From: mari...@marilynburgess.com To: catalyst@lists.scsys.co.uk On linux I start the server with: > DBIC_TRACE=1 myapp_server.pl -r which does the trick. Not sure if the same will work under windows. Marilyn On Wed, Dec 1, 2010 at 3:03 PM, Blaine Everingham wrote: I'm trying to see the queries the actual query code that is submitted to the database when I perform a find on a model. I've tried: 1) Adding $ENV{DBIC_TRACE}++ to the MyApp.pm 2) Setting the Windows7 Environment variable DBIC_TRACE to 1 3) Setting my run configuration in Eclispe with the arguments -d -r AND Environment DBIC_TRACE = 1 Each time I run the myapp_server.pl -d -r it does not show the query executed. Ideally Executing : $c->model("MyDatabase::UserAccount")->find({ realm => $c->user->auth_realm, key => $c->user->url }); Would show the query below in STDOUT SELECT * FROM UserAccount where realm = '' AND key =''; I'm running in a windows environment with strawberry perl and using Eclipse. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Catalyst::Model::DBIC::Schema - Print Debug statement
I'm trying to see the queries the actual query code that is submitted to the database when I perform a find on a model. I've tried: 1) Adding $ENV{DBIC_TRACE}++ to the MyApp.pm 2) Setting the Windows7 Environment variable DBIC_TRACE to 1 3) Setting my run configuration in Eclispe with the arguments -d -r AND Environment DBIC_TRACE = 1 Each time I run the myapp_server.pl -d -r it does not show the query executed. Ideally Executing : $c->model("MyDatabase::UserAccount")->find({ realm => $c->user->auth_realm, key => $c->user->url }); Would show the query below in STDOUT SELECT * FROM UserAccount where realm = '' AND key =''; I'm running in a windows environment with strawberry perl and using Eclipse. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Catalyst::Model::DBIC::Schema - Print Debug statement
I'm trying to see the queries the actual query code that is submitted to the database when I perform a find on a model. I've tried: 1) Adding $ENV{DBIC_TRACE}++ to the MyApp.pm 2) Setting the Windows7 Environment variable DBIC_TRACE to 1 3) Setting my run configuration in Eclispe with the arguments -d -r AND Environment DBIC_TRACE = 1 Each time I run the myapp_server.pl -d -r it does not show the query executed. Ideally Executing : $c->model("MyDatabase::UserAccount")->find({ realm => $c->user->auth_realm, key => $c->user->url }); Would show the query below in STDOUT SELECT * FROM UserAccount where realm = '' AND key =''; I'm running in a windows environment with strawberry perl and using Eclipse. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
RE: [Catalyst] Catalyst::Authentication::Credential::OAuth
Thank you very much for this information. I was pulling my hair out trying OAuth as I thought FBConnect was being depreciated. > Date: Wed, 24 Nov 2010 10:12:27 +0200 > Subject: Re: [Catalyst] Catalyst::Authentication::Credential::OAuth > From: bog...@sinapticode.ro > To: catalyst@lists.scsys.co.uk > > you can also read http://www.catalystframework.org/calendar/2009/4 > > but as far as I know, the OAuth credential doesn't (yet) properly work > with Facebook, there should be a new release soon fixing that. > > On Wed, Nov 24, 2010 at 1:27 AM, Hernan Lopes wrote: > > To integrate facebook login onto your site, > > Have you tried Catalyst::Authentication::Credential::FBConnect ? > > It works and lets you access users facebook id from $c->user->session_uid as > > documented > > > > 1. You need to register under http://developers.facebook.com and register a > > new application. You must include the exact address you will use on the > > machine for it to work ie. "http://localhost:3000/"; > > > > 2. you need to configure include these onto your myapp.conf > > > > > > default_realm facebook > > > > > > > > > > class FBConnect > > api_key my_app_key > > secret my_app_secret > > app_namemy_app_name > > > > > > > > > > > > > > 3. you need a piece of javascript from facebook to create login button > > (replace with your appId/fb_app_id as below): > > > > sub login_facebook : Path('/loginfacebook') : Args(0) { > > my ( $self, $c ) = @_; > > my $fb_app_id = ''; > > $c->stash( template => \< > > > > > > > > > > > > > > > window.fbAsyncInit = function() { > > FB.init({appId: '$fb_app_id', status: true, cookie: true, > > xfbml: true}); > > > > FB.Event.subscribe('auth.sessionChange', function(response) { > > > > if (response.session) { > > // A user has logged in, and a new cookie has been saved > > window.location="/fblogin"; //redirects user to our facebook login > > so we can validate him and get his user id. > > > > } else { > > // The user has logged out, and the cookie has been cleared > > window.location="/"; > > } > > }); > > }; > > > > (function() { > > var e = document.createElement('script'); > > > > e.type = 'text/javascript'; > > e.src = document.location.protocol + > > '//connect.facebook.net/en_US/all.js'; > > e.async = true; > > > > document.getElementById('fb-root').appendChild(e); > > }()); > > > > FBLOGIN > > ); > > } > > > > 4. then , i created an action /fblogin to register facebook credentials > > internally when user logs in (see in the js) > > > > sub fbauthenticate :Path('/fblogin') :Args(0) { > > my ($self, $c) = @_; > > if ($c->authenticate()) { > > $c->log->debug($c->user->session_uid); > > $c->log->debug($c->user->session_key); > > $c->log->debug($c->user->session_expires); > > } > > $c->res->redirect('/'); > > } > > > > > > So remember, register at the http://developer.facebook.com with the same url > > your application will use, include ports if its not 80 > > > > --Hernan > > > > > > On Tue, Nov 23, 2010 at 8:32 PM, Blaine Everingham > > wrote: > >> > >> Hi, > >> > >> I was wondering if anyone has a simple example of using OAuth with > >> facebook to allow user login, to your software. > >> > >> I keep getting the error "oauth_parameters_absent:scope", but > >> Catalyst::Authentication::Credential::OAuth document does not outline where > >> you are supposed to enter this. > >> > >> Thanks, > >> Blaine > >> > >> ___ > >> List: Catalyst@lists.scsys.co.uk > >> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > >> Searchable
[Catalyst] Catalyst::Authentication::Credential::OAuth
Hi, I was wondering if anyone has a simple example of using OAuth with facebook to allow user login, to your software. I keep getting the error "oauth_parameters_absent:scope", but Catalyst::Authentication::Credential::OAuth document does not outline where you are supposed to enter this. Thanks, Blaine ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
RE: [Catalyst] Catalyst with HTML::FormHandler
Sorry the error message is Error: Can't locate MyApp/UserInterface/Form/User.pm in @INC (@INC contains: C:/strawberry/perl/site/lib C:/strawberry/perl/vendor/lib C:/strawberry/perl/lib .) Resource: User.pm Path: /MyApp-Software/lib/MyApp/UserInterface/Controller/Admin Location: line 5 Line 5 of /MyApp-Software/lib/MyApp/UserInterface/Controller/Admin/User.pm is: use MyApp::UserInterface::Form::User; > Date: Fri, 5 Nov 2010 14:40:37 -0400 > From: st...@matsch.com > To: catalyst@lists.scsys.co.uk > Subject: Re: [Catalyst] Catalyst with HTML::FormHandler > > The actual error message would help... > On 11/5/2010 2:33 PM, Blaine Everingham wrote: > > I'm new to Catalyst and and trying to build a simple form. > > > > In the Catalyst controller > > MyApp/UserInterface/Controller/Admin/Users.pm I've added an 'use > > MyApp::UserInterface::Form::User', however it can not find this file. > > Meaning that it's not in the INC path. > > > > Obviously I could push this directory on to the INC stack, but none of > > the examples that I've seen have had to do this. What is the proper > > way to go about this? > > > > Below is an example of the directory structure. > > > > MyApp/UserInterface/Controller > > MyApp/UserInterface/Controller/Admin > > MyApp/UserInterface/Controller/Admin/Users.pm > > MyApp/UserInterface/Form > > MyApp/UserInterface/Form/User.pm > > MyApp/UserInterface/Model > > MyApp/UserInterface/Schema > > MyApp/UserInterface/View > > > > > > ___ > > List: Catalyst@lists.scsys.co.uk > > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > > Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ > > Dev site: http://dev.catalyst.perl.org/ > > ___ > List: Catalyst@lists.scsys.co.uk > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ > Dev site: http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Catalyst with HTML::FormHandler
I'm new to Catalyst and and trying to build a simple form. In the Catalyst controller MyApp/UserInterface/Controller/Admin/Users.pm I've added an 'use MyApp::UserInterface::Form::User', however it can not find this file. Meaning that it's not in the INC path. Obviously I could push this directory on to the INC stack, but none of the examples that I've seen have had to do this. What is the proper way to go about this? Below is an example of the directory structure. MyApp/UserInterface/Controller MyApp/UserInterface/Controller/Admin MyApp/UserInterface/Controller/Admin/Users.pm MyApp/UserInterface/Form MyApp/UserInterface/Form/User.pm MyApp/UserInterface/Model MyApp/UserInterface/Schema MyApp/UserInterface/View ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/