| Line | |
|---|
| 1 | package MobileCat::Controller::Signup; |
|---|
| 2 | use strict; |
|---|
| 3 | use warnings; |
|---|
| 4 | use base 'Catalyst::Controller'; |
|---|
| 5 | |
|---|
| 6 | sub index :Private { |
|---|
| 7 | my ($self, $c) = @_; |
|---|
| 8 | $c->view('TT')->template('signup/index.tt'); |
|---|
| 9 | } |
|---|
| 10 | |
|---|
| 11 | sub entry :Local { |
|---|
| 12 | my ($self, $c) = @_; |
|---|
| 13 | |
|---|
| 14 | if ($c->forward('/auth/authenticate_mobileid')) { |
|---|
| 15 | $c->stash->{error} = 'already exists'; |
|---|
| 16 | return; |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | if (not $c->forward('/auth/confirm_mobile')) { |
|---|
| 20 | $c->stash->{error} = $c->stash->{auth_error} || 'unknown'; |
|---|
| 21 | return; |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | $c->forward('create'); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | sub create :Private { |
|---|
| 28 | my ($self, $c) = @_; |
|---|
| 29 | |
|---|
| 30 | my $user = $c->model('Users')->create({ |
|---|
| 31 | username => undef, |
|---|
| 32 | mobile_id => $c->req->mobile_agent->user_id, |
|---|
| 33 | }); |
|---|
| 34 | |
|---|
| 35 | $c->stash->{ticket} = $c->model('Tickets')->create({ |
|---|
| 36 | action => 'signup', |
|---|
| 37 | user_id => $user->id, |
|---|
| 38 | }); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | sub welcome :Private { |
|---|
| 42 | my ($self, $c) = @_; |
|---|
| 43 | |
|---|
| 44 | my $user = $c->stash->{ticket}->user; |
|---|
| 45 | $c->req->param(username => $user->mobile_id); |
|---|
| 46 | $c->req->param(email => $c->req->param('sender')); |
|---|
| 47 | $c->form( |
|---|
| 48 | username => [ 'NOT_BLANK' ], |
|---|
| 49 | email => [ 'NOT_BLANK', 'EMAIL_MOBILE_JP' ], |
|---|
| 50 | ); |
|---|
| 51 | |
|---|
| 52 | if ($c->form->has_error) { |
|---|
| 53 | return; |
|---|
| 54 | } |
|---|
| 55 | if ($user->enable($c->form->valid)) { |
|---|
| 56 | $c->view('Email')->send('mail/welcome.tt', { |
|---|
| 57 | to => $user->email, |
|---|
| 58 | }); |
|---|
| 59 | } else { |
|---|
| 60 | $c->log->error('user enable error. user_id:'. $user->id); |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | 1; |
|---|