示例#1
0
文件: task.py 项目: renzon/pswdless
def send_login_email(_render, login_id, lang):
    logging.info(login_id)
    logging.info(login_id)
    setup_locale(lang)

    def send(login, site, user):
        cmd = gaecookie_facade.sign('ticket', login.key.id())
        cmd.execute()
        signed = cmd.result
        link = settings.APP_HOME + router.to_path(redirect, lang, signed)
        values = {'APP_NAME': settings.APP_NAME, 'site': site.domain, 'login_link': link}
        body = _render('login_email.txt', values)
        subject = _('%(site)s Login Link') % {'site': site.domain}
        logging.info(user)
        logging.info(body)
        mail.send_mail(settings.SENDER_EMAIL,
                       user.email,
                       subject,
                       body)

    facade.send_login_email(login_id, send).execute()
示例#2
0
def send_login_email(_render, login_id, lang):
    logging.info(login_id)
    logging.info(login_id)
    setup_locale(lang)

    def send(login, site, user):
        cmd = gaecookie_facade.sign('ticket', login.key.id())
        cmd.execute()
        signed = cmd.result
        link = settings.APP_HOME + router.to_path(redirect, lang, signed)
        values = {
            'APP_NAME': settings.APP_NAME,
            'site': site.domain,
            'login_link': link
        }
        body = _render('login_email.txt', values)
        subject = _('%(site)s Login Link') % {'site': site.domain}
        logging.info(user)
        logging.info(body)
        mail.send_mail(settings.SENDER_EMAIL, user.email, subject, body)

    facade.send_login_email(login_id, send).execute()
示例#3
0
    def test_success(self):
        # Mocks
        site = Site(domain='pswdless.appspot.com', token='t')
        email = '*****@*****.**'
        user = mommy.make_one(MainUser, email=email)
        login = Login(status=LOGIN_CALL,
                      hook='https://pswdless.appspot.com/foo')
        ndb.put_multi([site, user, login])

        # Arcs
        ndb.put_multi([
            LoginUser(origin=login.key, destination=user.key),
            LoginSite(origin=login.key, destination=site.key)
        ])

        callback_flag = Mock()

        def callback(*args):
            callback_flag()
            zipped = zip([login, site, user], args)
            for expected, current in zipped:
                self.assertEqual(type(expected), type(current))
                self.assertEqual(expected.key, current.key)

        send_email = facade.send_login_email(str(login.key.id()), callback)
        send_email.execute()

        # Login changes
        login_db = login.key.get()
        self.assertEqual(LOGIN_EMAIL, login_db.status)
        search = SingleLoginStatusArcSearch(login)
        login_status = search()
        self.assertIsInstance(login_status, LoginStatus)
        self.assertEqual(LOGIN_EMAIL, login_status.label)

        # Site User creation
        user_search = SingleSiteUserSearch(site)
        db_user = user_search()
        self.assertEqual(user.key, db_user.key)

        # Callback call
        callback_flag.assert_called_once_with()
示例#4
0
    def test_success(self):
        # Mocks
        site = Site(domain='pswdless.appspot.com', token='t')
        email = '*****@*****.**'
        user = mommy.make_one(MainUser, email=email)
        login = Login(status=LOGIN_CALL, hook='https://pswdless.appspot.com/foo')
        ndb.put_multi([site, user, login])

        # Arcs
        ndb.put_multi(
            [LoginUser(origin=login.key, destination=user.key),
             LoginSite(origin=login.key, destination=site.key)])

        callback_flag = Mock()

        def callback(*args):
            callback_flag()
            zipped = zip([login, site, user], args)
            for expected, current in zipped:
                self.assertEqual(type(expected), type(current))
                self.assertEqual(expected.key, current.key)

        send_email = facade.send_login_email(str(login.key.id()), callback)
        send_email.execute()

        # Login changes
        login_db = login.key.get()
        self.assertEqual(LOGIN_EMAIL, login_db.status)
        search = SingleLoginStatusArcSearch(login)
        login_status = search()
        self.assertIsInstance(login_status, LoginStatus)
        self.assertEqual(LOGIN_EMAIL, login_status.label)

        # Site User creation
        user_search = SingleSiteUserSearch(site)
        db_user = user_search()
        self.assertEqual(user.key, db_user.key)

        # Callback call
        callback_flag.assert_called_once_with()