Last active
May 10, 2016 10:36
-
-
Save Code-Hex/c50ecaf325eef6b3b7a3161645a41048 to your computer and use it in GitHub Desktop.
sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sub github_auth { | |
| my $self = shift; | |
| my $config = $self->config->{github}->{user}; | |
| # login してない場合 | |
| unless ($self->is_login) { | |
| # error 処理 | |
| if (my $error = $self->param('error')) { | |
| return $self->render( | |
| text => "Call to github returned: $error" | |
| ); | |
| # 成功した場合 | |
| } else { | |
| $self->delay( | |
| sub { | |
| my $delay = shift; | |
| $self->oauth2->get_token(github => $delay->begin); | |
| }, | |
| sub { | |
| # oauth 成功した時はこれが実行される | |
| my ($delay, $error, $data) = @_; | |
| return $self->render(error => $error) unless $data->{access_token}; | |
| my $user = github($data->{access_token}); | |
| if ($user->{name} eq $config->{name} | |
| and $user->{login} eq $config->{login} | |
| and $user->{created_at} eq $config->{created_at}) { | |
| $self->session('session_id' => $self->sid); | |
| $self->redirect_to('/admin'); | |
| return 1; | |
| } | |
| $self->redirect_to('/fail'); | |
| }, | |
| ); | |
| } | |
| } else { | |
| $self->redirect_to('/admin'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment