Skip to content

Commit b5f1faf

Browse files
author
Evan Priestley
committed
Merge pull request phacility#31 from CodeBlock/42fba245
D602
2 parents ece9d79 + 42fba24 commit b5f1faf

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/applications/auth/controller/login/PhabricatorLoginController.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,17 @@ public function processRequest() {
3131
}
3232

3333
$next_uri = $this->getRequest()->getPath();
34-
if ($next_uri == '/login/') {
35-
$next_uri = null;
34+
$request->setCookie('next_uri', $next_uri);
35+
if ($next_uri == '/login/' && !$request->isFormPost()) {
36+
// The user went straight to /login/, so presumably they want to go
37+
// to the dashboard upon logging in. Because, you know, that's logical.
38+
// And people are logical. Sometimes... Fine, no they're not.
39+
// We check for POST here because getPath() would get reset to /login/.
40+
$request->setCookie('next_uri', '/');
3641
}
3742

43+
// Always use $request->getCookie('next_uri', '/') after the above.
44+
3845
$password_auth = PhabricatorEnv::getEnvConfig('auth.password-auth-enabled');
3946

4047
$forms = array();
@@ -66,7 +73,7 @@ public function processRequest() {
6673
$request->setCookie('phsid', $session_key);
6774

6875
return id(new AphrontRedirectResponse())
69-
->setURI('/');
76+
->setURI($request->getCookie('next_uri', '/'));
7077
} else {
7178
$log = PhabricatorUserLog::newLog(
7279
null,
@@ -93,7 +100,6 @@ public function processRequest() {
93100
$form
94101
->setUser($request->getUser())
95102
->setAction('/login/')
96-
->addHiddenInput('next', $next_uri)
97103
->appendChild(
98104
id(new AphrontFormTextControl())
99105
->setLabel('Username/Email')
@@ -115,8 +121,6 @@ public function processRequest() {
115121
$forms['Phabricator Login'] = $form;
116122
}
117123

118-
$oauth_state = $next_uri;
119-
120124
$providers = array(
121125
PhabricatorOAuthProvider::PROVIDER_FACEBOOK,
122126
PhabricatorOAuthProvider::PROVIDER_GITHUB,
@@ -160,7 +164,6 @@ public function processRequest() {
160164
->addHiddenInput('client_id', $client_id)
161165
->addHiddenInput('redirect_uri', $redirect_uri)
162166
->addHiddenInput('scope', $minimum_scope)
163-
->addHiddenInput('state', $oauth_state)
164167
->setUser($request->getUser())
165168
->setMethod('GET')
166169
->appendChild(

src/applications/auth/controller/oauth/PhabricatorOAuthLoginController.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,7 @@ public function processRequest() {
135135
->setURI('/settings/page/'.$provider_key.'/');
136136
}
137137

138-
$next_uri = '/';
139-
if ($this->oauthState) {
140-
// Make sure a blind redirect to evil.com is impossible.
141-
$uri = new PhutilURI($this->oauthState);
142-
$next_uri = $uri->getPath();
143-
}
138+
$next_uri = $request->getCookie('next_uri', '/');
144139

145140
// Login with known auth.
146141

@@ -158,6 +153,7 @@ public function processRequest() {
158153

159154
$request->setCookie('phusr', $known_user->getUsername());
160155
$request->setCookie('phsid', $session_key);
156+
$request->clearCookie('next_uri');
161157
return id(new AphrontRedirectResponse())
162158
->setURI($next_uri);
163159
}

0 commit comments

Comments
 (0)