/
Account.pm
102 lines (88 loc) · 2.74 KB
/
Account.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package MetaCPAN::Web::Controller::Account;
use Moose;
use List::MoreUtils qw(pairwise);
use DateTime ();
use JSON::MaybeXS ();
BEGIN { extends 'MetaCPAN::Web::Controller' }
sub auto : Private {
my ( $self, $c ) = @_;
# Keep everything here as specific to the user
# this is for proxies
$c->res->header( Vary => 'Cookie' );
unless ( $c->user_exists ) {
$c->forward('/forbidden');
}
return $c->user_exists;
}
sub logout : Local {
my ( $self, $c ) = @_;
$c->detach('/forbidden') unless ( $c->req->method eq 'POST' );
$c->req->session->expire;
$c->res->redirect(q{/});
}
sub settings : Local {
my ( $self, $c ) = @_;
}
sub identities : Local {
my ( $self, $c ) = @_;
if ( $c->req->method eq 'POST'
&& ( my $delete = $c->req->params->{delete} ) )
{
$c->model('API::User')->delete_identity( $delete, $c->token )->recv;
$c->res->redirect('/account/identities');
}
}
sub profile : Local {
my ( $self, $c ) = @_;
my $author = $c->model('API::User')->get_profile( $c->token )->recv;
$c->stash(
$author->{error} ? { no_profile => 1 } : { author => $author } );
my $req = $c->req;
return unless ( $req->method eq 'POST' );
my $data = $author;
$data->{blog}
= $req->param('blog.url')
? [
pairwise { { url => $a, feed => $b } }
@{ [ $req->param('blog.url') ] },
@{ [ $req->param('blog.feed') ] }
]
: undef;
$data->{donation}
= $req->param('donation.name')
? [
pairwise { { name => $a, id => $b } }
@{ [ $req->param('donation.name') ] },
@{ [ $req->param('donation.id') ] }
]
: undef;
$data->{profile}
= $req->param('profile.name')
? [
pairwise { { name => $a, id => $b } }
@{ [ $req->param('profile.name') ] },
@{ [ $req->param('profile.id') ] }
]
: undef;
$data->{location}
= $req->params->{latitude}
? [ $req->params->{latitude}, $req->params->{longitude} ]
: undef;
$data->{$_} = $req->params->{$_} eq q{} ? undef : $req->params->{$_}
for (qw(name asciiname gravatar_url city region country));
$data->{$_} = [ grep {$_} $req->param($_) ] for (qw(website email));
$data->{extra} = eval {
JSON::MaybeXS->new->relaxed->utf8->decode( $req->params->{extra} );
};
$data->{donation} = undef unless ( $req->params->{donations} );
my $res
= $c->model('API::User')->update_profile( $data, $c->token )->recv;
if ( $res->{error} ) {
$c->stash( { author => $data, errors => $res->{errors} } );
}
else {
$c->stash( { success => 1, author => $res } );
}
}
__PACKAGE__->meta->make_immutable;
1;