From db45f710c327186ab62ad5a40344dca20bc9b911 Mon Sep 17 00:00:00 2001 From: Finn Date: Thu, 24 Aug 2017 12:37:53 +0100 Subject: [PATCH] Code fixed, now functioning account edit --- lib/Pear/LocalLoop/Controller/Admin/Users.pm | 21 +++-- templates/admin/users/read.html.ep | 85 ++++++++++++++++---- 2 files changed, 85 insertions(+), 21 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Admin/Users.pm b/lib/Pear/LocalLoop/Controller/Admin/Users.pm index d48e259..2fbc110 100644 --- a/lib/Pear/LocalLoop/Controller/Admin/Users.pm +++ b/lib/Pear/LocalLoop/Controller/Admin/Users.pm @@ -1,17 +1,28 @@ package Pear::LocalLoop::Controller::Admin::Users; use Mojo::Base 'Mojolicious::Controller'; +use Try::Tiny; use Data::Dumper; -has result_set => sub { +has user_result_set => sub { my $c = shift; return $c->schema->resultset('User'); }; +has customer_result_set => sub { + my $c = shift; + return $c->schema->resultset('Customer'); +}; + +has organisation_result_set => sub { + my $c = shift; + return $c->schema->resultset('Organisation'); +}; + sub index { my $c = shift; - my $user_rs = $c->result_set; + my $user_rs = $c->user_result_set; $user_rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); $c->stash( users => [ $user_rs->all ] ); } @@ -21,7 +32,7 @@ sub read { my $id = $c->param('id'); - if ( my $user = $c->result_set->find($id) ) { + if ( my $user = $c->user_result_set->find($id) ) { $c->stash( user => $user ); } else { $c->flash( error => 'No User found' ); @@ -36,14 +47,14 @@ sub edit { my $user; - unless ( $user = $c->result_set->find($id) ) { + unless ( $user = $c->user_result_set->find($id) ) { $c->flash( error => 'No User found' ); return $c->redirect_to( '/admin/users/' . $id ); } my $validation = $c->validation; - my $not_myself_user_rs = $c->result_set->search({ + my $not_myself_user_rs = $c->user_result_set->search({ id => { "!=" => $user->id }, }); $validation->required('email')->email->not_in_resultset( 'email', $not_myself_user_rs ); diff --git a/templates/admin/users/read.html.ep b/templates/admin/users/read.html.ep index eaca969..9cf6740 100644 --- a/templates/admin/users/read.html.ep +++ b/templates/admin/users/read.html.ep @@ -11,20 +11,73 @@ Success! <%= $success %> % } -
-
- - -
-
- - -
-
- - -
-
- -
+ +

+ User Details +

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ % if ( my $customer_rs = $user->customer ) { +

+ Customer Details +

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ % } elsif ( my $org_rs = $user->organisation ) { +

+ Organisation Details +

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ % } else { +

+ User is not a customer or an organisation +

+ % } + +
+ +