Guest User

Untitled

a guest
Jun 18th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. ## Schema.pm
  2. package BoyosPlace::Schema;
  3.  
  4. use strict;
  5. use warnings;
  6.  
  7. use BoyosPlace;
  8. use BoyosPlace::Email;
  9. use base 'DBIx::Class::Schema';
  10.  
  11. __PACKAGE__->load_classes;
  12.  
  13. sub create_user {
  14. my ($self, $options) = @_;
  15.  
  16. $options ||= {};
  17. my $config = BoyosPlace->config;
  18. my $email = BoyosPlace::Email->new(
  19. to => $options->{email},
  20. from => $config->{email}{from},
  21. subject => "Boyosplace.com Registration Confirmation",
  22. data => "Thank you for signing up!",
  23. );
  24.  
  25. my $create = sub {
  26. $self->name( $options->{name} );
  27. $self->email( $options->{email} );
  28. $self->password( $options->{password} );
  29. $email->send;
  30. };
  31.  
  32. $self->txn_do($create);
  33.  
  34. if ($@) {
  35. die "Something went wrong creating a user: $@";
  36. exit
  37. }
  38.  
  39.  
  40. }
  41. 1;
  42.  
  43. ## create action
  44. sub create : Path("/signup") : FormConfig {
  45. my ( $self, $c ) = @_;
  46.  
  47. my $form = $c->stash->{form};
  48. $c->stash->{template} = "users/create.tt2";
  49.  
  50. ## let's make sure we have a valid form
  51. if ( $form->submitted_and_valid ) {
  52.  
  53. my $user = $c->model('DB::Schema')->create_user(
  54. {
  55. name => $form->param('name'),
  56. email => $form->param('email'),
  57. password => $form->param('password')
  58. }
  59. );
  60.  
  61. }
  62.  
  63. }
Add Comment
Please, Sign In to add comment