Merge pull request #1115 from ONLYOFFICE/feature/register-confirm

Feature/register confirm
This commit is contained in:
Alexey Safronov 2022-12-09 12:12:27 +03:00 committed by GitHub
commit 058e6e9448
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 120 additions and 28 deletions

View File

@ -150,7 +150,7 @@ RUN dos2unix /docker-entrypoint.d/prepare-nginx-proxy.sh && \
RUN chown nginx:nginx /etc/nginx/* -R && \
chown nginx:nginx /docker-entrypoint.d/* && \
# changes for upstream configure
# sed -i 's/127.0.0.1:5010/$service_api_system/' /etc/nginx/conf.d/onlyoffice.conf && \
sed -i 's/127.0.0.1:5010/$service_api_system/' /etc/nginx/conf.d/onlyoffice.conf && \
sed -i 's/127.0.0.1:5012/$service_backup/' /etc/nginx/conf.d/onlyoffice.conf && \
sed -i 's/127.0.0.1:5007/$service_files/' /etc/nginx/conf.d/onlyoffice.conf && \
sed -i 's/127.0.0.1:5004/$service_people_server/' /etc/nginx/conf.d/onlyoffice.conf && \
@ -175,13 +175,13 @@ COPY --from=base --chown=onlyoffice:onlyoffice ${BUILD_PATH}/services/ASC.Data.B
CMD ["ASC.Data.Backup.BackgroundTasks.dll", "ASC.Data.Backup.BackgroundTasks"]
# ASC.ApiSystem ##
# FROM dotnetrun AS api_system
# WORKDIR ${BUILD_PATH}/services/ASC.ApiSystem/
FROM dotnetrun AS api_system
WORKDIR ${BUILD_PATH}/services/ASC.ApiSystem/
# COPY --chown=onlyoffice:onlyoffice docker-entrypoint.py ./docker-entrypoint.py
# COPY --from=base --chown=onlyoffice:onlyoffice ${BUILD_PATH}/services/ASC.ApiSystem/service/ .
COPY --chown=onlyoffice:onlyoffice docker-entrypoint.py ./docker-entrypoint.py
COPY --from=base --chown=onlyoffice:onlyoffice ${BUILD_PATH}/services/ASC.ApiSystem/service/ .
# CMD ["ASC.ApiSystem.dll", "ASC.ApiSystem"]
CMD ["ASC.ApiSystem.dll", "ASC.ApiSystem"]
## ASC.ClearEvents ##
FROM dotnetrun AS clear-events

View File

@ -92,12 +92,12 @@ services:
target: api
image: "${REPO}/${DOCKER_IMAGE_PREFIX}-api:${DOCKER_TAG}"
# onlyoffice-api-system:
# build:
# context: ./
# dockerfile: "${DOCKERFILE}"
# target: api_system
# image: "${REPO}/${DOCKER_IMAGE_PREFIX}-api-system:${DOCKER_TAG}"
onlyoffice-api-system:
build:
context: ./
dockerfile: "${DOCKERFILE}"
target: api_system
image: "${REPO}/${DOCKER_IMAGE_PREFIX}-api-system:${DOCKER_TAG}"
onlyoffice-studio:
build:

View File

@ -116,10 +116,10 @@ services:
image: "${REPO}/${DOCKER_IMAGE_PREFIX}-api:${DOCKER_TAG}"
container_name: ${API_HOST}
# onlyoffice-api-system:
# <<: *x-service-base
# image: "${REPO}/${DOCKER_IMAGE_PREFIX}-api-system:${DOCKER_TAG}"
# container_name: ${API_SYSTEM_HOST}
onlyoffice-api-system:
<<: *x-service-base
image: "${REPO}/${DOCKER_IMAGE_PREFIX}-api-system:${DOCKER_TAG}"
container_name: ${API_SYSTEM_HOST}
onlyoffice-studio:
<<: *x-service-base
@ -163,7 +163,7 @@ services:
# - onlyoffice-telegram-service
# - onlyoffice-urlshortener
- onlyoffice-api
# - onlyoffice-api-system
- onlyoffice-api-system
- onlyoffice-studio
- onlyoffice-ssoauth
environment:

View File

@ -20,6 +20,7 @@ const DeactivatePortal = lazy(() =>
import("./sub-components/deactivatePortal")
);
const ContinuePortal = lazy(() => import("./sub-components/continuePortal"));
const Auth = lazy(() => import("./sub-components/auth"));
const Confirm = ({ match }) => {
//console.log("Confirm render");
@ -88,6 +89,7 @@ const Confirm = ({ match }) => {
path={`${path}/PortalContinue`}
component={ContinuePortal}
/>
<ConfirmRoute forUnauthorized path={`${path}/Auth`} component={Auth} />
{/* <Route component={Error404} /> */}
</Switch>

View File

@ -0,0 +1,38 @@
import React, { useEffect } from "react";
import { withRouter } from "react-router";
import Loader from "@docspace/components/loader";
import Section from "@docspace/common/components/Section";
import { loginWithConfirmKey } from "@docspace/common/api/user";
import toastr from "@docspace/components/toast/toastr";
const Auth = (props) => {
console.log("Auth render");
const { linkData } = props;
useEffect(() => {
loginWithConfirmKey({
ConfirmData: {
Email: linkData.email,
Key: linkData.confirmHeader,
},
})
.then((res) => {
console.log("Login with confirm key success", res);
if (typeof res === "string") window.location.replace(res);
else window.location.replace("/");
})
.catch((error) => toastr.error(error));
});
return <Loader className="pageLoader" type="rombs" size="40px" />;
};
const AuthPage = (props) => (
<Section>
<Section.SectionBody>
<Auth {...props} />
</Section.SectionBody>
</Section>
);
export default withRouter(AuthPage);

