<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 async def add_message(self, request):
 """Registers a new message for the user."""

        session = await get_session(request)
        user_id = session.get('user_id')
        if not user_id:
            raise web.HTTPNotAuthorized()
        form = await request.post()

        if form.get('text'):
            user = await self.mongo.user.find_one(
                {'_id': ObjectId(session['user_id'])},
                {'email': 1, 'username': 1})

            await self.mongo.message.insert(
                {'author_id': ObjectId(user_id),
                 'email': user['email'],
                 'username': user['username'],
                 'text': form['text'],
                 'pub_date': datetime.datetime.utcnow()})
        return redirect(request, 'timeline')