| 1 | package Yukki::Web::View::Login; | ||
| 2 | $Yukki::Web::View::Login::VERSION = '0.991_002'; # TRIAL | ||
| 3 | |||
| 4 | $Yukki::Web::View::Login::VERSION = '0.991002';use v5.24; | ||
| 5 | use utf8; | ||
| 6 | use Moo; | ||
| 7 | |||
| 8 | use Type::Utils; | ||
| 9 | |||
| 10 | use namespace::clean; | ||
| 11 | |||
| 12 | extends 'Yukki::Web::View'; | ||
| 13 | |||
| 14 | # ABSTRACT: show a login form | ||
| 15 | |||
| 16 | |||
| 17 | has login_template => ( | ||
| 18 | is => 'ro', | ||
| 19 | isa => class_type('Template::Pure'), | ||
| 20 | lazy => 1, | ||
| 21 | builder => '_build_login_template', | ||
| 22 | ); | ||
| 23 | |||
| 24 | sub _build_login_template { | ||
| 25 | shift->prepare_template( | ||
| 26 | template => 'login/page.html', | ||
| 27 | directives => [ | ||
| 28 | 'form@action' => 'login_submit_url', | ||
| 29 | ], | ||
| 30 | ); | ||
| 31 | } | ||
| 32 | |||
| 33 | has profile_template => ( | ||
| 34 | is => 'ro', | ||
| 35 | isa => class_type('Template::Pure'), | ||
| 36 | lazy => 1, | ||
| 37 | builder => '_build_profile_template', | ||
| 38 | ); | ||
| 39 | |||
| 40 | sub _build_profile_template { | ||
| 41 | shift->prepare_template( | ||
| 42 | template => 'login/profile.html', | ||
| 43 | directives => [ | ||
| 44 | 'form@action' => 'profile_submit_url', | ||
| 45 | 'input.login_name@value' => 'user.login_name', | ||
| 46 | 'div.login_name' => 'user.login_name', | ||
| 47 | '.name@value' => 'name', | ||
| 48 | '.email@value' => 'email', | ||
| 49 | ], | ||
| 50 | ); | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 54 | sub page { | ||
| 55 | my ($self, $ctx) = @_; | ||
| 56 | |||
| 57 | return $self->render_page( | ||
| 58 | template => $self->login_template, | ||
| 59 | context => $ctx, | ||
| 60 | vars => { | ||
| 61 | 'login_submit_url' => $ctx->rebase_url('login/submit'), | ||
| 62 | }, | ||
| 63 | ); | ||
| 64 | } | ||
| 65 | |||
| 66 | |||
| 67 | sub profile { | ||
| 68 | my ($self, $ctx, $name, $email) = @_; | ||
| 69 | |||
| 70 | $ctx->response->page_title('Profile of ' . $ctx->session->{user}{name}); | ||
| 71 | |||
| 72 | return $self->render_page( | ||
| 73 | template => $self->profile_template, | ||
| 74 | context => $ctx, | ||
| 75 | vars => { | ||
| 76 | profile_submit_url => $ctx->rebase_url('profile/update'), | ||
| 77 | user => $ctx->session->{user}, | ||
| 78 | name => $name // $ctx->session->{user}{name}, | ||
| 79 | email => $email // $ctx->session->{user}{email}, | ||
| 80 | }, | ||
| 81 | ); | ||
| 82 | } | ||
| 83 | |||
| 84 | 1; | ||
| 85 | |||
| 86 | __END__ | ||
| 87 | |||
| 88 | =pod | ||
| 89 | |||
| 90 | =encoding UTF-8 | ||
| 91 | |||
| 92 | =head1 NAME | ||
| 93 | |||
| 94 | Yukki::Web::View::Login - show a login form | ||
| 95 | |||
| 96 | =head1 VERSION | ||
| 97 | |||
| 98 | version 0.991_002 | ||
| 99 | |||
| 100 | =head1 DESCRIPTION | ||
| 101 | |||
| 102 | Renders the login form. | ||
| 103 | |||
| 104 | =head1 METHODS | ||
| 105 | |||
| 106 | =head2 page | ||
| 107 | |||
| 108 | Renders the login page. | ||
| 109 | |||
| 110 | =head2 profile | ||
| 111 | |||
| 112 | Renders the user profile page. | ||
| 113 | |||
| 114 | =head1 AUTHOR | ||
| 115 | |||
| 116 | Andrew Sterling Hanenkamp <hanenkamp@cpan.org> | ||
| 117 | |||
| 118 | =head1 COPYRIGHT AND LICENSE | ||
| 119 | |||
| 120 | This software is copyright (c) 2017 by Qubling Software LLC. | ||
| 121 | |||
| 122 | This is free software; you can redistribute it and/or modify it under | ||
| 123 | the same terms as the Perl 5 programming language system itself. | ||
| 124 | |||
| 125 | =cut |