Beispiel #1
0
        public async Task <ActionResult <Api.User> > PutUser([FromBody] Api.UserRequest user)
        {
            try
            {
                if (!await ModelState.TryValidateObjectAsync(user))
                {
                    return(BadRequest(ModelState));
                }
                user.Email = user.Email?.ToLower();

                var mUser = await tenantRepository.GetAsync <Models.User>(await Models.User.IdFormat(RouteBinding, user.Email));

                mUser.ConfirmAccount = user.ConfirmAccount;
                mUser.EmailVerified  = user.EmailVerified;
                mUser.ChangePassword = user.ChangePassword;
                mUser.DisableAccount = user.DisableAccount;
                var mClaims = mapper.Map <List <Models.ClaimAndValues> >(user.Claims);
                mUser.Claims = mClaims;
                await tenantRepository.UpdateAsync(mUser);

                return(Ok(mapper.Map <Api.User>(mUser)));
            }
            catch (CosmosDataException ex)
            {
                if (ex.StatusCode == HttpStatusCode.NotFound)
                {
                    logger.Warning(ex, $"NotFound, Update '{typeof(Api.UserRequest).Name}' by email '{user.Email}'.");
                    return(NotFound(typeof(Api.UserRequest).Name, user.Email));
                }
                throw;
            }
        }
Beispiel #2
0
        public async Task <ActionResult <Api.User> > PutUser([FromBody] Api.UserRequest user)
        {
            try
            {
                if (!await ModelState.TryValidateObjectAsync(user))
                {
                    return(BadRequest(ModelState));
                }
                user.Email = user.Email?.ToLower();

                var mUser = await tenantRepository.GetAsync <Models.User>(await Models.User.IdFormat(RouteBinding, user.Email));

                mUser.ConfirmAccount = user.ConfirmAccount;
                mUser.EmailVerified  = user.EmailVerified;
                mUser.ChangePassword = user.ChangePassword;
                mUser.DisableAccount = user.DisableAccount;
                if (!user.ActiveTwoFactorApp)
                {
                    if (!mUser.TwoFactorAppSecretExternalName.IsNullOrEmpty())
                    {
                        try
                        {
                            await externalSecretLogic.DeleteExternalSecretAsync(mUser.TwoFactorAppSecretExternalName);
                        }
                        catch (Exception ex)
                        {
                            logger.Warning(ex, $"Unable to delete external secret, secretExternalName '{mUser.TwoFactorAppSecretExternalName}'.");
                        }
                    }

                    mUser.TwoFactorAppSecretExternalName = null;
                    mUser.TwoFactorAppRecoveryCode       = null;
                }
                mUser.RequireMultiFactor = user.RequireMultiFactor;
                var mClaims = mapper.Map <List <Models.ClaimAndValues> >(user.Claims);
                mUser.Claims = mClaims;
                await tenantRepository.UpdateAsync(mUser);

                return(Ok(mapper.Map <Api.User>(mUser)));
            }
            catch (CosmosDataException ex)
            {
                if (ex.StatusCode == HttpStatusCode.NotFound)
                {
                    logger.Warning(ex, $"NotFound, Update '{typeof(Api.UserRequest).Name}' by email '{user.Email}'.");
                    return(NotFound(typeof(Api.UserRequest).Name, user.Email));
                }
                throw;
            }
        }