Skip to content

Commit

Permalink
Remove some deprecated interface parts of account registration.
Browse files Browse the repository at this point in the history
  • Loading branch information
fisx committed Aug 5, 2024
1 parent df1f23f commit b2ff4a1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 107 deletions.
42 changes: 0 additions & 42 deletions docs/src/developer/reference/user/registration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
// The password is optional
"password": "secret"
}
```

```
201 Created
Set-Cookie: zuid=...
{
"accent_id": 0,
"assets": [],
"email": "[email protected]",
"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)=

Expand Down
22 changes: 2 additions & 20 deletions services/brig/src/Brig/API/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
20 changes: 2 additions & 18 deletions services/brig/src/Brig/API/Public.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 ->
Expand All @@ -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
Expand All @@ -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 <-
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions services/brig/src/Brig/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
40 changes: 15 additions & 25 deletions services/brig/src/Brig/API/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b2ff4a1

Please sign in to comment.