diff --git a/docs/src/developer/reference/user/registration.md b/docs/src/developer/reference/user/registration.md index b598d4ac365..7f57a5dbe19 100644 --- a/docs/src/developer/reference/user/registration.md +++ b/docs/src/developer/reference/user/registration.md @@ -72,48 +72,6 @@ If the code is incorrect or if an incorrect code has been tried enough times, th } ``` -## Registration without pre-verification -(RefRegistrationNoPreverification)= - -_NOTE: This flow is currently not used by any clients. At least this was the state on 2020-05-28_ - -It is also possible to call `POST /register` without verifying the email -address, in which case the account will have to be activated later by calling -[`POST /activate`](RefActivationSubmit). Sample API request and response: - -``` -POST /register - -{ - // The name is mandatory - "name": "Pink", - - // 'email' has to be provided - "email": "pink@example.com", - - // The password is optional - "password": "secret" -} -``` - -``` -201 Created -Set-Cookie: zuid=... - -{ - "accent_id": 0, - "assets": [], - "email": "pink@example.com", - "id": "c193136a-55fb-4534-ad72-d02a72bb16af", - "locale": "en", - "managed_by": "wire", - "name": "Pink", - "picture": [] -} -``` - -A verification email will be sent to the email address (if provided). - ## Anonymous registration, aka "Wireless" (RefRegistrationWireless)= diff --git a/services/brig/src/Brig/API/Internal.hs b/services/brig/src/Brig/API/Internal.hs index 85d5342bc0b..08dba466200 100644 --- a/services/brig/src/Brig/API/Internal.hs +++ b/services/brig/src/Brig/API/Internal.hs @@ -32,7 +32,6 @@ import Brig.API.OAuth (internalOauthAPI) import Brig.API.Types import Brig.API.User qualified as API import Brig.App -import Brig.Data.Activation import Brig.Data.Client qualified as Data import Brig.Data.Connection qualified as Data import Brig.Data.MLS.KeyPackage qualified as Data @@ -94,7 +93,6 @@ import Wire.API.Routes.Internal.Brig.Connection import Wire.API.Routes.Named import Wire.API.Team.Feature qualified as ApiFt import Wire.API.User -import Wire.API.User.Activation import Wire.API.User.Client import Wire.API.User.RichInfo import Wire.API.UserEvent @@ -474,15 +472,7 @@ createUserNoVerify :: (Handler r) (Either RegisterError SelfProfile) createUserNoVerify uData = lift . runExceptT $ do result <- API.createUser uData - let acc = createdAccount result - let usr = accountUser acc - let uid = userId usr - let eac = createdEmailActivation result - for_ eac $ \adata -> - let key = ActivateKey $ activationKey adata - code = activationCode adata - in API.activate key code (Just uid) !>> activationErrorToRegisterError - pure . SelfProfile $ usr + pure $ SelfProfile result.createdAccount.accountUser createUserNoVerifySpar :: ( Member GalleyAPIAccess r, @@ -499,15 +489,7 @@ createUserNoVerifySpar :: createUserNoVerifySpar uData = lift . runExceptT $ do result <- API.createUserSpar uData - let acc = createdAccount result - let usr = accountUser acc - let uid = userId usr - let eac = createdEmailActivation result - for_ eac $ \adata -> - let key = ActivateKey $ activationKey adata - code = activationCode adata - in API.activate key code (Just uid) !>> CreateUserSparRegistrationError . activationErrorToRegisterError - pure . SelfProfile $ usr + pure $ SelfProfile result.createdAccount.accountUser deleteUserNoAuthH :: ( Member (Embed HttpClientIO) r, diff --git a/services/brig/src/Brig/API/Public.hs b/services/brig/src/Brig/API/Public.hs index fd28aa8afbb..a72d434dfe7 100644 --- a/services/brig/src/Brig/API/Public.hs +++ b/services/brig/src/Brig/API/Public.hs @@ -51,7 +51,6 @@ import Brig.Options hiding (internalEvents) import Brig.Provider.API import Brig.Team.API qualified as Team import Brig.Team.Email qualified as Team -import Brig.Types.Activation (ActivationPair) import Brig.Types.Intra (UserAccount (UserAccount, accountUser)) import Brig.Types.User (HavePendingInvitations (..)) import Brig.User.API.Handle qualified as Handle @@ -61,7 +60,7 @@ import Brig.User.Auth.Cookie qualified as Auth import Cassandra qualified as C import Cassandra qualified as Data import Control.Error hiding (bool, note) -import Control.Lens (view, (.~), (?~), (^.)) +import Control.Lens (view, (.~), (?~)) import Control.Monad.Catch (throwM) import Control.Monad.Except import Data.Aeson hiding (json) @@ -129,7 +128,6 @@ import Wire.API.Routes.Public.Util import Wire.API.Routes.Version import Wire.API.SwaggerHelper (cleanupSwagger) import Wire.API.SystemSettings -import Wire.API.Team qualified as Public import Wire.API.Team.LegalHold (LegalholdProtectee (..)) import Wire.API.Team.Member (HiddenPerm (..), hasPermission) import Wire.API.User (RegisterError (RegisterErrorAllowlistError)) @@ -707,7 +705,6 @@ createUser :: Member (Input (Local ())) r, Member (Input UTCTime) r, Member (ConnectionStore InternalPaging) r, - Member EmailSubsystem r, Member EmailSending r ) => Public.NewUserPublic -> @@ -720,8 +717,6 @@ createUser (Public.NewUserPublic new) = lift . runExceptT $ do result <- API.createUser new let acc = createdAccount result - let eac = createdEmailActivation result - let epair = (,) <$> (activationKey <$> eac) <*> (activationCode <$> eac) let newUserLabel = Public.newUserLabel new let newUserTeam = Public.newUserTeam new let usr = accountUser acc @@ -739,12 +734,10 @@ createUser (Public.NewUserPublic new) = lift . runExceptT $ do ) lift . Log.info $ context . Log.msg @Text "Sucessfully created user" - let Public.User {userLocale, userDisplayName} = usr + let Public.User {userLocale} = usr userEmail = Public.userEmail usr userId = Public.userId usr lift $ do - for_ (liftM2 (,) userEmail epair) $ \(e, p) -> - sendActivationEmail e userDisplayName p (Just userLocale) newUserTeam for_ (liftM3 (,,) userEmail (createdUserTeam result) newUserTeam) $ \(e, ct, ut) -> sendWelcomeEmail e ct ut (Just userLocale) cok <- @@ -758,15 +751,6 @@ createUser (Public.NewUserPublic new) = lift . runExceptT $ do -- pure $ CreateUserResponse cok userId (Public.SelfProfile usr) pure $ Public.RegisterSuccess cok (Public.SelfProfile usr) where - sendActivationEmail :: (Member EmailSubsystem r) => Public.Email -> Public.Name -> ActivationPair -> Maybe Public.Locale -> Maybe Public.NewTeamUser -> (AppT r) () - sendActivationEmail email name (key, code) locale mTeamUser - | Just teamUser <- mTeamUser, - Public.NewTeamCreator creator <- teamUser, - let Public.BindingNewTeamUser (Public.BindingNewTeam team) _ = creator = - liftSem $ sendTeamActivationMail email name key code locale (fromRange $ team ^. Public.newTeamName) - | otherwise = - liftSem $ sendActivationMail email name key code locale - sendWelcomeEmail :: (Member EmailSending r) => Public.Email -> CreateUserTeam -> Public.NewTeamUser -> Maybe Public.Locale -> (AppT r) () -- NOTE: Welcome e-mails for the team creator are not dealt by brig anymore sendWelcomeEmail e (CreateUserTeam t n) newUser l = case newUser of diff --git a/services/brig/src/Brig/API/Types.hs b/services/brig/src/Brig/API/Types.hs index 8251e823b81..53740901d6e 100644 --- a/services/brig/src/Brig/API/Types.hs +++ b/services/brig/src/Brig/API/Types.hs @@ -51,8 +51,6 @@ import Wire.UserKeyStore data CreateUserResult = CreateUserResult { -- | The newly created user account. createdAccount :: !UserAccount, - -- | Activation data for the registered email address, if any. - createdEmailActivation :: !(Maybe Activation), -- | Info of a team just created/joined createdUserTeam :: !(Maybe CreateUserTeam) } diff --git a/services/brig/src/Brig/API/User.hs b/services/brig/src/Brig/API/User.hs index cc5c2bcc3cd..2d4fb396b15 100644 --- a/services/brig/src/Brig/API/User.hs +++ b/services/brig/src/Brig/API/User.hs @@ -236,7 +236,7 @@ createUserSpar new = do -- Set handle lift $ updateHandle' luid handle' - pure $! CreateUserResult account Nothing (Just userTeam) + pure $! CreateUserResult account (Just userTeam) where updateHandle' :: Local UserId -> Maybe Handle -> AppT r () updateHandle' _ Nothing = pure () @@ -363,14 +363,11 @@ createUser new = do pure (activatedTeam <|> joinedTeamInvite <|> joinedTeamSSO) - edata <- - if isJust teamInvitation - then pure Nothing - else handleEmailActivation email uid mNewTeamUser - + when (isNothing teamInvitation) do + handleEmailActivation email uid mNewTeamUser lift $ initAccountFeatureConfig uid - pure $! CreateUserResult account edata createUserTeam + pure $! CreateUserResult account createUserTeam where -- NOTE: all functions in the where block don't use any arguments of createUser @@ -461,24 +458,17 @@ createUser new = do Team.TeamName nm <- lift $ liftSem $ GalleyAPIAccess.getTeamName tid pure $ CreateUserTeam tid nm - -- Handle e-mail activation (deprecated, see #RefRegistrationNoPreverification in /docs/reference/user/registration.md) - handleEmailActivation :: Maybe Email -> UserId -> Maybe BindingNewTeamUser -> ExceptT RegisterError (AppT r) (Maybe Activation) - handleEmailActivation email uid newTeam = do - fmap join . for (mkEmailKey <$> email) $ \ek -> case newUserEmailCode new of - Nothing -> do - timeout <- setActivationTimeout <$> view settings - edata <- lift . wrapClient $ Data.newActivation ek timeout (Just uid) - lift . liftSem . Log.info $ - field "user" (toByteString uid) - . field "activation.key" (toByteString $ activationKey edata) - . msg (val "Created email activation key/code pair") - pure $ Just edata - Just c -> do - ak <- liftIO $ Data.mkActivationKey ek - void $ - activateWithCurrency (ActivateKey ak) c (Just uid) (bnuCurrency =<< newTeam) - !>> activationErrorToRegisterError - pure Nothing + -- Handle e-mail activation (se #RefRegistrationStandard in /docs/reference/user/registration.md) + handleEmailActivation :: Maybe Email -> UserId -> Maybe BindingNewTeamUser -> ExceptT RegisterError (AppT r) () + handleEmailActivation email uid newTeam = maybe (pure ()) hdl (mkEmailKey <$> email) + where + hdl ek = case newUserEmailCode new of + Nothing -> throwE RegisterErrorInvalidActivationCodeWrongCode -- (actually no code. should we introduce a new error for that?) + Just c -> do + ak <- liftIO $ Data.mkActivationKey ek + void $ + activateWithCurrency (ActivateKey ak) c (Just uid) (bnuCurrency =<< newTeam) + !>> activationErrorToRegisterError initAccountFeatureConfig :: UserId -> (AppT r) () initAccountFeatureConfig uid = do