# Path: yithlibraryserver/email.py
# def send_email(request, template, context, subject, recipients,
#                attachments=None, extra_headers=None):
#     message = create_message(request, template, context, subject, recipients,
#                              attachments, extra_headers)
#     return get_mailer(request).send(message)


import uuid
from yithlibraryserver.email import send_email
        return str(uuid.uuid4())

    def store(self, db, user):
        result = db.users.update({'_id': user['_id']}, {
                '$set': {'email_verification_code': self.code},
                }, safe=True)
        return result['n'] == 1

    def remove(self, db, email, verified):
        result = db.users.update({
                'email_verification_code': self.code,
                'email': email,
                }, {
                '$unset': {'email_verification_code': 1},
                '$set': {'email_verified': verified},
                }, safe=True)
        return result['n'] == 1

    def verify(self, db, email):
        result = db.users.find_one({
                'email': email,
                'email_verification_code': self.code,
                })
        return result is not None

    def send(self, request, user, url):
        context = {
            'link': '%s?code=%s&email=%s' % (url, self.code, user['email']),
            'user': user,
        }

# Path: yithlibraryserver/email.py
# def send_email(request, template, context, subject, recipients,
#                attachments=None, extra_headers=None):
#     message = create_message(request, template, context, subject, recipients,
#                              attachments, extra_headers)
#     return get_mailer(request).send(message)


# Path: yithlibraryserver/user/email_verification.py
import uuid
from yithlibraryserver.email import send_email

        return str(uuid.uuid4())

    def store(self, db, user):
        result = db.users.update({'_id': user['_id']}, {
                '$set': {'email_verification_code': self.code},
                }, safe=True)
        return result['n'] == 1

    def remove(self, db, email, verified):
        result = db.users.update({
                'email_verification_code': self.code,
                'email': email,
                }, {
                '$unset': {'email_verification_code': 1},
                '$set': {'email_verified': verified},
                }, safe=True)
        return result['n'] == 1

    def verify(self, db, email):
        result = db.users.find_one({
                'email': email,
                'email_verification_code': self.code,
                })
        return result is not None

    def send(self, request, user, url):
        context = {
            'link': '%s?code=%s&email=%s' % (url, self.code, user['email']),
            'user': user,
        }

        return send_email(