def test_factory_w_secret(self): from repoze.who.plugins.auth_tkt import make_plugin plugin = make_plugin('secret') self.assertEqual(plugin.cookie_name, 'auth_tkt') self.assertEqual(plugin.secret, 'secret') self.assertEqual(plugin.include_ip, False) self.assertEqual(plugin.secure, False)
def test_factory_w_secretfile(self): import os from tempfile import mkdtemp from repoze.who.plugins.auth_tkt import make_plugin tempdir = self.tempdir = mkdtemp() path = os.path.join(tempdir, 'who.secret') secret = open(path, 'w') secret.write('s33kr1t\n') secret.flush() secret.close() plugin = make_plugin(secretfile=path) self.assertEqual(plugin.secret, 's33kr1t')
def test_factory_with_userid_checker(self): from repoze.who.plugins.auth_tkt import make_plugin plugin = make_plugin( 'secret', userid_checker='repoze.who.plugins.auth_tkt:make_plugin') self.assertEqual(plugin.userid_checker, make_plugin)
def test_factory_with_timeout_and_reissue_time(self): from repoze.who.plugins.auth_tkt import make_plugin plugin = make_plugin('secret', timeout=5, reissue_time=1) self.assertEqual(plugin.timeout, 5) self.assertEqual(plugin.reissue_time, 1)
def test_factory_with_alternate_hash_func(self): from repoze.who.plugins.auth_tkt import make_plugin import hashlib plugin = make_plugin('secret', digest_algo=hashlib.sha1) self.assertEqual(plugin.digest_algo, hashlib.sha1)
def allocate(self): captcha_response = h.recaptcha.submit() if captcha_response.is_valid: login = request.params['login'].lower() password = md5(request.params['password'] + login).hexdigest() if not valid(login): return 'Invalid Mail Address' # Create the user account in the database try: db = psycopg2.connect("dbname=triggr") qr = db.cursor() qr.execute("select * from fn_account_create(%s, %s)", (login, password)) qr.execute("select * from logging.fn_signup(%(userid)s)", {'userid': login}) db.commit() except: return 'An account with that email address already exists; please <a style="color: blue" href="javascript:history.back(1)">try again</a>' # Attempt to automatically log the user in try: # This is a bit of a workaround - manually instantiate a user identity ... request.environ['repoze.who.identity'] = { 'identifier': 'form', 'repoze.who.userid': login, } # ... create a repoze.who cookie authentication plugin ... plugin = auth_tkt.make_plugin(secret='N0t1fy', cookie_name='auth_tkt') # ... and use it to persist the user's newly-created account in their session cookies = plugin.remember(request.environ, request.environ['repoze.who.identity']) for (header, value) in cookies: response.headers.add(str(header), str(value)) except: pass # Send a new account notification addrFrom = '*****@*****.**' addrTo = login subject = 'Triggr: User Account Created' body = """\ From: %s To: %s Subject: %s Welcome to Triggr! Your user account has been created and you'll now be able to log into the website using your e-mail address (%s) and the password you supplied during registration. We're still a new service, so things may be a little rocky from time to time, but we'll do our best and will always listen to feedback. If you find any problems with the service, just reply to this message or use the 'contact' link on the https://triggr.me site to get in touch, and we'll get back to you! Enjoy the service and we hope it comes in useful! Regards, Team Triggr """ % (addrFrom, addrTo, subject, addrTo) server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.login('*****@*****.**', 'T3llM3Wh3n') server.sendmail(addrFrom, addrTo, body) server.quit() for row in qr.fetchall(): pass return 'Account Created' else: return render('/account_create.mako')