View File

@ -63,3 +63,12 @@ export function loginWithTfaCode(userName, passwordHash, code) {
data,
});
}
export function loginWithConfirmKey(data) {
return request({
method: "post",
url: `/authentication.json`,
skipLogout: true,
data,
});
}

View File

@ -42,7 +42,8 @@ public class AuthenticationController : ControllerBase
private readonly CookiesManager _cookiesManager;
private readonly PasswordHasher _passwordHasher;
private readonly EmailValidationKeyModelHelper _emailValidationKeyModelHelper;
private readonly ICache _cache;
private readonly ICache _cache;
private readonly SetupInfo _setupInfo;
private readonly MessageService _messageService;
private readonly ProviderManager _providerManager;
private readonly AccountLinker _accountLinker;
@ -66,7 +67,8 @@ public class AuthenticationController : ControllerBase
private readonly CookieStorage _cookieStorage;
private readonly DbLoginEventsManager _dbLoginEventsManager;
private readonly UserManagerWrapper _userManagerWrapper;
private readonly TfaAppAuthSettingsHelper _tfaAppAuthSettingsHelper;
private readonly TfaAppAuthSettingsHelper _tfaAppAuthSettingsHelper;
private readonly EmailValidationKeyProvider _emailValidationKeyProvider;
private readonly BruteForceLoginManager _bruteForceLoginManager;
public AuthenticationController(
@ -103,7 +105,8 @@ public class AuthenticationController : ControllerBase
CookieStorage cookieStorage,
DbLoginEventsManager dbLoginEventsManager,
BruteForceLoginManager bruteForceLoginManager,
TfaAppAuthSettingsHelper tfaAppAuthSettingsHelper)
TfaAppAuthSettingsHelper tfaAppAuthSettingsHelper,
EmailValidationKeyProvider emailValidationKeyProvider)
{
_userManager = userManager;
_tenantManager = tenantManager;
@ -112,7 +115,8 @@ public class AuthenticationController : ControllerBase
_cookiesManager = cookiesManager;
_passwordHasher = passwordHasher;
_emailValidationKeyModelHelper = emailValidationKeyModelHelper;
_cache = cache;
_cache = cache;
_setupInfo = setupInfo;
_messageService = messageService;
_providerManager = providerManager;
_accountLinker = accountLinker;
@ -137,7 +141,8 @@ public class AuthenticationController : ControllerBase
_dbLoginEventsManager = dbLoginEventsManager;
_userManagerWrapper = userManagerWrapper;
_bruteForceLoginManager = bruteForceLoginManager;
_tfaAppAuthSettingsHelper = tfaAppAuthSettingsHelper;
_tfaAppAuthSettingsHelper = tfaAppAuthSettingsHelper;
_emailValidationKeyProvider = emailValidationKeyProvider;
}
[AllowNotPayment]
@ -215,7 +220,12 @@ public class AuthenticationController : ControllerBase
{
var wrapper = await GetUser(inDto);
var viaEmail = wrapper.ViaEmail;
var user = wrapper.UserInfo;
var user = wrapper.UserInfo;
if (user == null || Equals(user, Constants.LostUser))
{
throw new Exception(Resource.ErrorUserNotFound);
}
if (_studioSmsNotificationSettingsHelper.IsVisibleAndAvailableSettings() && _studioSmsNotificationSettingsHelper.TfaEnabledForUser(user.Id))
{
@ -347,12 +357,34 @@ public class AuthenticationController : ControllerBase
var wrapper = new UserInfoWrapper
{
ViaEmail = true
};
};
var action = MessageAction.LoginFailViaApi;
UserInfo user;
UserInfo user = null;
try
{
if ((string.IsNullOrEmpty(inDto.Provider) && string.IsNullOrEmpty(inDto.SerializedProfile)) || inDto.Provider == "email")
{
if (inDto.ConfirmData != null)
{
var email = inDto.ConfirmData.Email;
var checkKeyResult = _emailValidationKeyProvider.ValidateEmailKey(email + ConfirmType.Auth + inDto.ConfirmData.First + inDto.ConfirmData.Module + inDto.ConfirmData.Sms, inDto.ConfirmData.Key, _setupInfo.ValidAuthKeyInterval);
if (checkKeyResult == ValidationResult.Ok)
{
user = email.Contains("@")
? _userManager.GetUserByEmail(email)
: _userManager.GetUsers(new Guid(email));
if (_securityContext.IsAuthenticated && _securityContext.CurrentAccount.ID != user.Id)
{
_securityContext.Logout();
_cookiesManager.ClearCookies(CookiesType.AuthKey);
_cookiesManager.ClearCookies(CookiesType.SocketIO);
}
}
}
else if ((string.IsNullOrEmpty(inDto.Provider) && string.IsNullOrEmpty(inDto.SerializedProfile)) || inDto.Provider == "email")
{
inDto.UserName.ThrowIfNull(new ArgumentException(@"userName empty", "userName"));
if (!string.IsNullOrEmpty(inDto.Password))

View File

@ -36,10 +36,21 @@ public class AuthRequestsDto
public string SerializedProfile { get; set; }
public string Code { get; set; }
public string CodeOAuth { get; set; }
public bool Session { get; set; }
public bool Session { get; set; }
public ConfirmData ConfirmData { get; set; }
}
public class MobileRequestsDto
{
public string MobilePhone { get; set; }
}
public class ConfirmData
{
public string Email { get; set; }
public string Module { get; set; }
public bool? First { get; set; }
public bool? Sms { get; set; }
public string Key { get; set; }
}