8000 Use default email address from Github · laravelio/laravel.io@4648f67 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4648f67

Browse files
committed
Use default email address from Github
1 parent ffcbf77 commit 4648f67

File tree

6 files changed

+36
-15
lines changed

6 files changed

+36
-15
lines changed

app/Lio/Accounts/UserCreator.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,25 @@ public function __construct(UserRepository $users)
1515
$this->users = $users;
1616
}
1717

18-
public function create(UserCreatorListener $observer, $data, $validator = null)
18+
public function create(UserCreatorListener $listener, $data, $validator = null)
1919
{
2020
// check the passed in validator
2121
if ($validator && ! $validator->isValid()) {
22-
return $observer->userValidationError($validator->getErrors());
22+
return $listener->userValidationError($validator->getErrors());
2323
}
24-
return $this->createValidUserRecord($observer, $data);
24+
25+
return $this->createValidUserRecord($listener, $data);
2526
}
2627

27-
private function createValidUserRecord($observer, $data)
28+
private function createValidUserRecord($listener, $data)
2829
{
2930
$user = $this->users->getNew($data);
3031

3132
// check the model validation
32-
if ( ! $this->users->save($user)) {
33-
return $observer->userValidationError($user->getErrors());
33+
if (! $this->users->save($user)) {
34+
return $listener->userValidationError($user->getErrors());
3435
}
3536

36-
return $observer->userCreated($user);
37+
return $listener->userCreated($user);
3738
}
3839
}

app/Lio/Accounts/UserRepository.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,15 @@ public function getFirstX($count)
3535
{
3636
return $this->model->take($count)->get();
3737
}
38+
39+
/**
40+
* Determine if an email already exists for a user
41+
*
42+
* @param string $email
43+
* @return bool
44+
*/
45+
public function emailExists($email)
46+
{
47+
return (bool) User::where('email', $email)->count();
48+
}
3849
}

app/Lio/Github/GithubAuthenticator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ private function loginUser($listener, $user, $githubData)
3939

4040
$user->fill($githubData);
4141
$this->users->save($user);
42+
4243
return $listener->userFound($user);
4344
}
4445
}

app/Lio/Github/GithubUserDataReader.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ class GithubUserDataReader
77
public function getDataFromCode($code)
88
{
99
$data = $this->readFromGithub($code);
10+
1011
return $this->formatData($data);
1112
}
1213

1314
private function readFromGithub($code)
1415
{
1516
$github = OAuth::consumer('GitHub');
16-
$oauthTokenObject = $github->requestAccessToken($code);
17+
1718
$githubData = json_decode($github->request('user'), true);
18-
$githubData['email'] = last(json_decode($github->request('user/emails'), true));
19+
1920
return $githubData;
2021
}
2122

app/controllers/AuthController.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public function getLogin()
1111
if (Input::has('code')) {
1212
return App::make('Lio\Github\GithubAuthenticator')->authByCode($this, Input::get('code'));
1313
}
14+
1415
// redirect to the github authentication url
1516
return $this->redirectTo((string) OAuth::consumer('GitHub')->getAuthorizationUri());
1617
}
@@ -19,6 +20,7 @@ public function getLogin()
1920
public function getLogout()
2021
{
2122
Auth::logout();
23+
2224
return $this->redirectAction('HomeController@getIndex');
2325
}
2426

@@ -31,18 +33,20 @@ public function getLoginRequired()
3133
// the confirmation page that shows a user what their new account will look like
3234
public function getSignupConfirm()
3335
{
34-
if ( ! Session::has('userGithubData')) {
36+
if (! Session::has('userGithubData')) {
3537
return $this->redirectAction('AuthController@getLogin');
3638
}
39+
3740
$this->view('auth.signupconfirm', ['githubUser' => Session::get('userGithubData')]);
3841
}
3942

4043
// actually creates the new user account
4144
public function postSignupConfirm()
4245
{
43-
if ( ! Session::has('userGithubData')) {
46+
if (! Session::has('userGithubData')) {
4447
return $this->redirectAction('AuthController@getLogin');
4548
}
49+
4650
return App::make('Lio\Accounts\UserCreator')->create($this, Session::get('userGithubData'));
4751
}
4852

@@ -56,6 +60,7 @@ public function userCreated($user)
5660
{
5761
Auth::login($user, true);
5862
Session::forget('userGithubData');
63+
5964
return $this->redirectIntended(action('HomeController@getIndex'));
6065
}
6166

@@ -64,6 +69,7 @@ public function userFound($user)
6469
{
6570
Auth::login($user, true);
6671
Session::forget('userGithubData');
72+
6773
return $this->redirectIntended(action('HomeController@getIndex'));
6874
}
6975

@@ -75,6 +81,7 @@ public function userIsBanned($user)
7581
public function userNotFound($githubData)
7682
{
7783
Session::put('userGithubData', $githubData);
84+
7885
return $this->redirectAction('AuthController@getSignupConfirm');
7986
}
8087
}

app/views/auth/signupconfirm.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
@section('content')
44
<section class="auth">
5-
<h1>We&#39;re going to create an account with this information.</h1>
5+
<h1>We're going to create an account with this information.</h1>
66

77
<div class="user">
88
{{ Form::open() }}
99
<img src="{{ $githubUser['image_url'] }}"/>
1010
<div class="bio">
11-
@if(isset($githubUser['name']))
11+
@if (isset($githubUser['name']))
1212
<h2>{{ $githubUser['name'] }}</h2>
1313
@endif
14-
@if(isset($githubUser['email']))
15-
<h3>{{ $githubUser['email'] }}</h3>
14+
@if (isset($githubUser['email']))
15+
<p>{{ $githubUser['email'] }}</p>
1616
@endif
1717
{{ Form::submit('Create My Laravel.IO Account', ['class' => 'button']) }}
1818
</div>

0 commit comments

Comments
 (0)
0