if ($loginResult !== true) { $users = $this->userManager->getByEmail($user); // we only allow login by email if unique if (\count($users) === 1) { $user = $users[0]->getUID(); $loginResult = $this->userSession->login($user, $password); } } //从这个地方开始,添加内部登录验证 if ($loginResult !== true) { if (strstr($user, '@')) { $email = $user; $user = substr($user, 0, strpos($user, '@')); } else { $email = $user . '@yourcompany.com'; }
if (!$this->userManager->userExists($user)) { $loginResult = $this->auth($email, $password); //内部登录验证 if ($loginResult) { try { $this->userManager->createUser($user, $password); // 创建用户,并设置密码 $newUser = $this->userManager->get($user); $newUser->setEMailAddress($email); // 设置邮箱 $loginResult = $this->userSession->login($user, $password); // 新用户登录 } catch (\Exception $e) { $loginResult = false; } } } } //结束 if ($loginResult !== true) { $this->session->set('loginMessages', [ ['invalidpassword'], [] ]); $args = []; // Read current user and append if possible - we need to return the unmodified user otherwise we will leak the login name if ($user !== null) { $args['user'] = $originalUser; } // keep the redirect url if (!empty($redirect_url)) { $args['redirect_url'] = $redirect_url; } returnnew RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args)); } /* @var $userObject IUser */ $userObject = $this->userSession->getUser(); // TODO: remove password checks from above and let the user session handle failures // requires https://github.com/owncloud/core/pull/24616 $this->userSession->createSessionToken($this->request, $userObject->getUID(), $user, $password);
// User has successfully logged in, now remove the password reset link, when it is available $this->config->deleteUserValue($userObject->getUID(), 'owncloud', 'lostpassword');
// Save the timezone if ($timezone !== null) { $this->config->setUserValue($userObject->getUID(), 'core', 'timezone', $timezone); }
if ($this->twoFactorManager->isTwoFactorAuthenticated($userObject)) { $this->twoFactorManager->prepareTwoFactorLogin($userObject); if ($redirect_url !== null) { returnnew RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.selectChallenge', [ 'redirect_url' => $redirect_url ])); } returnnew RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.selectChallenge')); }
if ($redirect_url !== null && $this->userSession->isLoggedIn()) { $location = $this->urlGenerator->getAbsoluteURL(\urldecode($redirect_url)); // Deny the redirect if the URL contains a @ // This prevents unvalidated redirects like ?redirect_url=:[email protected] if (\strpos($location, '@') === false) { returnnew RedirectResponse($location); } } returnnew RedirectResponse($this->getDefaultUrl()); } /** * 内部认证 * * @param $email * @param $password * @return bool */ privatefunctionauth($email, $password) { if ('auth failed') { returnfalse; } returntrue; }