diff --git a/keyserver/src/responders/user-responders.js b/keyserver/src/responders/user-responders.js --- a/keyserver/src/responders/user-responders.js +++ b/keyserver/src/responders/user-responders.js @@ -4,7 +4,7 @@ import t from 'tcomb'; import bcrypt from 'twin-bcrypt'; -import { policies } from 'lib/facts/policies.js'; +import { policies, policyTypes } from 'lib/facts/policies.js'; import { hasMinCodeVersion } from 'lib/shared/version-utils'; import type { ResetPasswordRequest, @@ -66,7 +66,7 @@ } from '../updaters/account-updaters'; import { userSubscriptionUpdater } from '../updaters/user-subscription-updaters'; import { viewerAcknowledgmentUpdater } from '../updaters/viewer-acknowledgment-updater.js'; -import { validateInput } from '../utils/validation-utils'; +import { policiesValidator, validateInput } from '../utils/validation-utils'; import { entryQueryInputValidator, newEntryQueryInputValidator, @@ -290,6 +290,15 @@ if (rawEntryInfos) { response.rawEntryInfos = rawEntryInfos; } + + try { + await policiesValidator(viewer, [policyTypes.tosAndPrivacyPolicy]); + } catch (error) { + if (error.message === 'policies_not_accepted') { + response.notAcknowledgedPolicies = error.payload.notAcknowledgedPolicies; + } + } + return response; } diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js --- a/lib/actions/user-actions.js +++ b/lib/actions/user-actions.js @@ -147,6 +147,7 @@ userInfos, updatesCurrentAsOf: response.serverTime, logInActionSource: logInInfo.logInActionSource, + notAcknowledgedPolicies: response.notAcknowledgedPolicies, }; }; diff --git a/lib/hooks/log-in-call.js b/lib/hooks/log-in-call.js new file mode 100644 --- /dev/null +++ b/lib/hooks/log-in-call.js @@ -0,0 +1,35 @@ +// @flow + +import * as React from 'react'; +import { useDispatch } from 'react-redux'; + +import { logIn } from '../actions/user-actions.js'; +import type { LogInInfo, LogInResult } from '../types/account-types.js'; +import { forcePolicyAcknowledgmentActionType } from '../types/policy-types.js'; +import { useServerCall } from '../utils/action-utils.js'; + +function useLogInServerCall(): (logInInfo: LogInInfo) => Promise { + const dispatch = useDispatch(); + const callLogIn = useServerCall(logIn); + + return React.useCallback( + async (logInInfo: LogInInfo) => { + const result = await callLogIn(logInInfo); + if ( + result.notAcknowledgedPolicies && + result.notAcknowledgedPolicies.length + ) { + dispatch({ + type: forcePolicyAcknowledgmentActionType, + payload: { + notAcknowledgedPolicies: result.notAcknowledgedPolicies, + }, + }); + } + return result; + }, + [callLogIn, dispatch], + ); +} + +export { useLogInServerCall }; diff --git a/lib/types/account-types.js b/lib/types/account-types.js --- a/lib/types/account-types.js +++ b/lib/types/account-types.js @@ -129,6 +129,7 @@ threadInfos: { +[id: string]: RawThreadInfo }, userInfos: $ReadOnlyArray, }, + notAcknowledgedPolicies?: $ReadOnlyArray, }; export type LogInResult = { @@ -139,6 +140,7 @@ +calendarResult: CalendarResult, +updatesCurrentAsOf: number, +logInActionSource: LogInActionSource, + +notAcknowledgedPolicies?: $ReadOnlyArray, }; export type UpdatePasswordRequest = { diff --git a/native/account/log-in-panel.react.js b/native/account/log-in-panel.react.js --- a/native/account/log-in-panel.react.js +++ b/native/account/log-in-panel.react.js @@ -5,7 +5,8 @@ import { View, StyleSheet, Alert, Keyboard, Platform } from 'react-native'; import Animated from 'react-native-reanimated'; -import { logInActionTypes, logIn } from 'lib/actions/user-actions'; +import { logInActionTypes } from 'lib/actions/user-actions'; +import { useLogInServerCall } from 'lib/hooks/log-in-call'; import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors'; import { validEmailRegex, @@ -20,7 +21,6 @@ } from 'lib/types/account-types'; import type { LoadingStatus } from 'lib/types/loading-types'; import { - useServerCall, useDispatchActionPromise, type DispatchActionPromise, } from 'lib/utils/action-utils'; @@ -366,7 +366,7 @@ ); const dispatchActionPromise = useDispatchActionPromise(); - const callLogIn = useServerCall(logIn); + const callLogIn = useLogInServerCall(); return (