@@ -16,73 +16,73 @@ |
||
16 | 16 | |
17 | 17 | class PagePreferences extends InternalPageBase |
18 | 18 | { |
19 | - /** |
|
20 | - * Main function for this page, when no specific actions are called. |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - protected function main() |
|
24 | - { |
|
25 | - $this->setHtmlTitle('Preferences'); |
|
19 | + /** |
|
20 | + * Main function for this page, when no specific actions are called. |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + protected function main() |
|
24 | + { |
|
25 | + $this->setHtmlTitle('Preferences'); |
|
26 | 26 | |
27 | - $enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth(); |
|
28 | - $database = $this->getDatabase(); |
|
29 | - $user = User::getCurrent($database); |
|
27 | + $enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth(); |
|
28 | + $database = $this->getDatabase(); |
|
29 | + $user = User::getCurrent($database); |
|
30 | 30 | |
31 | - // Dual mode |
|
32 | - if (WebRequest::wasPosted()) { |
|
33 | - $this->validateCSRFToken(); |
|
34 | - $user->setWelcomeSig(WebRequest::postString('sig')); |
|
35 | - $user->setEmailSig(WebRequest::postString('emailsig')); |
|
36 | - $user->setAbortPref(WebRequest::getBoolean('sig') ? 1 : 0); |
|
37 | - $this->setCreationMode($user); |
|
31 | + // Dual mode |
|
32 | + if (WebRequest::wasPosted()) { |
|
33 | + $this->validateCSRFToken(); |
|
34 | + $user->setWelcomeSig(WebRequest::postString('sig')); |
|
35 | + $user->setEmailSig(WebRequest::postString('emailsig')); |
|
36 | + $user->setAbortPref(WebRequest::getBoolean('sig') ? 1 : 0); |
|
37 | + $this->setCreationMode($user); |
|
38 | 38 | |
39 | - $email = WebRequest::postEmail('email'); |
|
40 | - if ($email !== null) { |
|
41 | - $user->setEmail($email); |
|
42 | - } |
|
39 | + $email = WebRequest::postEmail('email'); |
|
40 | + if ($email !== null) { |
|
41 | + $user->setEmail($email); |
|
42 | + } |
|
43 | 43 | |
44 | - $user->save(); |
|
45 | - SessionAlert::success("Preferences updated!"); |
|
44 | + $user->save(); |
|
45 | + SessionAlert::success("Preferences updated!"); |
|
46 | 46 | |
47 | - $this->redirect(''); |
|
48 | - } |
|
49 | - else { |
|
50 | - $this->assignCSRFToken(); |
|
51 | - $this->setTemplate('preferences/prefs.tpl'); |
|
52 | - $this->assign("enforceOAuth", $enforceOAuth); |
|
47 | + $this->redirect(''); |
|
48 | + } |
|
49 | + else { |
|
50 | + $this->assignCSRFToken(); |
|
51 | + $this->setTemplate('preferences/prefs.tpl'); |
|
52 | + $this->assign("enforceOAuth", $enforceOAuth); |
|
53 | 53 | |
54 | - $this->assign('canManualCreate', |
|
55 | - $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation')); |
|
56 | - $this->assign('canOauthCreate', |
|
57 | - $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation')); |
|
58 | - $this->assign('canBotCreate', |
|
59 | - $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation')); |
|
54 | + $this->assign('canManualCreate', |
|
55 | + $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation')); |
|
56 | + $this->assign('canOauthCreate', |
|
57 | + $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation')); |
|
58 | + $this->assign('canBotCreate', |
|
59 | + $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation')); |
|
60 | 60 | |
61 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
|
62 | - $this->getSiteConfiguration()); |
|
63 | - $this->assign('oauth', $oauth); |
|
61 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
|
62 | + $this->getSiteConfiguration()); |
|
63 | + $this->assign('oauth', $oauth); |
|
64 | 64 | |
65 | - $identity = null; |
|
66 | - if ($oauth->isFullyLinked()) { |
|
67 | - $identity = $oauth->getIdentity(); |
|
68 | - } |
|
65 | + $identity = null; |
|
66 | + if ($oauth->isFullyLinked()) { |
|
67 | + $identity = $oauth->getIdentity(); |
|
68 | + } |
|
69 | 69 | |
70 | - $this->assign('identity', $identity); |
|
71 | - $this->assign('graceTime', $this->getSiteConfiguration()->getOauthIdentityGraceTime()); |
|
72 | - } |
|
73 | - } |
|
70 | + $this->assign('identity', $identity); |
|
71 | + $this->assign('graceTime', $this->getSiteConfiguration()->getOauthIdentityGraceTime()); |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @param User $user |
|
77 | - */ |
|
78 | - protected function setCreationMode(User $user) |
|
79 | - { |
|
80 | - // if the user is selecting a creation mode that they are not allowed, do nothing. |
|
81 | - // this has the side effect of allowing them to keep a selected mode that either has been changed for them, |
|
82 | - // or that they have kept from when they previously had certain access. |
|
83 | - $creationMode = WebRequest::postInt('creationmode'); |
|
84 | - if($this->barrierTest($creationMode, $user, 'RequestCreation')){ |
|
85 | - $user->setCreationMode($creationMode); |
|
86 | - } |
|
87 | - } |
|
75 | + /** |
|
76 | + * @param User $user |
|
77 | + */ |
|
78 | + protected function setCreationMode(User $user) |
|
79 | + { |
|
80 | + // if the user is selecting a creation mode that they are not allowed, do nothing. |
|
81 | + // this has the side effect of allowing them to keep a selected mode that either has been changed for them, |
|
82 | + // or that they have kept from when they previously had certain access. |
|
83 | + $creationMode = WebRequest::postInt('creationmode'); |
|
84 | + if($this->barrierTest($creationMode, $user, 'RequestCreation')){ |
|
85 | + $user->setCreationMode($creationMode); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | } |
@@ -81,7 +81,7 @@ |
||
81 | 81 | // this has the side effect of allowing them to keep a selected mode that either has been changed for them, |
82 | 82 | // or that they have kept from when they previously had certain access. |
83 | 83 | $creationMode = WebRequest::postInt('creationmode'); |
84 | - if($this->barrierTest($creationMode, $user, 'RequestCreation')){ |
|
84 | + if ($this->barrierTest($creationMode, $user, 'RequestCreation')) { |
|
85 | 85 | $user->setCreationMode($creationMode); |
86 | 86 | } |
87 | 87 | } |
@@ -81,7 +81,7 @@ |
||
81 | 81 | // this has the side effect of allowing them to keep a selected mode that either has been changed for them, |
82 | 82 | // or that they have kept from when they previously had certain access. |
83 | 83 | $creationMode = WebRequest::postInt('creationmode'); |
84 | - if($this->barrierTest($creationMode, $user, 'RequestCreation')){ |
|
84 | + if($this->barrierTest($creationMode, $user, 'RequestCreation')) { |
|
85 | 85 | $user->setCreationMode($creationMode); |
86 | 86 | } |
87 | 87 | } |
@@ -17,90 +17,90 @@ |
||
17 | 17 | |
18 | 18 | class PageOAuthCallback extends InternalPageBase |
19 | 19 | { |
20 | - /** |
|
21 | - * @return bool |
|
22 | - */ |
|
23 | - protected function isProtectedPage() |
|
24 | - { |
|
25 | - // This page is critical to ensuring OAuth functionality is operational. |
|
26 | - return false; |
|
27 | - } |
|
20 | + /** |
|
21 | + * @return bool |
|
22 | + */ |
|
23 | + protected function isProtectedPage() |
|
24 | + { |
|
25 | + // This page is critical to ensuring OAuth functionality is operational. |
|
26 | + return false; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Main function for this page, when no specific actions are called. |
|
31 | - * @return void |
|
32 | - */ |
|
33 | - protected function main() |
|
34 | - { |
|
35 | - // This should never get hit except by URL manipulation. |
|
36 | - $this->redirect(''); |
|
37 | - } |
|
29 | + /** |
|
30 | + * Main function for this page, when no specific actions are called. |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + protected function main() |
|
34 | + { |
|
35 | + // This should never get hit except by URL manipulation. |
|
36 | + $this->redirect(''); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Registered endpoint for the account creation callback. |
|
41 | - * |
|
42 | - * If this ever gets hit, something is wrong somewhere. |
|
43 | - */ |
|
44 | - protected function create() |
|
45 | - { |
|
46 | - throw new Exception('OAuth account creation endpoint triggered.'); |
|
47 | - } |
|
39 | + /** |
|
40 | + * Registered endpoint for the account creation callback. |
|
41 | + * |
|
42 | + * If this ever gets hit, something is wrong somewhere. |
|
43 | + */ |
|
44 | + protected function create() |
|
45 | + { |
|
46 | + throw new Exception('OAuth account creation endpoint triggered.'); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Callback entry point |
|
51 | - */ |
|
52 | - protected function authorise() |
|
53 | - { |
|
54 | - $oauthToken = WebRequest::getString('oauth_token'); |
|
55 | - $oauthVerifier = WebRequest::getString('oauth_verifier'); |
|
49 | + /** |
|
50 | + * Callback entry point |
|
51 | + */ |
|
52 | + protected function authorise() |
|
53 | + { |
|
54 | + $oauthToken = WebRequest::getString('oauth_token'); |
|
55 | + $oauthVerifier = WebRequest::getString('oauth_verifier'); |
|
56 | 56 | |
57 | - $this->doCallbackValidation($oauthToken, $oauthVerifier); |
|
57 | + $this->doCallbackValidation($oauthToken, $oauthVerifier); |
|
58 | 58 | |
59 | - $database = $this->getDatabase(); |
|
59 | + $database = $this->getDatabase(); |
|
60 | 60 | |
61 | - $user = OAuthUserHelper::findUserByRequestToken($oauthToken, $database); |
|
62 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
61 | + $user = OAuthUserHelper::findUserByRequestToken($oauthToken, $database); |
|
62 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
63 | 63 | |
64 | - try { |
|
65 | - $oauth->completeHandshake($oauthVerifier); |
|
66 | - } |
|
67 | - catch (CurlException $ex) { |
|
68 | - throw new ApplicationLogicException($ex->getMessage(), 0, $ex); |
|
69 | - } |
|
64 | + try { |
|
65 | + $oauth->completeHandshake($oauthVerifier); |
|
66 | + } |
|
67 | + catch (CurlException $ex) { |
|
68 | + throw new ApplicationLogicException($ex->getMessage(), 0, $ex); |
|
69 | + } |
|
70 | 70 | |
71 | - // OK, we're the same session that just did a partial login that was redirected to OAuth. Let's upgrade the |
|
72 | - // login to a full login |
|
73 | - if (WebRequest::getPartialLogin() === $user->getId()) { |
|
74 | - WebRequest::setLoggedInUser($user); |
|
75 | - } |
|
71 | + // OK, we're the same session that just did a partial login that was redirected to OAuth. Let's upgrade the |
|
72 | + // login to a full login |
|
73 | + if (WebRequest::getPartialLogin() === $user->getId()) { |
|
74 | + WebRequest::setLoggedInUser($user); |
|
75 | + } |
|
76 | 76 | |
77 | - // My thinking is there are three cases here: |
|
78 | - // a) new user => redirect to prefs - it's the only thing they can access other than stats |
|
79 | - // b) existing user hit the connect button in prefs => redirect to prefs since it's where they were |
|
80 | - // c) existing user logging in => redirect to wherever they came from |
|
81 | - $redirectDestination = WebRequest::clearPostLoginRedirect(); |
|
82 | - if ($redirectDestination !== null && !$user->isNewUser()) { |
|
83 | - $this->redirectUrl($redirectDestination); |
|
84 | - } |
|
85 | - else { |
|
86 | - $this->redirect('preferences', null, null, 'internal.php'); |
|
87 | - } |
|
88 | - } |
|
77 | + // My thinking is there are three cases here: |
|
78 | + // a) new user => redirect to prefs - it's the only thing they can access other than stats |
|
79 | + // b) existing user hit the connect button in prefs => redirect to prefs since it's where they were |
|
80 | + // c) existing user logging in => redirect to wherever they came from |
|
81 | + $redirectDestination = WebRequest::clearPostLoginRedirect(); |
|
82 | + if ($redirectDestination !== null && !$user->isNewUser()) { |
|
83 | + $this->redirectUrl($redirectDestination); |
|
84 | + } |
|
85 | + else { |
|
86 | + $this->redirect('preferences', null, null, 'internal.php'); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @param string $oauthToken |
|
92 | - * @param string $oauthVerifier |
|
93 | - * |
|
94 | - * @throws ApplicationLogicException |
|
95 | - */ |
|
96 | - private function doCallbackValidation($oauthToken, $oauthVerifier) |
|
97 | - { |
|
98 | - if ($oauthToken === null) { |
|
99 | - throw new ApplicationLogicException('No token provided'); |
|
100 | - } |
|
90 | + /** |
|
91 | + * @param string $oauthToken |
|
92 | + * @param string $oauthVerifier |
|
93 | + * |
|
94 | + * @throws ApplicationLogicException |
|
95 | + */ |
|
96 | + private function doCallbackValidation($oauthToken, $oauthVerifier) |
|
97 | + { |
|
98 | + if ($oauthToken === null) { |
|
99 | + throw new ApplicationLogicException('No token provided'); |
|
100 | + } |
|
101 | 101 | |
102 | - if ($oauthVerifier === null) { |
|
103 | - throw new ApplicationLogicException('No oauth verifier provided.'); |
|
104 | - } |
|
105 | - } |
|
102 | + if ($oauthVerifier === null) { |
|
103 | + throw new ApplicationLogicException('No oauth verifier provided.'); |
|
104 | + } |
|
105 | + } |
|
106 | 106 | } |
107 | 107 | \ No newline at end of file |
@@ -21,77 +21,77 @@ |
||
21 | 21 | |
22 | 22 | class PageOAuth extends InternalPageBase |
23 | 23 | { |
24 | - /** |
|
25 | - * Attach entry point |
|
26 | - * |
|
27 | - * must be posted, or will redirect to preferences |
|
28 | - */ |
|
29 | - protected function attach() |
|
30 | - { |
|
31 | - if (!WebRequest::wasPosted()) { |
|
32 | - $this->redirect('preferences'); |
|
33 | - |
|
34 | - return; |
|
35 | - } |
|
36 | - |
|
37 | - $database = $this->getDatabase(); |
|
38 | - |
|
39 | - $this->validateCSRFToken(); |
|
40 | - |
|
41 | - $oauthProtocolHelper = $this->getOAuthProtocolHelper(); |
|
42 | - $user = User::getCurrent($database); |
|
43 | - $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration()); |
|
44 | - |
|
45 | - try { |
|
46 | - $authoriseUrl = $oauth->getRequestToken(); |
|
47 | - $this->redirectUrl($authoriseUrl); |
|
48 | - } |
|
49 | - catch (CurlException $ex) { |
|
50 | - throw new ApplicationLogicException($ex->getMessage(), 0, $ex); |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Detach account entry point |
|
56 | - */ |
|
57 | - protected function detach() |
|
58 | - { |
|
59 | - if ($this->getSiteConfiguration()->getEnforceOAuth()) { |
|
60 | - throw new AccessDeniedException($this->getSecurityManager()); |
|
61 | - } |
|
62 | - |
|
63 | - $database = $this->getDatabase(); |
|
64 | - $user = User::getCurrent($database); |
|
65 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
66 | - |
|
67 | - try { |
|
68 | - $oauth->refreshIdentity(); |
|
69 | - } |
|
70 | - catch (CurlException $ex) { |
|
71 | - // do nothing. The user's already revoked this access anyway. |
|
72 | - } |
|
73 | - catch (OAuthException $ex) { |
|
74 | - // do nothing. The user's already revoked this access anyway. |
|
75 | - } |
|
76 | - |
|
77 | - $oauth->detach(); |
|
78 | - |
|
79 | - // TODO: figure out why we need to force logout after a detach. |
|
80 | - $user->setForcelogout(true); |
|
81 | - $user->save(); |
|
82 | - |
|
83 | - // force the user to log out |
|
84 | - Session::destroy(); |
|
85 | - |
|
86 | - $this->redirect('login'); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Main function for this page, when no specific actions are called. |
|
91 | - * @return void |
|
92 | - */ |
|
93 | - protected function main() |
|
94 | - { |
|
95 | - $this->redirect('preferences'); |
|
96 | - } |
|
24 | + /** |
|
25 | + * Attach entry point |
|
26 | + * |
|
27 | + * must be posted, or will redirect to preferences |
|
28 | + */ |
|
29 | + protected function attach() |
|
30 | + { |
|
31 | + if (!WebRequest::wasPosted()) { |
|
32 | + $this->redirect('preferences'); |
|
33 | + |
|
34 | + return; |
|
35 | + } |
|
36 | + |
|
37 | + $database = $this->getDatabase(); |
|
38 | + |
|
39 | + $this->validateCSRFToken(); |
|
40 | + |
|
41 | + $oauthProtocolHelper = $this->getOAuthProtocolHelper(); |
|
42 | + $user = User::getCurrent($database); |
|
43 | + $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration()); |
|
44 | + |
|
45 | + try { |
|
46 | + $authoriseUrl = $oauth->getRequestToken(); |
|
47 | + $this->redirectUrl($authoriseUrl); |
|
48 | + } |
|
49 | + catch (CurlException $ex) { |
|
50 | + throw new ApplicationLogicException($ex->getMessage(), 0, $ex); |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Detach account entry point |
|
56 | + */ |
|
57 | + protected function detach() |
|
58 | + { |
|
59 | + if ($this->getSiteConfiguration()->getEnforceOAuth()) { |
|
60 | + throw new AccessDeniedException($this->getSecurityManager()); |
|
61 | + } |
|
62 | + |
|
63 | + $database = $this->getDatabase(); |
|
64 | + $user = User::getCurrent($database); |
|
65 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
66 | + |
|
67 | + try { |
|
68 | + $oauth->refreshIdentity(); |
|
69 | + } |
|
70 | + catch (CurlException $ex) { |
|
71 | + // do nothing. The user's already revoked this access anyway. |
|
72 | + } |
|
73 | + catch (OAuthException $ex) { |
|
74 | + // do nothing. The user's already revoked this access anyway. |
|
75 | + } |
|
76 | + |
|
77 | + $oauth->detach(); |
|
78 | + |
|
79 | + // TODO: figure out why we need to force logout after a detach. |
|
80 | + $user->setForcelogout(true); |
|
81 | + $user->save(); |
|
82 | + |
|
83 | + // force the user to log out |
|
84 | + Session::destroy(); |
|
85 | + |
|
86 | + $this->redirect('login'); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Main function for this page, when no specific actions are called. |
|
91 | + * @return void |
|
92 | + */ |
|
93 | + protected function main() |
|
94 | + { |
|
95 | + $this->redirect('preferences'); |
|
96 | + } |
|
97 | 97 | } |
@@ -17,70 +17,70 @@ |
||
17 | 17 | |
18 | 18 | class PageChangePassword extends InternalPageBase |
19 | 19 | { |
20 | - /** |
|
21 | - * Main function for this page, when no specific actions are called. |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - protected function main() |
|
25 | - { |
|
26 | - $this->setHtmlTitle('Change Password'); |
|
20 | + /** |
|
21 | + * Main function for this page, when no specific actions are called. |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + protected function main() |
|
25 | + { |
|
26 | + $this->setHtmlTitle('Change Password'); |
|
27 | 27 | |
28 | - if (WebRequest::wasPosted()) { |
|
29 | - $this->validateCSRFToken(); |
|
30 | - try { |
|
31 | - $oldPassword = WebRequest::postString('oldpassword'); |
|
32 | - $newPassword = WebRequest::postString('newpassword'); |
|
33 | - $newPasswordConfirmation = WebRequest::postString('newpasswordconfirm'); |
|
28 | + if (WebRequest::wasPosted()) { |
|
29 | + $this->validateCSRFToken(); |
|
30 | + try { |
|
31 | + $oldPassword = WebRequest::postString('oldpassword'); |
|
32 | + $newPassword = WebRequest::postString('newpassword'); |
|
33 | + $newPasswordConfirmation = WebRequest::postString('newpasswordconfirm'); |
|
34 | 34 | |
35 | - $user = User::getCurrent($this->getDatabase()); |
|
36 | - if (!$user instanceof User) { |
|
37 | - throw new ApplicationLogicException('User not found'); |
|
38 | - } |
|
35 | + $user = User::getCurrent($this->getDatabase()); |
|
36 | + if (!$user instanceof User) { |
|
37 | + throw new ApplicationLogicException('User not found'); |
|
38 | + } |
|
39 | 39 | |
40 | - $this->validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, $user); |
|
41 | - } |
|
42 | - catch (ApplicationLogicException $ex) { |
|
43 | - SessionAlert::error($ex->getMessage()); |
|
44 | - $this->redirect('changePassword'); |
|
40 | + $this->validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, $user); |
|
41 | + } |
|
42 | + catch (ApplicationLogicException $ex) { |
|
43 | + SessionAlert::error($ex->getMessage()); |
|
44 | + $this->redirect('changePassword'); |
|
45 | 45 | |
46 | - return; |
|
47 | - } |
|
46 | + return; |
|
47 | + } |
|
48 | 48 | |
49 | - $passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration()); |
|
50 | - $passwordProvider->setCredential($user, 1, $newPassword); |
|
49 | + $passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration()); |
|
50 | + $passwordProvider->setCredential($user, 1, $newPassword); |
|
51 | 51 | |
52 | - SessionAlert::success('Password changed successfully!'); |
|
52 | + SessionAlert::success('Password changed successfully!'); |
|
53 | 53 | |
54 | - $this->redirect('preferences'); |
|
55 | - } |
|
56 | - else { |
|
57 | - $this->assignCSRFToken(); |
|
58 | - $this->setTemplate('preferences/changePassword.tpl'); |
|
59 | - } |
|
60 | - } |
|
54 | + $this->redirect('preferences'); |
|
55 | + } |
|
56 | + else { |
|
57 | + $this->assignCSRFToken(); |
|
58 | + $this->setTemplate('preferences/changePassword.tpl'); |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @param string $oldPassword |
|
64 | - * @param string $newPassword |
|
65 | - * @param string $newPasswordConfirmation |
|
66 | - * @param User $user |
|
67 | - * |
|
68 | - * @throws ApplicationLogicException |
|
69 | - */ |
|
70 | - protected function validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, User $user) |
|
71 | - { |
|
72 | - if ($oldPassword === null || $newPassword === null || $newPasswordConfirmation === null) { |
|
73 | - throw new ApplicationLogicException('All three fields must be completed to change your password'); |
|
74 | - } |
|
62 | + /** |
|
63 | + * @param string $oldPassword |
|
64 | + * @param string $newPassword |
|
65 | + * @param string $newPasswordConfirmation |
|
66 | + * @param User $user |
|
67 | + * |
|
68 | + * @throws ApplicationLogicException |
|
69 | + */ |
|
70 | + protected function validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, User $user) |
|
71 | + { |
|
72 | + if ($oldPassword === null || $newPassword === null || $newPasswordConfirmation === null) { |
|
73 | + throw new ApplicationLogicException('All three fields must be completed to change your password'); |
|
74 | + } |
|
75 | 75 | |
76 | - if ($newPassword !== $newPasswordConfirmation) { |
|
77 | - throw new ApplicationLogicException('Your new passwords did not match!'); |
|
78 | - } |
|
76 | + if ($newPassword !== $newPasswordConfirmation) { |
|
77 | + throw new ApplicationLogicException('Your new passwords did not match!'); |
|
78 | + } |
|
79 | 79 | |
80 | - // TODO: adapt for MFA support |
|
81 | - $passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration()); |
|
82 | - if (!$passwordProvider->authenticate($user, $oldPassword)) { |
|
83 | - throw new ApplicationLogicException('The password you entered was incorrect.'); |
|
84 | - } |
|
85 | - } |
|
80 | + // TODO: adapt for MFA support |
|
81 | + $passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration()); |
|
82 | + if (!$passwordProvider->authenticate($user, $oldPassword)) { |
|
83 | + throw new ApplicationLogicException('The password you entered was incorrect.'); |
|
84 | + } |
|
85 | + } |
|
86 | 86 | } |
87 | 87 | \ No newline at end of file |
@@ -23,155 +23,155 @@ |
||
23 | 23 | */ |
24 | 24 | class PageLogin extends InternalPageBase |
25 | 25 | { |
26 | - /** |
|
27 | - * Main function for this page, when no specific actions are called. |
|
28 | - */ |
|
29 | - protected function main() |
|
30 | - { |
|
31 | - // Start by enforcing HTTPS |
|
32 | - if ($this->getSiteConfiguration()->getUseStrictTransportSecurity() !== false) { |
|
33 | - if (WebRequest::isHttps()) { |
|
34 | - // Client can clearly use HTTPS, so let's enforce it for all connections. |
|
35 | - if (!headers_sent()) { |
|
36 | - header("Strict-Transport-Security: max-age=15768000"); |
|
37 | - } |
|
38 | - } |
|
39 | - else { |
|
40 | - // This is the login form, not the request form. We need protection here. |
|
41 | - $this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri()); |
|
42 | - |
|
43 | - return; |
|
44 | - } |
|
45 | - } |
|
46 | - |
|
47 | - if (WebRequest::wasPosted()) { |
|
48 | - // POST. Do some authentication. |
|
49 | - $this->validateCSRFToken(); |
|
50 | - |
|
51 | - $user = null; |
|
52 | - try { |
|
53 | - $user = $this->getAuthenticatingUser(); |
|
54 | - } |
|
55 | - catch (ApplicationLogicException $ex) { |
|
56 | - SessionAlert::error($ex->getMessage()); |
|
57 | - $this->redirect('login'); |
|
58 | - |
|
59 | - return; |
|
60 | - } |
|
61 | - |
|
62 | - // Touch force logout |
|
63 | - $user->setForceLogout(false); |
|
64 | - $user->save(); |
|
65 | - |
|
66 | - $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), |
|
67 | - $this->getSiteConfiguration()); |
|
68 | - |
|
69 | - if ($oauth->isFullyLinked()) { |
|
70 | - try{ |
|
71 | - // Reload the user's identity ticket. |
|
72 | - $oauth->refreshIdentity(); |
|
73 | - |
|
74 | - // Check for blocks |
|
75 | - if($oauth->getIdentity()->getBlocked()) { |
|
76 | - // blocked! |
|
77 | - SessionAlert::error("You are currently blocked on-wiki. You will not be able to log in until you are unblocked."); |
|
78 | - $this->redirect('login'); |
|
79 | - |
|
80 | - return; |
|
81 | - } |
|
82 | - } |
|
83 | - catch(OAuthException $ex) { |
|
84 | - // Oops. Refreshing ticket failed. Force a re-auth. |
|
85 | - $authoriseUrl = $oauth->getRequestToken(); |
|
86 | - WebRequest::setPartialLogin($user); |
|
87 | - $this->redirectUrl($authoriseUrl); |
|
88 | - |
|
89 | - return; |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - if (($this->getSiteConfiguration()->getEnforceOAuth() && !$oauth->isFullyLinked()) |
|
94 | - || $oauth->isPartiallyLinked() |
|
95 | - ) { |
|
96 | - $authoriseUrl = $oauth->getRequestToken(); |
|
97 | - WebRequest::setPartialLogin($user); |
|
98 | - $this->redirectUrl($authoriseUrl); |
|
99 | - |
|
100 | - return; |
|
101 | - } |
|
102 | - |
|
103 | - WebRequest::setLoggedInUser($user); |
|
104 | - |
|
105 | - $this->goBackWhenceYouCame($user); |
|
106 | - } |
|
107 | - else { |
|
108 | - // GET. Show the form |
|
109 | - $this->assignCSRFToken(); |
|
110 | - $this->setTemplate("login.tpl"); |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @return User |
|
116 | - * @throws ApplicationLogicException |
|
117 | - */ |
|
118 | - private function getAuthenticatingUser() |
|
119 | - { |
|
120 | - $username = WebRequest::postString("username"); |
|
121 | - $password = WebRequest::postString("password"); |
|
122 | - |
|
123 | - if ($username === null || $password === null || $username === "" || $password === "") { |
|
124 | - throw new ApplicationLogicException("No username/password specified"); |
|
125 | - } |
|
126 | - |
|
127 | - /** @var User $user */ |
|
128 | - $user = User::getByUsername($username, $this->getDatabase()); |
|
129 | - |
|
130 | - if ($user == false) { |
|
131 | - throw new ApplicationLogicException("Authentication failed"); |
|
132 | - } |
|
133 | - |
|
134 | - $authMan = new AuthenticationManager($this->getDatabase(), $this->getSiteConfiguration(), |
|
135 | - $this->getHttpHelper()); |
|
136 | - $authResult = $authMan->authenticate($user, $password, 1); |
|
137 | - |
|
138 | - if ($authResult === AuthenticationManager::AUTH_FAIL) { |
|
139 | - throw new ApplicationLogicException("Authentication failed"); |
|
140 | - } |
|
141 | - |
|
142 | - if ($authResult === AuthenticationManager::AUTH_REQUIRE_NEXT_STAGE) { |
|
143 | - throw new ApplicationLogicException("Next stage of authentication required. This is not currently supported."); |
|
144 | - } |
|
145 | - |
|
146 | - return $user; |
|
147 | - } |
|
148 | - |
|
149 | - protected function isProtectedPage() |
|
150 | - { |
|
151 | - return false; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Redirect the user back to wherever they came from after a successful login |
|
156 | - * |
|
157 | - * @param User $user |
|
158 | - */ |
|
159 | - private function goBackWhenceYouCame(User $user) |
|
160 | - { |
|
161 | - // Redirect to wherever the user came from |
|
162 | - $redirectDestination = WebRequest::clearPostLoginRedirect(); |
|
163 | - if ($redirectDestination !== null) { |
|
164 | - $this->redirectUrl($redirectDestination); |
|
165 | - } |
|
166 | - else { |
|
167 | - if ($user->isNewUser()) { |
|
168 | - // home page isn't allowed, go to preferences instead |
|
169 | - $this->redirect('preferences'); |
|
170 | - } |
|
171 | - else { |
|
172 | - // go to the home page |
|
173 | - $this->redirect(''); |
|
174 | - } |
|
175 | - } |
|
176 | - } |
|
26 | + /** |
|
27 | + * Main function for this page, when no specific actions are called. |
|
28 | + */ |
|
29 | + protected function main() |
|
30 | + { |
|
31 | + // Start by enforcing HTTPS |
|
32 | + if ($this->getSiteConfiguration()->getUseStrictTransportSecurity() !== false) { |
|
33 | + if (WebRequest::isHttps()) { |
|
34 | + // Client can clearly use HTTPS, so let's enforce it for all connections. |
|
35 | + if (!headers_sent()) { |
|
36 | + header("Strict-Transport-Security: max-age=15768000"); |
|
37 | + } |
|
38 | + } |
|
39 | + else { |
|
40 | + // This is the login form, not the request form. We need protection here. |
|
41 | + $this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri()); |
|
42 | + |
|
43 | + return; |
|
44 | + } |
|
45 | + } |
|
46 | + |
|
47 | + if (WebRequest::wasPosted()) { |
|
48 | + // POST. Do some authentication. |
|
49 | + $this->validateCSRFToken(); |
|
50 | + |
|
51 | + $user = null; |
|
52 | + try { |
|
53 | + $user = $this->getAuthenticatingUser(); |
|
54 | + } |
|
55 | + catch (ApplicationLogicException $ex) { |
|
56 | + SessionAlert::error($ex->getMessage()); |
|
57 | + $this->redirect('login'); |
|
58 | + |
|
59 | + return; |
|
60 | + } |
|
61 | + |
|
62 | + // Touch force logout |
|
63 | + $user->setForceLogout(false); |
|
64 | + $user->save(); |
|
65 | + |
|
66 | + $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), |
|
67 | + $this->getSiteConfiguration()); |
|
68 | + |
|
69 | + if ($oauth->isFullyLinked()) { |
|
70 | + try{ |
|
71 | + // Reload the user's identity ticket. |
|
72 | + $oauth->refreshIdentity(); |
|
73 | + |
|
74 | + // Check for blocks |
|
75 | + if($oauth->getIdentity()->getBlocked()) { |
|
76 | + // blocked! |
|
77 | + SessionAlert::error("You are currently blocked on-wiki. You will not be able to log in until you are unblocked."); |
|
78 | + $this->redirect('login'); |
|
79 | + |
|
80 | + return; |
|
81 | + } |
|
82 | + } |
|
83 | + catch(OAuthException $ex) { |
|
84 | + // Oops. Refreshing ticket failed. Force a re-auth. |
|
85 | + $authoriseUrl = $oauth->getRequestToken(); |
|
86 | + WebRequest::setPartialLogin($user); |
|
87 | + $this->redirectUrl($authoriseUrl); |
|
88 | + |
|
89 | + return; |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + if (($this->getSiteConfiguration()->getEnforceOAuth() && !$oauth->isFullyLinked()) |
|
94 | + || $oauth->isPartiallyLinked() |
|
95 | + ) { |
|
96 | + $authoriseUrl = $oauth->getRequestToken(); |
|
97 | + WebRequest::setPartialLogin($user); |
|
98 | + $this->redirectUrl($authoriseUrl); |
|
99 | + |
|
100 | + return; |
|
101 | + } |
|
102 | + |
|
103 | + WebRequest::setLoggedInUser($user); |
|
104 | + |
|
105 | + $this->goBackWhenceYouCame($user); |
|
106 | + } |
|
107 | + else { |
|
108 | + // GET. Show the form |
|
109 | + $this->assignCSRFToken(); |
|
110 | + $this->setTemplate("login.tpl"); |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @return User |
|
116 | + * @throws ApplicationLogicException |
|
117 | + */ |
|
118 | + private function getAuthenticatingUser() |
|
119 | + { |
|
120 | + $username = WebRequest::postString("username"); |
|
121 | + $password = WebRequest::postString("password"); |
|
122 | + |
|
123 | + if ($username === null || $password === null || $username === "" || $password === "") { |
|
124 | + throw new ApplicationLogicException("No username/password specified"); |
|
125 | + } |
|
126 | + |
|
127 | + /** @var User $user */ |
|
128 | + $user = User::getByUsername($username, $this->getDatabase()); |
|
129 | + |
|
130 | + if ($user == false) { |
|
131 | + throw new ApplicationLogicException("Authentication failed"); |
|
132 | + } |
|
133 | + |
|
134 | + $authMan = new AuthenticationManager($this->getDatabase(), $this->getSiteConfiguration(), |
|
135 | + $this->getHttpHelper()); |
|
136 | + $authResult = $authMan->authenticate($user, $password, 1); |
|
137 | + |
|
138 | + if ($authResult === AuthenticationManager::AUTH_FAIL) { |
|
139 | + throw new ApplicationLogicException("Authentication failed"); |
|
140 | + } |
|
141 | + |
|
142 | + if ($authResult === AuthenticationManager::AUTH_REQUIRE_NEXT_STAGE) { |
|
143 | + throw new ApplicationLogicException("Next stage of authentication required. This is not currently supported."); |
|
144 | + } |
|
145 | + |
|
146 | + return $user; |
|
147 | + } |
|
148 | + |
|
149 | + protected function isProtectedPage() |
|
150 | + { |
|
151 | + return false; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Redirect the user back to wherever they came from after a successful login |
|
156 | + * |
|
157 | + * @param User $user |
|
158 | + */ |
|
159 | + private function goBackWhenceYouCame(User $user) |
|
160 | + { |
|
161 | + // Redirect to wherever the user came from |
|
162 | + $redirectDestination = WebRequest::clearPostLoginRedirect(); |
|
163 | + if ($redirectDestination !== null) { |
|
164 | + $this->redirectUrl($redirectDestination); |
|
165 | + } |
|
166 | + else { |
|
167 | + if ($user->isNewUser()) { |
|
168 | + // home page isn't allowed, go to preferences instead |
|
169 | + $this->redirect('preferences'); |
|
170 | + } |
|
171 | + else { |
|
172 | + // go to the home page |
|
173 | + $this->redirect(''); |
|
174 | + } |
|
175 | + } |
|
176 | + } |
|
177 | 177 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | } |
39 | 39 | else { |
40 | 40 | // This is the login form, not the request form. We need protection here. |
41 | - $this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri()); |
|
41 | + $this->redirectUrl('https://'.WebRequest::serverName().WebRequest::requestUri()); |
|
42 | 42 | |
43 | 43 | return; |
44 | 44 | } |
@@ -67,12 +67,12 @@ discard block |
||
67 | 67 | $this->getSiteConfiguration()); |
68 | 68 | |
69 | 69 | if ($oauth->isFullyLinked()) { |
70 | - try{ |
|
70 | + try { |
|
71 | 71 | // Reload the user's identity ticket. |
72 | 72 | $oauth->refreshIdentity(); |
73 | 73 | |
74 | 74 | // Check for blocks |
75 | - if($oauth->getIdentity()->getBlocked()) { |
|
75 | + if ($oauth->getIdentity()->getBlocked()) { |
|
76 | 76 | // blocked! |
77 | 77 | SessionAlert::error("You are currently blocked on-wiki. You will not be able to log in until you are unblocked."); |
78 | 78 | $this->redirect('login'); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | return; |
81 | 81 | } |
82 | 82 | } |
83 | - catch(OAuthException $ex) { |
|
83 | + catch (OAuthException $ex) { |
|
84 | 84 | // Oops. Refreshing ticket failed. Force a re-auth. |
85 | 85 | $authoriseUrl = $oauth->getRequestToken(); |
86 | 86 | WebRequest::setPartialLogin($user); |
@@ -67,7 +67,7 @@ |
||
67 | 67 | $this->getSiteConfiguration()); |
68 | 68 | |
69 | 69 | if ($oauth->isFullyLinked()) { |
70 | - try{ |
|
70 | + try { |
|
71 | 71 | // Reload the user's identity ticket. |
72 | 72 | $oauth->refreshIdentity(); |
73 | 73 |
@@ -18,149 +18,149 @@ |
||
18 | 18 | |
19 | 19 | class PageForgotPassword extends InternalPageBase |
20 | 20 | { |
21 | - /** |
|
22 | - * Main function for this page, when no specific actions are called. |
|
23 | - * |
|
24 | - * This is the forgotten password reset form |
|
25 | - * @category Security-Critical |
|
26 | - */ |
|
27 | - protected function main() |
|
28 | - { |
|
29 | - if (WebRequest::wasPosted()) { |
|
30 | - $this->validateCSRFToken(); |
|
31 | - $username = WebRequest::postString('username'); |
|
32 | - $email = WebRequest::postEmail('email'); |
|
33 | - $database = $this->getDatabase(); |
|
34 | - |
|
35 | - if ($username === null || trim($username) === "" || $email === null || trim($email) === "") { |
|
36 | - throw new ApplicationLogicException("Both username and email address must be specified!"); |
|
37 | - } |
|
38 | - |
|
39 | - $user = User::getByUsername($username, $database); |
|
40 | - $this->sendResetMail($user, $email); |
|
41 | - |
|
42 | - SessionAlert::success('<strong>Your password reset request has been completed.</strong> Please check your e-mail.'); |
|
43 | - |
|
44 | - $this->redirect('login'); |
|
45 | - } |
|
46 | - else { |
|
47 | - $this->assignCSRFToken(); |
|
48 | - $this->setTemplate('forgot-password/forgotpw.tpl'); |
|
49 | - } |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Sends a reset email if the user is authenticated |
|
54 | - * |
|
55 | - * @param User|boolean $user The user located from the database, or false. Doesn't really matter, since we do the |
|
56 | - * check anyway within this method and silently skip if we don't have a user. |
|
57 | - * @param string $email The provided email address |
|
58 | - */ |
|
59 | - private function sendResetMail($user, $email) |
|
60 | - { |
|
61 | - // If the user isn't found, or the email address is wrong, skip sending the details silently. |
|
62 | - if (!$user instanceof User) { |
|
63 | - return; |
|
64 | - } |
|
65 | - |
|
66 | - if (strtolower($user->getEmail()) === strtolower($email)) { |
|
67 | - $clientIp = $this->getXffTrustProvider() |
|
68 | - ->getTrustedClientIp(WebRequest::remoteAddress(), WebRequest::forwardedAddress()); |
|
69 | - |
|
70 | - $this->assign("user", $user); |
|
71 | - $this->assign("hash", $user->getForgottenPasswordHash()); |
|
72 | - $this->assign("remoteAddress", $clientIp); |
|
73 | - |
|
74 | - $emailContent = $this->fetchTemplate('forgot-password/reset-mail.tpl'); |
|
75 | - |
|
76 | - $this->getEmailHelper()->sendMail($user->getEmail(), "", $emailContent); |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Entry point for the reset action |
|
82 | - * |
|
83 | - * This is the reset password part of the form. |
|
84 | - * @category Security-Critical |
|
85 | - */ |
|
86 | - protected function reset() |
|
87 | - { |
|
88 | - $si = WebRequest::getString('si'); |
|
89 | - $id = WebRequest::getString('id'); |
|
90 | - |
|
91 | - if ($si === null || trim($si) === "" || $id === null || trim($id) === "") { |
|
92 | - throw new ApplicationLogicException("Link not valid, please ensure it has copied correctly"); |
|
93 | - } |
|
94 | - |
|
95 | - $database = $this->getDatabase(); |
|
96 | - $user = $this->getResettingUser($id, $database, $si); |
|
97 | - |
|
98 | - // Dual mode |
|
99 | - if (WebRequest::wasPosted()) { |
|
100 | - $this->validateCSRFToken(); |
|
101 | - try { |
|
102 | - $this->doReset($user); |
|
103 | - } |
|
104 | - catch (ApplicationLogicException $ex) { |
|
105 | - SessionAlert::error($ex->getMessage()); |
|
106 | - $this->redirect('forgotPassword', 'reset', array('si' => $si, 'id' => $id)); |
|
107 | - |
|
108 | - return; |
|
109 | - } |
|
110 | - } |
|
111 | - else { |
|
112 | - $this->assignCSRFToken(); |
|
113 | - $this->assign('user', $user); |
|
114 | - $this->setTemplate('forgot-password/forgotpwreset.tpl'); |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Gets the user resetting their password from the database, or throwing an exception if that is not possible. |
|
120 | - * |
|
121 | - * @param integer $id The ID of the user to retrieve |
|
122 | - * @param PdoDatabase $database The database object to use |
|
123 | - * @param string $si The reset hash provided |
|
124 | - * |
|
125 | - * @return User |
|
126 | - * @throws ApplicationLogicException |
|
127 | - */ |
|
128 | - private function getResettingUser($id, $database, $si) |
|
129 | - { |
|
130 | - $user = User::getById($id, $database); |
|
131 | - |
|
132 | - if ($user === false || $user->getForgottenPasswordHash() !== $si || $user->isCommunityUser()) { |
|
133 | - throw new ApplicationLogicException("User not found"); |
|
134 | - } |
|
135 | - |
|
136 | - return $user; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Performs the setting of the new password |
|
141 | - * |
|
142 | - * @param User $user The user to set the password for |
|
143 | - * |
|
144 | - * @throws ApplicationLogicException |
|
145 | - */ |
|
146 | - private function doReset(User $user) |
|
147 | - { |
|
148 | - $pw = WebRequest::postString('pw'); |
|
149 | - $pw2 = WebRequest::postString('pw2'); |
|
150 | - |
|
151 | - if ($pw !== $pw2) { |
|
152 | - throw new ApplicationLogicException('Passwords do not match!'); |
|
153 | - } |
|
154 | - |
|
155 | - $passwordCredentialProvider = new PasswordCredentialProvider($user->getDatabase(), $this->getSiteConfiguration()); |
|
156 | - $passwordCredentialProvider->setCredential($user, 1, $pw); |
|
157 | - |
|
158 | - SessionAlert::success('You may now log in!'); |
|
159 | - $this->redirect('login'); |
|
160 | - } |
|
161 | - |
|
162 | - protected function isProtectedPage() |
|
163 | - { |
|
164 | - return false; |
|
165 | - } |
|
21 | + /** |
|
22 | + * Main function for this page, when no specific actions are called. |
|
23 | + * |
|
24 | + * This is the forgotten password reset form |
|
25 | + * @category Security-Critical |
|
26 | + */ |
|
27 | + protected function main() |
|
28 | + { |
|
29 | + if (WebRequest::wasPosted()) { |
|
30 | + $this->validateCSRFToken(); |
|
31 | + $username = WebRequest::postString('username'); |
|
32 | + $email = WebRequest::postEmail('email'); |
|
33 | + $database = $this->getDatabase(); |
|
34 | + |
|
35 | + if ($username === null || trim($username) === "" || $email === null || trim($email) === "") { |
|
36 | + throw new ApplicationLogicException("Both username and email address must be specified!"); |
|
37 | + } |
|
38 | + |
|
39 | + $user = User::getByUsername($username, $database); |
|
40 | + $this->sendResetMail($user, $email); |
|
41 | + |
|
42 | + SessionAlert::success('<strong>Your password reset request has been completed.</strong> Please check your e-mail.'); |
|
43 | + |
|
44 | + $this->redirect('login'); |
|
45 | + } |
|
46 | + else { |
|
47 | + $this->assignCSRFToken(); |
|
48 | + $this->setTemplate('forgot-password/forgotpw.tpl'); |
|
49 | + } |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Sends a reset email if the user is authenticated |
|
54 | + * |
|
55 | + * @param User|boolean $user The user located from the database, or false. Doesn't really matter, since we do the |
|
56 | + * check anyway within this method and silently skip if we don't have a user. |
|
57 | + * @param string $email The provided email address |
|
58 | + */ |
|
59 | + private function sendResetMail($user, $email) |
|
60 | + { |
|
61 | + // If the user isn't found, or the email address is wrong, skip sending the details silently. |
|
62 | + if (!$user instanceof User) { |
|
63 | + return; |
|
64 | + } |
|
65 | + |
|
66 | + if (strtolower($user->getEmail()) === strtolower($email)) { |
|
67 | + $clientIp = $this->getXffTrustProvider() |
|
68 | + ->getTrustedClientIp(WebRequest::remoteAddress(), WebRequest::forwardedAddress()); |
|
69 | + |
|
70 | + $this->assign("user", $user); |
|
71 | + $this->assign("hash", $user->getForgottenPasswordHash()); |
|
72 | + $this->assign("remoteAddress", $clientIp); |
|
73 | + |
|
74 | + $emailContent = $this->fetchTemplate('forgot-password/reset-mail.tpl'); |
|
75 | + |
|
76 | + $this->getEmailHelper()->sendMail($user->getEmail(), "", $emailContent); |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Entry point for the reset action |
|
82 | + * |
|
83 | + * This is the reset password part of the form. |
|
84 | + * @category Security-Critical |
|
85 | + */ |
|
86 | + protected function reset() |
|
87 | + { |
|
88 | + $si = WebRequest::getString('si'); |
|
89 | + $id = WebRequest::getString('id'); |
|
90 | + |
|
91 | + if ($si === null || trim($si) === "" || $id === null || trim($id) === "") { |
|
92 | + throw new ApplicationLogicException("Link not valid, please ensure it has copied correctly"); |
|
93 | + } |
|
94 | + |
|
95 | + $database = $this->getDatabase(); |
|
96 | + $user = $this->getResettingUser($id, $database, $si); |
|
97 | + |
|
98 | + // Dual mode |
|
99 | + if (WebRequest::wasPosted()) { |
|
100 | + $this->validateCSRFToken(); |
|
101 | + try { |
|
102 | + $this->doReset($user); |
|
103 | + } |
|
104 | + catch (ApplicationLogicException $ex) { |
|
105 | + SessionAlert::error($ex->getMessage()); |
|
106 | + $this->redirect('forgotPassword', 'reset', array('si' => $si, 'id' => $id)); |
|
107 | + |
|
108 | + return; |
|
109 | + } |
|
110 | + } |
|
111 | + else { |
|
112 | + $this->assignCSRFToken(); |
|
113 | + $this->assign('user', $user); |
|
114 | + $this->setTemplate('forgot-password/forgotpwreset.tpl'); |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Gets the user resetting their password from the database, or throwing an exception if that is not possible. |
|
120 | + * |
|
121 | + * @param integer $id The ID of the user to retrieve |
|
122 | + * @param PdoDatabase $database The database object to use |
|
123 | + * @param string $si The reset hash provided |
|
124 | + * |
|
125 | + * @return User |
|
126 | + * @throws ApplicationLogicException |
|
127 | + */ |
|
128 | + private function getResettingUser($id, $database, $si) |
|
129 | + { |
|
130 | + $user = User::getById($id, $database); |
|
131 | + |
|
132 | + if ($user === false || $user->getForgottenPasswordHash() !== $si || $user->isCommunityUser()) { |
|
133 | + throw new ApplicationLogicException("User not found"); |
|
134 | + } |
|
135 | + |
|
136 | + return $user; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Performs the setting of the new password |
|
141 | + * |
|
142 | + * @param User $user The user to set the password for |
|
143 | + * |
|
144 | + * @throws ApplicationLogicException |
|
145 | + */ |
|
146 | + private function doReset(User $user) |
|
147 | + { |
|
148 | + $pw = WebRequest::postString('pw'); |
|
149 | + $pw2 = WebRequest::postString('pw2'); |
|
150 | + |
|
151 | + if ($pw !== $pw2) { |
|
152 | + throw new ApplicationLogicException('Passwords do not match!'); |
|
153 | + } |
|
154 | + |
|
155 | + $passwordCredentialProvider = new PasswordCredentialProvider($user->getDatabase(), $this->getSiteConfiguration()); |
|
156 | + $passwordCredentialProvider->setCredential($user, 1, $pw); |
|
157 | + |
|
158 | + SessionAlert::success('You may now log in!'); |
|
159 | + $this->redirect('login'); |
|
160 | + } |
|
161 | + |
|
162 | + protected function isProtectedPage() |
|
163 | + { |
|
164 | + return false; |
|
165 | + } |
|
166 | 166 | } |
@@ -200,24 +200,24 @@ discard block |
||
200 | 200 | |
201 | 201 | // request states |
202 | 202 | $availableRequestStates = array( |
203 | - 'Open' => array( |
|
204 | - 'defertolog' => 'users', // don't change or you'll break old logs |
|
205 | - 'deferto' => 'users', |
|
206 | - 'header' => 'Open requests', |
|
207 | - 'api' => "open", |
|
208 | - ), |
|
209 | - 'Flagged users' => array( |
|
210 | - 'defertolog' => 'flagged users', // don't change or you'll break old logs |
|
211 | - 'deferto' => 'flagged users', |
|
212 | - 'header' => 'Flagged user needed', |
|
213 | - 'api' => "admin", |
|
214 | - ), |
|
215 | - 'Checkuser' => array( |
|
216 | - 'defertolog' => 'checkusers', // don't change or you'll break old logs |
|
217 | - 'deferto' => 'checkusers', |
|
218 | - 'header' => 'Checkuser needed', |
|
219 | - 'api' => "checkuser", |
|
220 | - ), |
|
203 | + 'Open' => array( |
|
204 | + 'defertolog' => 'users', // don't change or you'll break old logs |
|
205 | + 'deferto' => 'users', |
|
206 | + 'header' => 'Open requests', |
|
207 | + 'api' => "open", |
|
208 | + ), |
|
209 | + 'Flagged users' => array( |
|
210 | + 'defertolog' => 'flagged users', // don't change or you'll break old logs |
|
211 | + 'deferto' => 'flagged users', |
|
212 | + 'header' => 'Flagged user needed', |
|
213 | + 'api' => "admin", |
|
214 | + ), |
|
215 | + 'Checkuser' => array( |
|
216 | + 'defertolog' => 'checkusers', // don't change or you'll break old logs |
|
217 | + 'deferto' => 'checkusers', |
|
218 | + 'header' => 'Checkuser needed', |
|
219 | + 'api' => "checkuser", |
|
220 | + ), |
|
221 | 221 | ); |
222 | 222 | |
223 | 223 | $defaultRequestStateKey = 'Open'; |
@@ -259,21 +259,21 @@ discard block |
||
259 | 259 | require_once('config.local.inc.php'); |
260 | 260 | |
261 | 261 | $cDatabaseConfig = array( |
262 | - "acc" => array( |
|
263 | - "dsrcname" => "mysql:host=" . $toolserver_host . ";dbname=" . $toolserver_database, |
|
264 | - "username" => $toolserver_username, |
|
265 | - "password" => $toolserver_password, |
|
266 | - ), |
|
267 | - "wikipedia" => array( |
|
268 | - "dsrcname" => "mysql:host=" . $antispoof_host . ";dbname=" . $antispoof_db, |
|
269 | - "username" => $toolserver_username, |
|
270 | - "password" => $toolserver_password, |
|
271 | - ), |
|
272 | - "notifications" => array( |
|
273 | - "dsrcname" => "mysql:host=" . $toolserver_notification_dbhost . ";dbname=" . $toolserver_notification_database, |
|
274 | - "username" => $notifications_username, |
|
275 | - "password" => $notifications_password, |
|
276 | - ), |
|
262 | + "acc" => array( |
|
263 | + "dsrcname" => "mysql:host=" . $toolserver_host . ";dbname=" . $toolserver_database, |
|
264 | + "username" => $toolserver_username, |
|
265 | + "password" => $toolserver_password, |
|
266 | + ), |
|
267 | + "wikipedia" => array( |
|
268 | + "dsrcname" => "mysql:host=" . $antispoof_host . ";dbname=" . $antispoof_db, |
|
269 | + "username" => $toolserver_username, |
|
270 | + "password" => $toolserver_password, |
|
271 | + ), |
|
272 | + "notifications" => array( |
|
273 | + "dsrcname" => "mysql:host=" . $toolserver_notification_dbhost . ";dbname=" . $toolserver_notification_database, |
|
274 | + "username" => $notifications_username, |
|
275 | + "password" => $notifications_password, |
|
276 | + ), |
|
277 | 277 | ); |
278 | 278 | |
279 | 279 | // //Keep the included files from being executed. |
@@ -285,18 +285,18 @@ discard block |
||
285 | 285 | ini_set('user_agent', $toolUserAgent); |
286 | 286 | |
287 | 287 | foreach (array( |
288 | - "mbstring", // unicode and stuff |
|
289 | - "pdo", |
|
290 | - "pdo_mysql", // new database module |
|
291 | - "session", |
|
292 | - "date", |
|
293 | - "pcre", // core stuff |
|
294 | - "curl", // mediawiki api access etc |
|
295 | - "openssl", // token generation |
|
288 | + "mbstring", // unicode and stuff |
|
289 | + "pdo", |
|
290 | + "pdo_mysql", // new database module |
|
291 | + "session", |
|
292 | + "date", |
|
293 | + "pcre", // core stuff |
|
294 | + "curl", // mediawiki api access etc |
|
295 | + "openssl", // token generation |
|
296 | 296 | ) as $x) { |
297 | - if (!extension_loaded($x)) { |
|
298 | - die("extension $x is required."); |
|
299 | - } |
|
297 | + if (!extension_loaded($x)) { |
|
298 | + die("extension $x is required."); |
|
299 | + } |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | // Set up the AutoLoader |
@@ -323,36 +323,36 @@ discard block |
||
323 | 323 | $siteConfiguration = new \Waca\SiteConfiguration(); |
324 | 324 | |
325 | 325 | $siteConfiguration->setBaseUrl($baseurl) |
326 | - ->setFilePath(__DIR__) |
|
327 | - ->setDebuggingTraceEnabled($enableErrorTrace) |
|
328 | - ->setForceIdentification($forceIdentification) |
|
329 | - ->setIdentificationCacheExpiry($identificationCacheExpiry) |
|
330 | - ->setMediawikiScriptPath($mediawikiScriptPath) |
|
331 | - ->setMediawikiWebServiceEndpoint($mediawikiWebServiceEndpoint) |
|
332 | - ->setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint) |
|
333 | - ->setEnforceOAuth($enforceOAuth) |
|
334 | - ->setEmailConfirmationEnabled($enableEmailConfirm == 1) |
|
335 | - ->setEmailConfirmationExpiryDays($emailConfirmationExpiryDays) |
|
336 | - ->setMiserModeLimit($requestLimitShowOnly) |
|
337 | - ->setRequestStates($availableRequestStates) |
|
338 | - ->setSquidList($squidIpList) |
|
339 | - ->setDefaultCreatedTemplateId($createdid) |
|
340 | - ->setDefaultRequestStateKey($defaultRequestStateKey) |
|
341 | - ->setUseStrictTransportSecurity($strictTransportSecurityExpiry) |
|
342 | - ->setUserAgent($toolUserAgent) |
|
343 | - ->setCurlDisableVerifyPeer($curlDisableSSLVerifyPeer) |
|
344 | - ->setUseOAuthSignup($useOauthSignup) |
|
345 | - ->setOAuthBaseUrl($oauthBaseUrl) |
|
346 | - ->setOAuthConsumerToken($oauthConsumerToken) |
|
347 | - ->setOAuthConsumerSecret($oauthSecretToken) |
|
348 | - ->setOauthMediaWikiCanonicalServer($oauthMediaWikiCanonicalServer) |
|
349 | - ->setDataClearInterval($dataclear_interval) |
|
350 | - ->setXffTrustedHostsFile($xff_trusted_hosts_file) |
|
351 | - ->setIrcNotificationsEnabled($ircBotNotificationsEnabled == 1) |
|
352 | - ->setIrcNotificationType($ircBotNotificationType) |
|
353 | - ->setIrcNotificationsInstance($whichami) |
|
354 | - ->setTitleBlacklistEnabled($enableTitleblacklist == 1) |
|
355 | - ->setTorExitPaths(array_merge(gethostbynamel('en.wikipedia.org'), gethostbynamel('accounts.wmflabs.org'))) |
|
356 | - ->setCreationBotUsername($creationBotUsername) |
|
357 | - ->setCreationBotPassword($creationBotPassword) |
|
358 | - ->setCurlCookieJar($curlCookieJar); |
|
326 | + ->setFilePath(__DIR__) |
|
327 | + ->setDebuggingTraceEnabled($enableErrorTrace) |
|
328 | + ->setForceIdentification($forceIdentification) |
|
329 | + ->setIdentificationCacheExpiry($identificationCacheExpiry) |
|
330 | + ->setMediawikiScriptPath($mediawikiScriptPath) |
|
331 | + ->setMediawikiWebServiceEndpoint($mediawikiWebServiceEndpoint) |
|
332 | + ->setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint) |
|
333 | + ->setEnforceOAuth($enforceOAuth) |
|
334 | + ->setEmailConfirmationEnabled($enableEmailConfirm == 1) |
|
335 | + ->setEmailConfirmationExpiryDays($emailConfirmationExpiryDays) |
|
336 | + ->setMiserModeLimit($requestLimitShowOnly) |
|
337 | + ->setRequestStates($availableRequestStates) |
|
338 | + ->setSquidList($squidIpList) |
|
339 | + ->setDefaultCreatedTemplateId($createdid) |
|
340 | + ->setDefaultRequestStateKey($defaultRequestStateKey) |
|
341 | + ->setUseStrictTransportSecurity($strictTransportSecurityExpiry) |
|
342 | + ->setUserAgent($toolUserAgent) |
|
343 | + ->setCurlDisableVerifyPeer($curlDisableSSLVerifyPeer) |
|
344 | + ->setUseOAuthSignup($useOauthSignup) |
|
345 | + ->setOAuthBaseUrl($oauthBaseUrl) |
|
346 | + ->setOAuthConsumerToken($oauthConsumerToken) |
|
347 | + ->setOAuthConsumerSecret($oauthSecretToken) |
|
348 | + ->setOauthMediaWikiCanonicalServer($oauthMediaWikiCanonicalServer) |
|
349 | + ->setDataClearInterval($dataclear_interval) |
|
350 | + ->setXffTrustedHostsFile($xff_trusted_hosts_file) |
|
351 | + ->setIrcNotificationsEnabled($ircBotNotificationsEnabled == 1) |
|
352 | + ->setIrcNotificationType($ircBotNotificationType) |
|
353 | + ->setIrcNotificationsInstance($whichami) |
|
354 | + ->setTitleBlacklistEnabled($enableTitleblacklist == 1) |
|
355 | + ->setTorExitPaths(array_merge(gethostbynamel('en.wikipedia.org'), gethostbynamel('accounts.wmflabs.org'))) |
|
356 | + ->setCreationBotUsername($creationBotUsername) |
|
357 | + ->setCreationBotPassword($creationBotPassword) |
|
358 | + ->setCurlCookieJar($curlCookieJar); |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | $BUbasefile = "backup"; // The basefile's name. |
132 | 132 | $BUdir = "/home/project/a/c/c/acc/backups"; // The directory where backups should be stored. |
133 | -$BUmonthdir = $BUdir . "/monthly"; // The directory where monthly backups should be stored. |
|
133 | +$BUmonthdir = $BUdir."/monthly"; // The directory where monthly backups should be stored. |
|
134 | 134 | $BUdumper = "/opt/ts/mysql/5.1/bin/mysqldump --defaults-file=~/.my.cnf p_acc_live"; // Add parameters here if they are needed. |
135 | 135 | $BUgzip = "/usr/bin/gzip"; // Add the gzip parameters here if needed. |
136 | 136 | $BUtar = "/bin/tar -cvf"; // Add the tar parameters here if needed. |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | $curlDisableSSLVerifyPeer = false; |
247 | 247 | |
248 | 248 | // Change this to be outside the web directory. |
249 | -$curlCookieJar = __DIR__ . '/../cookies.txt'; |
|
249 | +$curlCookieJar = __DIR__.'/../cookies.txt'; |
|
250 | 250 | |
251 | 251 | /************************************************************************** |
252 | 252 | ********** IMPORTANT NOTICE ********** |
@@ -260,17 +260,17 @@ discard block |
||
260 | 260 | |
261 | 261 | $cDatabaseConfig = array( |
262 | 262 | "acc" => array( |
263 | - "dsrcname" => "mysql:host=" . $toolserver_host . ";dbname=" . $toolserver_database, |
|
263 | + "dsrcname" => "mysql:host=".$toolserver_host.";dbname=".$toolserver_database, |
|
264 | 264 | "username" => $toolserver_username, |
265 | 265 | "password" => $toolserver_password, |
266 | 266 | ), |
267 | 267 | "wikipedia" => array( |
268 | - "dsrcname" => "mysql:host=" . $antispoof_host . ";dbname=" . $antispoof_db, |
|
268 | + "dsrcname" => "mysql:host=".$antispoof_host.";dbname=".$antispoof_db, |
|
269 | 269 | "username" => $toolserver_username, |
270 | 270 | "password" => $toolserver_password, |
271 | 271 | ), |
272 | 272 | "notifications" => array( |
273 | - "dsrcname" => "mysql:host=" . $toolserver_notification_dbhost . ";dbname=" . $toolserver_notification_database, |
|
273 | + "dsrcname" => "mysql:host=".$toolserver_notification_dbhost.";dbname=".$toolserver_notification_database, |
|
274 | 274 | "username" => $notifications_username, |
275 | 275 | "password" => $notifications_password, |
276 | 276 | ), |
@@ -300,13 +300,13 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | // Set up the AutoLoader |
303 | -require_once(__DIR__ . "/includes/AutoLoader.php"); |
|
303 | +require_once(__DIR__."/includes/AutoLoader.php"); |
|
304 | 304 | spl_autoload_register('Waca\\AutoLoader::load'); |
305 | -require_once(__DIR__ . '/vendor/autoload.php'); |
|
305 | +require_once(__DIR__.'/vendor/autoload.php'); |
|
306 | 306 | |
307 | 307 | // Extra includes which are just plain awkward wherever they are. |
308 | -require_once(__DIR__ . '/lib/mediawiki-extensions-OAuth/lib/OAuth.php'); |
|
309 | -require_once(__DIR__ . '/lib/mediawiki-extensions-OAuth/lib/JWT.php'); |
|
308 | +require_once(__DIR__.'/lib/mediawiki-extensions-OAuth/lib/OAuth.php'); |
|
309 | +require_once(__DIR__.'/lib/mediawiki-extensions-OAuth/lib/JWT.php'); |
|
310 | 310 | |
311 | 311 | // Crap that's needed for libraries. >:( |
312 | 312 | /** |