@@ -12,20 +12,20 @@ discard block |
||
12 | 12 | { |
13 | 13 | public function redirectTo() |
14 | 14 | { |
15 | - $accountModel = new AccountModel(); |
|
16 | - if(Auth::check()){ |
|
15 | + $accountModel=new AccountModel(); |
|
16 | + if (Auth::check()) { |
|
17 | 17 | $info=$accountModel->detail(Auth::user()->id); |
18 | - if(Auth::check() && $info['contest_account']){ |
|
18 | + if (Auth::check() && $info['contest_account']) { |
|
19 | 19 | return redirect('/account/settings'); |
20 | 20 | } |
21 | 21 | } |
22 | - if(Auth::check() && $accountModel->getExtra(Auth::user()->id ,'github_id')){ |
|
23 | - return view('oauth.index',[ |
|
22 | + if (Auth::check() && $accountModel->getExtra(Auth::user()->id, 'github_id')) { |
|
23 | + return view('oauth.index', [ |
|
24 | 24 | 'page_title'=>"OAuth", |
25 | 25 | 'site_title'=>config("app.name"), |
26 | 26 | 'navigation'=>"OAuth", |
27 | 27 | 'platform' => 'Github', |
28 | - 'display_html' => 'You\'re already tied to the github account : <span class="text-info">'.$accountModel->getExtra(Auth::user()->id ,'github_email').'</span><br /> |
|
28 | + 'display_html' => 'You\'re already tied to the github account : <span class="text-info">'.$accountModel->getExtra(Auth::user()->id, 'github_email').'</span><br /> |
|
29 | 29 | You can choose to unbind or go back to the homepage', |
30 | 30 | 'buttons' => [ |
31 | 31 | [ |
@@ -45,19 +45,19 @@ discard block |
||
45 | 45 | |
46 | 46 | public function handleCallback() |
47 | 47 | { |
48 | - try{ |
|
49 | - $github_user = Socialite::driver('github')->user(); |
|
50 | - }catch(\Laravel\Socialite\Two\InvalidStateException $e){ |
|
48 | + try { |
|
49 | + $github_user=Socialite::driver('github')->user(); |
|
50 | + } catch (\Laravel\Socialite\Two\InvalidStateException $e) { |
|
51 | 51 | return redirect('/'); |
52 | 52 | } |
53 | 53 | |
54 | - $accountModel = new AccountModel(); |
|
55 | - if(Auth::check()){ |
|
56 | - $user_id = Auth::user()->id; |
|
57 | - $ret = $accountModel->findExtra('github_id',$github_user->id); |
|
58 | - if(!empty($ret) && $ret['uid'] != $user_id){ |
|
59 | - $user = UserModel::find($ret['uid']); |
|
60 | - return view('oauth.index',[ |
|
54 | + $accountModel=new AccountModel(); |
|
55 | + if (Auth::check()) { |
|
56 | + $user_id=Auth::user()->id; |
|
57 | + $ret=$accountModel->findExtra('github_id', $github_user->id); |
|
58 | + if (!empty($ret) && $ret['uid']!=$user_id) { |
|
59 | + $user=UserModel::find($ret['uid']); |
|
60 | + return view('oauth.index', [ |
|
61 | 61 | 'page_title'=>"OAuth", |
62 | 62 | 'site_title'=>config("app.name"), |
63 | 63 | 'navigation'=>"OAuth", |
@@ -72,17 +72,17 @@ discard block |
||
72 | 72 | ] |
73 | 73 | ]); |
74 | 74 | } |
75 | - $accountModel->setExtra($user_id,'github_id',$github_user->id); |
|
76 | - $accountModel->setExtra($user_id,'github_email',$github_user->email); |
|
77 | - $accountModel->setExtra($user_id,'github_nickname',$github_user->nickname); |
|
78 | - $accountModel->setExtra($user_id,'github_homepage',($github_user->user)['html_url']); |
|
79 | - $accountModel->setExtra($user_id,'github_token',$github_user->token,101); |
|
80 | - return view('oauth.index',[ |
|
75 | + $accountModel->setExtra($user_id, 'github_id', $github_user->id); |
|
76 | + $accountModel->setExtra($user_id, 'github_email', $github_user->email); |
|
77 | + $accountModel->setExtra($user_id, 'github_nickname', $github_user->nickname); |
|
78 | + $accountModel->setExtra($user_id, 'github_homepage', ($github_user->user)['html_url']); |
|
79 | + $accountModel->setExtra($user_id, 'github_token', $github_user->token, 101); |
|
80 | + return view('oauth.index', [ |
|
81 | 81 | 'page_title'=>"OAuth", |
82 | 82 | 'site_title'=>config("app.name"), |
83 | 83 | 'navigation'=>"OAuth", |
84 | 84 | 'platform' => 'Github', |
85 | - 'display_html' => 'You have successfully tied up the github account : <span class="text-info">'.$accountModel->getExtra(Auth::user()->id ,'github_email').'</span><br /> |
|
85 | + 'display_html' => 'You have successfully tied up the github account : <span class="text-info">'.$accountModel->getExtra(Auth::user()->id, 'github_email').'</span><br /> |
|
86 | 86 | You can log in to '.config("app.name").' later using this account', |
87 | 87 | 'buttons' => [ |
88 | 88 | [ |
@@ -91,18 +91,18 @@ discard block |
||
91 | 91 | ], |
92 | 92 | ] |
93 | 93 | ]); |
94 | - }else{ |
|
95 | - $ret = $accountModel->findExtra('github_id',$github_user->id); |
|
96 | - if(!empty($ret)){ |
|
94 | + } else { |
|
95 | + $ret=$accountModel->findExtra('github_id', $github_user->id); |
|
96 | + if (!empty($ret)) { |
|
97 | 97 | Auth::loginUsingId($ret['uid']); |
98 | - $user_id = Auth::user()->id; |
|
99 | - $accountModel->setExtra($user_id,'github_email',$github_user->email); |
|
100 | - $accountModel->setExtra($user_id,'github_nickname',$github_user->nickname); |
|
101 | - $accountModel->setExtra($user_id,'github_homepage',($github_user->user)['html_url']); |
|
102 | - $accountModel->setExtra($user_id,'github_token',$github_user->token,101); |
|
98 | + $user_id=Auth::user()->id; |
|
99 | + $accountModel->setExtra($user_id, 'github_email', $github_user->email); |
|
100 | + $accountModel->setExtra($user_id, 'github_nickname', $github_user->nickname); |
|
101 | + $accountModel->setExtra($user_id, 'github_homepage', ($github_user->user)['html_url']); |
|
102 | + $accountModel->setExtra($user_id, 'github_token', $github_user->token, 101); |
|
103 | 103 | return redirect('/'); |
104 | - }else{ |
|
105 | - return view('oauth.index',[ |
|
104 | + } else { |
|
105 | + return view('oauth.index', [ |
|
106 | 106 | 'page_title'=>"OAuth", |
107 | 107 | 'site_title'=>config("app.name"), |
108 | 108 | 'navigation'=>"OAuth", |
@@ -125,19 +125,19 @@ discard block |
||
125 | 125 | |
126 | 126 | public function unbind() |
127 | 127 | { |
128 | - if(!Auth::check()){ |
|
128 | + if (!Auth::check()) { |
|
129 | 129 | return redirect('/'); |
130 | 130 | } |
131 | - $accountModel = new AccountModel(); |
|
132 | - if($accountModel->getExtra(Auth::user()->id ,'github_id')){ |
|
133 | - return view('oauth.index',[ |
|
131 | + $accountModel=new AccountModel(); |
|
132 | + if ($accountModel->getExtra(Auth::user()->id, 'github_id')) { |
|
133 | + return view('oauth.index', [ |
|
134 | 134 | 'page_title'=>"OAuth", |
135 | 135 | 'site_title'=>config("app.name"), |
136 | 136 | 'navigation'=>"OAuth", |
137 | 137 | 'platform' => 'Github', |
138 | 138 | 'display_html' => 'You are trying to unbind the following two : <br /> |
139 | 139 | Your '.config("app.name").' account : <span class="text-info">'.Auth::user()->email.'</span><br /> |
140 | - This Github account : <span class="text-info">'.$accountModel->getExtra(Auth::user()->id ,'github_email').'</span><br /> |
|
140 | + This Github account : <span class="text-info">'.$accountModel->getExtra(Auth::user()->id, 'github_email').'</span><br /> |
|
141 | 141 | Make your decision carefully, although you can later establish the binding again', |
142 | 142 | 'buttons' => [ |
143 | 143 | [ |
@@ -151,8 +151,8 @@ discard block |
||
151 | 151 | ], |
152 | 152 | ] |
153 | 153 | ]); |
154 | - }else{ |
|
155 | - return view('oauth.index',[ |
|
154 | + } else { |
|
155 | + return view('oauth.index', [ |
|
156 | 156 | 'page_title'=>"OAuth", |
157 | 157 | 'site_title'=>config("app.name"), |
158 | 158 | 'navigation'=>"OAuth", |
@@ -170,18 +170,18 @@ discard block |
||
170 | 170 | |
171 | 171 | public function confirmUnbind() |
172 | 172 | { |
173 | - if(!Auth::check()){ |
|
173 | + if (!Auth::check()) { |
|
174 | 174 | return redirect('/'); |
175 | 175 | } |
176 | - $accountModel = new AccountModel(); |
|
177 | - $user_id = Auth::user()->id; |
|
178 | - if($accountModel->getExtra($user_id ,'github_id')){ |
|
179 | - $accountModel->setExtra($user_id,'github_id',null); |
|
180 | - $accountModel->setExtra($user_id,'github_email',null); |
|
181 | - $accountModel->setExtra($user_id,'github_nickname',null); |
|
182 | - $accountModel->setExtra($user_id,'github_homepage',null); |
|
183 | - $accountModel->setExtra($user_id,'github_token',null); |
|
184 | - return view('oauth.index',[ |
|
176 | + $accountModel=new AccountModel(); |
|
177 | + $user_id=Auth::user()->id; |
|
178 | + if ($accountModel->getExtra($user_id, 'github_id')) { |
|
179 | + $accountModel->setExtra($user_id, 'github_id', null); |
|
180 | + $accountModel->setExtra($user_id, 'github_email', null); |
|
181 | + $accountModel->setExtra($user_id, 'github_nickname', null); |
|
182 | + $accountModel->setExtra($user_id, 'github_homepage', null); |
|
183 | + $accountModel->setExtra($user_id, 'github_token', null); |
|
184 | + return view('oauth.index', [ |
|
185 | 185 | 'page_title'=>"OAuth", |
186 | 186 | 'site_title'=>config("app.name"), |
187 | 187 | 'navigation'=>"OAuth", |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | ], |
195 | 195 | ] |
196 | 196 | ]); |
197 | - }else{ |
|
198 | - return view('oauth.index',[ |
|
197 | + } else { |
|
198 | + return view('oauth.index', [ |
|
199 | 199 | 'page_title'=>"OAuth", |
200 | 200 | 'site_title'=>config("app.name"), |
201 | 201 | 'navigation'=>"OAuth", |