def post(self): global VerifyLinkIDLength with db.getCur() as cur: email = self.get_argument("email", None) cur.execute("SELECT Id FROM Users WHERE Email = ?", (email, )) row = cur.fetchone() if row is not None: code = util.randString(VerifyLinkIDLength) cur.execute( "INSERT INTO ResetLinks(Id, User, Expires) " "VALUES (?, ?, ?)", (code, row[0], expiration_date().isoformat())) util.sendEmail( email, "Your {0} Account".format(settings.WEBSITENAME), """ <p>Here's the link to reset your {websitename} account password.<br /> Click <a href="{hostprefix}/reset/{code}">this link</a> to reset your password, or copy and paste the following into your URL bar:<br /> {hostprefix}/reset/{code} </p> """.format(websitename=settings.WEBSITENAME, hostprefix=this_server(self.request), code=code)) self.render("message.html", message="Your password reset link has been sent") else: self.render( "message.html", message="No account found associated with this email", email=email)
def __init__(self, config_file=None, runmode="local"): self.start_time = time.time() self.config = updateConfig(DEFAULT_CONFIG, config_file) self.runmode = runmode self.client_name = "client_%s_%s" % (runmode, randString(self.config['client_uid_length'])) self.client_dir = os.path.join(self.config['base_dir'], self.client_name) self.create_client_dir() self.logger = Logger(os.path.join(self.client_dir, "log.txt"), "a") sys.stdout = self.logger sys.stderr = self.logger print "[%s][%s] Starting client with following config:" % (getTime(), self.client_name) pprint.pprint(self.config, indent=2); print my_queue = ShortestTaskQueue if self.config['runmode'] == "hybrid" else FIFOQueue self.submit_queue = my_queue(queue_dir=os.path.join(self.config['base_dir'], self.config['submit_queue_name'])) self.result_queue = my_queue(queue_dir=os.path.join(self.config['base_dir'], self.config['result_queue_name'])) self.stop_running = False self.run()
def post(self): global VerifyLinkIDLength email = self.get_argument('email', None) if not db.valid['email'].match(email): self.render("setup.html", message="Please enter a valid email address.") else: with db.getCur() as cur: code = util.randString(VerifyLinkIDLength) cur.execute( "INSERT INTO VerifyLinks (Id, Email, Expires) " "VALUES (?, LOWER(?), ?)", (code, email, expiration_date().isoformat())) if len(settings.EMAILPASSWORD) > 0: util.sendEmail( email, "Your {0} Account".format(settings.WEBSITENAME), format_invite(settings.WEBSITENAME, this_server(self.request), code)) self.render( "message.html", message="Invite sent. It will expire in {0} days.". format(settings.LINKVALIDDAYS), title="Invite") else: self.redirect("{}/verify/{}".format( settings.PROXYPREFIX.rstrip('/'), code))
def post(self): email = self.get_argument('email', None) if not re.match("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]+$", email, flags = re.IGNORECASE): self.render("invite.html", message = "Please enter a valid email address.") else: with db.getCur() as cur: cur.execute("SELECT Email from Users where Email = ?", (email,)) try: existing = cur.fetchone()[0] self.render("message.html", message = "Account for {0} already exists.".format( email), title="Duplicate Account") return except: pass code = util.randString(32) cur.execute("INSERT INTO VerifyLinks (Id, Email, Expires) " "VALUES (?, LOWER(?), ?)", (code, email, expiration_date().isoformat())) util.sendEmail(email, "Your {0} Account".format(settings.CLUBNAME), format_invite(settings.CLUBNAME, self.request.host, code)) self.render("message.html", message = "Invite sent. It will expire in {0} days." .format(settings.LINKVALIDDAYS), title = "Invite")
def email(email_address): with db.getCur() as cur: code = util.randString(32) cur.execute( "INSERT INTO VerifyLinks (Id, Email, Expires) VALUES (?, ?, ?)", (code, email_address, (datetime.date.today() + datetime.timedelta(days=7)).isoformat())) util.sendEmail( email_address, "Your {0} Account".format(settings.CLUBNAME), login.format_invite(settings.CLUBNAME, settings.WEBHOST, code))
def post(self): with db.getCur() as cur: email = self.get_argument("email", None) cur.execute("SELECT Id FROM Users WHERE Email = ?", (email,)) row = cur.fetchone() if row is not None: code = util.randString(32) cur.execute("INSERT INTO ResetLinks(Id, User, Expires) VALUES (?, ?, ?)", (code, row[0], (datetime.date.today() + datetime.timedelta(days=7)).isoformat())) util.sendEmail(email, "Your SeattleMahjong Account", "<p>Here's the link to reset your SeattleMahjong account password\n<br />\ Click <a href=\"http://" + self.request.host + "/reset/" + code + "\">this</a> link to reset your password or copy and paste the following into your URL bar:<br />http://" + self.request.host + "/reset/" + code + "</p>\n") self.render("message.html", message = "Your password reset link has been sent") else: self.render("message.html", message = "No accounts found associated with this email", email = email)
def post(self): email = self.get_argument('email', None) if not re.match("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]+$", email, flags = re.IGNORECASE): self.render("invite.html", message = "Please enter a valid email address.") else: with db.getCur() as cur: code = util.randString(32) cur.execute("INSERT INTO VerifyLinks (Id, Email, Expires) VALUES (?, LOWER(?), ?)", (code, email, (datetime.date.today() + datetime.timedelta(days=7)).isoformat())) util.sendEmail(email, "Your SeattleMahjong Account", "<p>You've been invited to SeattleMahjong\n<br />\ Click <a href=\"http://" + self.request.host + "/verify/" + code + "\">this</a> link to accept the invite and register an account or copy and paste the following into your URL bar:<br />http://" + self.request.host + "/verify/" + code + "</p>\n" + "<p>If you believe you received this email in error, it can be safely ignored. It is likely a user simply entered your email by mistake.</p>") self.render("message.html", message = "Invite sent. It will expire in 7 days.", title = "Invite")
def push(self, task_object): task_obj_str = pickle.dumps(task_object, protocol=pickle.HIGHEST_PROTOCOL) # task_obj_str = jsonpickle.encode(task_object) # task_obj_hash = md5.new(task_obj_str).hexdigest() task_file = "%s.%s_%s_%s" % (int(time.time()), str( time.time() % 1.0)[2:8], str( task_object.estimated_time), randString(16)) task_file = os.path.join(self.queue_dir, task_file) with open(task_file, 'wb') as f: f.write(task_obj_str) f.flush() os.fsync(f.fileno()) os.rename(task_file, task_file + ".task") if DEBUG_MODE: print "pushing task to %s: %s" % (self.queue_dir, task_file)
def post(self): email = self.get_argument('email', None) if not re.match("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]+$", email, flags = re.IGNORECASE): self.render("setup.html", message = "Please enter a valid email address.") else: with db.getCur() as cur: code = util.randString(32) cur.execute("INSERT INTO VerifyLinks (Id, Email, Expires) " "VALUES (?, LOWER(?), ?)", (code, email, expiration_date().isoformat())) util.sendEmail(email, "Your {0} Account".format(settings.CLUBNAME), format_invite(settings.CLUBNAME, self.request.host, code)) self.render("message.html", message = "Invite sent. It will expire in {0} days." .format(settings.LINKVALIDDAYS), title = "Invite")
def __init__(self, task=None, task_data=None, is_result=False, estimated_time=None, metadata={}): if is_result: assert task is None assert estimated_time is None self.uid = randString(UID_LENGTH) self.time_created = time.time() self.num_failures = 0 self.is_result = is_result self.task = task self.task_data = task_data self.estimated_time = estimated_time self.metadata = metadata
def post(self): global VerifyLinkIDLength email = self.get_argument('email', None) if not db.valid['email'].match(email): self.render("invite.html", message="Please enter a valid email address.") else: with db.getCur() as cur: cur.execute("SELECT Email from Users where Email = ?", (email, )) try: existing = cur.fetchone()[0] self.render( "message.html", message="Account for {0} already exists.".format( email), title="Duplicate Account") return except: pass code = util.randString(VerifyLinkIDLength) cur.execute( "INSERT INTO VerifyLinks (Id, Email, Expires) " "VALUES (?, LOWER(?), ?)", (code, email, expiration_date().isoformat())) util.sendEmail( email, "Your {0} Account".format(settings.WEBSITENAME), format_invite(settings.WEBSITENAME, this_server(self.request), code)) self.render( "message.html", message="Invite sent. It will expire in {0} days.".format( settings.LINKVALIDDAYS), title="Invite")
import json import datetime from quemail import QueMail import handler import util import db import settings import seating import login import admin # import and define tornado-y things from tornado.options import define, options cookie_secret = util.randString(32) class MainHandler(handler.BaseHandler): def get(self): admin = self.get_secure_cookie("admin") self.render("index.html", admin = admin) class AddGameHandler(handler.BaseHandler): @tornado.web.authenticated def get(self): self.render("addgame.html") @tornado.web.authenticated def post(self): scores = self.get_argument('scores', None) if scores is None: self.write('{"status":1, "error":"Please enter some scores"}')
def post(self): global user_fields userdata = json.loads(self.get_argument('userdata', None)) if userdata is None or not ( isinstance(userdata['userID'], int) or userdata['userID'].isdigit() or userdata['userID'] == "-1"): return self.write(json.dumps( {'status':"error", 'message':"Invalid user ID provided"})) if not userdata['action'] in ['delete', 'update', 'resetpwd', 'add']: return self.write(json.dumps( {'status':"error", 'message':"Invalid action requested: {}".format( userdata['action'])})) try: user = str(userdata['userID']) action = userdata['action'] updatedict = dict( [i for i in userdata.items() if not i[0] in ['action', 'userID']]) log.debug('Request to {} user {} {}'.format( userdata['action'], userdata['userID'], updatedict)) with db.getCur() as cur: if action != 'add': cur.execute("SELECT Id FROM Users WHERE Id = ?", (user,)) if cur.fetchone() is None: return self.write(json.dumps( {'status':"error", 'message':"Please provide a valid user ID"})) else: cur.execute("INSERT INTO Users (Email, Password) VALUES" " (?, ?)", ('newuser', '?')) user = str(cur.lastrowid) log.info('Inserted new user ID {}'.format(user)) if action == 'delete': cur.execute("DELETE from Admins WHERE Id = ?", (user,)) cur.execute("DELETE from Users WHERE Id = ?", (user,)) log.info('Deleted user {}'.format(user)) elif action == 'resetpwd': code = util.randString(login.VerifyLinkIDLength) cur.execute("INSERT INTO ResetLinks(Id, User, Expires) " "VALUES (?, ?, ?)", (code, user, login.expiration_date(duration=1).isoformat())) log.info('Set up password reset for user {}'.format( user)) return self.write(json.dumps( {'status':"success", 'redirect': "{}/reset/{}?nexturi={}&nexttask={}".format( settings.PROXYPREFIX.rstrip('/'), code, url_escape('{}/users.html'.format( settings.PROXYPREFIX.rstrip('/'))), url_escape('Return to Users'))})) elif action == 'update': for colname, val in updatedict.items(): col = colname.lower() if isinstance(val, str): val = val.lower() if not col in user_fields or not db.valid[ col if col in db.valid else 'all'].match(val): return self.write(json.dumps( {'status':"error", 'message':"Invalid column or value provided"})) if not updatedict.get('Admin', False) == '1': cur.execute("DELETE from Admins WHERE Id = ?", (user,)) log.debug('Removed admin privilege from user {}' .format(user)) else: cur.execute( "INSERT OR IGNORE INTO Admins (Id) VALUES (?)", (user,)) log.debug('Granted admin privilege to user {}' .format(user)) for colname, val in updatedict.items(): if not colname.lower() in ('id', 'admin', 'password'): cur.execute("UPDATE Users SET {} = ? WHERE Id = ?" .format(colname), (val, user)) log.debug('Set {} to {} for user {}'.format( colname, val, user)) elif action == 'add': pass else: return self.write(json.dumps( {'status':"error", 'message': "Unknown action '{}' reqeusted".format( action)})) return self.write(json.dumps({'status':"success"})) except Exception as e: log.error('Error in ManageUsersHandler.post: {}'.format(e)) return self.write(json.dumps( {'status':"error", 'message':"Invalid info provided"}))
import seating import timers import login import admin import scores import leaderboard import playerstats import players import ratings import version # import and define tornado-y things from tornado.options import options cookie_secret = util.randString(32) class MainHandler(handler.BaseHandler): def get(self): admin = handler.stringify(self.get_secure_cookie("admin")) no_user = False with db.getCur() as cur: cur.execute("SELECT COUNT(*) FROM Users") no_user = cur.fetchone()[0] == 0 self.render("index.html", admin=admin, no_user=no_user) class HistoryHandler(handler.BaseHandler):