def get_email(id): conn = pool.take() cursor = conn.cursor() cursor.execute(u"select email from user where id=%s",(id,)) email, = cursor.fetchone() conn.commit() cursor.close() pool.give(conn) return email
def load_session(self): conn = pool.take() cursor = conn.cursor() cursor.execute("select data from session where uuid = %s",(self.uuid,)) row = cursor.fetchone() if row == None: raise InvalidCookieException() self.data = loads(row[0]) cursor.close() pool.give(conn)
def save_session(self): if not self.changed: return conn = pool.take() cursor = conn.cursor() cursor.execute( "update session set data=%s where uuid = %s", (dumps(self.data,-1), self.uuid) ) cursor.close() conn.commit() pool.give(conn)
def new_session(self): self.uuid = str(uuid4()) self.data = dict() conn = pool.take() cursor = conn.cursor() cursor.execute( "insert into session (uuid, data) VALUES(%s,%s)", (self.uuid,dumps(self.data,-1)) ) cursor.close() conn.commit() pool.give(conn)
def user_id_by_auth(email, password): conn = pool.take() cursor = conn.cursor() cursor.execute(u"select id from user where email=%s and password=%s", (email,password) ) try: id, = cursor.fetchone() except TypeError: raise AuthFailureException() finally: conn.commit() cursor.close() pool.give(conn) return id
def add_user(name, email): if not validEmail(email): raise InvalidEmail() password = _generate_password() conn = pool.take() cursor = conn.cursor() try: cursor.execute(u"insert into user (name, email, password) values(%s,%s,%s)", (name, email,password) ) except IntegrityError: raise EmailExists() finally: cursor.close() conn.commit() pool.give(conn)