| Conditions | 8 |
| Paths | 40 |
| Total Lines | 55 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 65 | public function startAction(): void |
||
| 66 | { |
||
| 67 | if (!$this->request->isPost()) { |
||
| 68 | $this->forward('session/index'); |
||
| 69 | } |
||
| 70 | $loginFromUser = (string)$this->request->getPost('login', null, 'guest'); |
||
| 71 | $passFromUser = (string)$this->request->getPost('password', null, 'guest'); |
||
| 72 | $this->flash->clear(); |
||
| 73 | $userLoggedIn = false; |
||
| 74 | $sessionParams = []; |
||
| 75 | // Check if the provided login and password match the stored values |
||
| 76 | if ($this->checkCredentials($loginFromUser, $passFromUser)) |
||
| 77 | { |
||
| 78 | $sessionParams = [ |
||
| 79 | SessionController::ROLE => AclProvider::ROLE_ADMINS, |
||
| 80 | SessionController::HOME_PAGE => $this->url->get('extensions/index'), |
||
| 81 | SessionController::USER_NAME => $loginFromUser |
||
| 82 | ]; |
||
| 83 | $userLoggedIn = true; |
||
| 84 | } else { |
||
| 85 | // Try to authenticate user over additional module |
||
| 86 | $additionalModules = PBXConfModulesProvider::hookModulesMethod(WebUIConfigInterface::AUTHENTICATE_USER, [$loginFromUser, $passFromUser]); |
||
| 87 | |||
| 88 | // Check if any additional module successfully authenticated the user |
||
| 89 | foreach ($additionalModules as $moduleUniqueId => $sessionData) { |
||
| 90 | if (!empty($sessionData)) { |
||
| 91 | $this->loggerAuth->info("User $loginFromUser was authenticated over module $moduleUniqueId"); |
||
| 92 | $sessionParams = $sessionData; |
||
| 93 | $userLoggedIn = true; |
||
| 94 | break; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | if ($userLoggedIn) { |
||
| 100 | // Register the session with the specified parameters |
||
| 101 | $this->_registerSession($sessionParams); |
||
| 102 | if ($this->session->has(PbxSettingsConstants::WEB_ADMIN_LANGUAGE)){ |
||
| 103 | LanguageController::updateSystemLanguage($this->session->get(PbxSettingsConstants::WEB_ADMIN_LANGUAGE)); |
||
| 104 | } |
||
| 105 | $this->view->success = true; |
||
| 106 | $backUri = $this->request->getPost('backUri'); |
||
| 107 | if (!empty($backUri)) { |
||
| 108 | $this->view->reload = $backUri; |
||
| 109 | } else { |
||
| 110 | $this->view->reload = $this->session->get(SessionController::HOME_PAGE); |
||
| 111 | } |
||
| 112 | } else { |
||
| 113 | // Authentication failed |
||
| 114 | $this->view->success = false; |
||
| 115 | $this->flash->error($this->translation->_('auth_WrongLoginPassword')); |
||
| 116 | $remoteAddress = $this->request->getClientAddress(true); |
||
| 117 | $userAgent = $this->request->getUserAgent(); |
||
| 118 | $this->loggerAuth->warning("From: {$remoteAddress} UserAgent:{$userAgent} Cause: Wrong password"); |
||
| 119 | $this->clearAuthCookies(); |
||
| 120 | } |
||
| 237 |