def register_handler(self, username=None, password=None, confirm_password=None, y=None, x=None, Submit=None): DBSession = DBSessionmaker() if password == confirm_password and username is not None and password is not None and confirm_password is not None: if DBSession.query(User).filter( User.user_name == username).count() == 0: newuser = User(username, password, 0) normal = DBSession.query(Group).filter( Group.group_name == 'normal').first() newuser.groups = newuser.groups + [normal] DBSession.add(newuser) DBSession.commit() flash(_('Successfully Registered, %s!') % username) redirect('/') else: flash(_('Username %s already registered') % username) redirect('/register') elif password != confirm_password: flash(_('Passwords do not match')) redirect('/register') else: flash(_('Insufficient information')) redirect('/register') return
def logout(self, came_from='/'): if request.identity is not None: username = request.identity['repoze.who.userid'] if 'GUEST-' in username: DBSession = DBSessionmaker() try: u = DBSession.query(User).filter(User.user_name == username).all() except: DBSession.close() redirect('/logout_handler') if len(u) == 0: DBSession.close() redirect('/logout_handler') buds = DBSession.query(Buddies).filter(or_(Buddies.user_initiated == u[0], Buddies.user_target == u[0])).all() msgs = DBSession.query(Message).filter(or_(Message.uto == u[0], Message.ufrom == u[0])).all() try: buds = DBSession.query(Buddies).filter(or_(Buddies.user_initiated == u[0], Buddies.user_target == u[0])).all() msgs = DBSession.query(Message).filter(or_(Message.uto == u[0], Message.ufrom == u[0])).all() except: DBSession.close() redirect('/logout_handler') DBSession.delete(u[0]) for b in buds: DBSession.delete(b) for m in msgs: DBSession.delete(m) DBSession.commit() DBSession.close() redirect('/logout_handler')
def guest(self): DBSession = DBSessionmaker() guests = DBSession.query(User).order_by(User.user_name).all() try: guests = DBSession.query(User).order_by(User.user_name).all() except: DBSession.close() redirect('/') last = -1 for guest in guests: if 'GUEST-' in guest.user_name: tmp = int(guest.user_name.split('GUEST-')[1]) if tmp > last: last = tmp username = '******' + str(last + 1) password = '******' confirm_password = '******' if password == confirm_password and username is not None and password is not None and confirm_password is not None: if DBSession.query(User).filter( User.user_name == username).count() == 0: newuser = User(username, password, 0) normal = DBSession.query(Group).filter( Group.group_name == 'normal').first() newuser.groups = newuser.groups + [normal] DBSession.add(newuser) DBSession.commit() DBSession.close() redirect('/auto_login?username='******'&password='******'Username %s already registered') % username) DBSession.close() redirect('/') elif password != confirm_password: flash(_('Passwords do not match')) DBSession.close() redirect('/') else: flash(_('Insufficient information')) DBSession.close() redirect('/')
def register_handler(self, username=None, password=None, confirm_password=None, y=None, x=None, Submit=None): DBSession = DBSessionmaker() if password == confirm_password and username is not None and password is not None and confirm_password is not None: if DBSession.query(User).filter(User.user_name==username).count() == 0: newuser = User(username, password, 0) normal = DBSession.query(Group).filter(Group.group_name=='normal').first() newuser.groups = newuser.groups + [normal] DBSession.add(newuser) DBSession.commit() flash(_('Successfully Registered, %s!') % username) redirect('/') else: flash(_('Username %s already registered') %username) redirect('/register') elif password != confirm_password: flash(_('Passwords do not match')) redirect('/register') else: flash(_('Insufficient information')) redirect('/register') return
def guest(self): DBSession = DBSessionmaker() guests = DBSession.query(User).order_by(User.user_name).all() try: guests = DBSession.query(User).order_by(User.user_name).all() except: DBSession.close() redirect('/') last = -1 for guest in guests: if 'GUEST-' in guest.user_name: tmp = int(guest.user_name.split('GUEST-')[1]) if tmp > last: last = tmp username = '******' + str(last + 1) password = '******' confirm_password = '******' if password == confirm_password and username is not None and password is not None and confirm_password is not None: if DBSession.query(User).filter(User.user_name==username).count() == 0: newuser = User(username, password, 0) normal = DBSession.query(Group).filter(Group.group_name=='normal').first() newuser.groups = newuser.groups + [normal] DBSession.add(newuser) DBSession.commit() DBSession.close() redirect('/auto_login?username='******'&password='******'Username %s already registered') %username) DBSession.close() redirect('/') elif password != confirm_password: flash(_('Passwords do not match')) DBSession.close() redirect('/') else: flash(_('Insufficient information')) DBSession.close() redirect('/')
def logout(self, came_from='/'): if request.identity is not None: username = request.identity['repoze.who.userid'] if 'GUEST-' in username: DBSession = DBSessionmaker() try: u = DBSession.query(User).filter( User.user_name == username).all() except: DBSession.close() redirect('/logout_handler') if len(u) == 0: DBSession.close() redirect('/logout_handler') buds = DBSession.query(Buddies).filter( or_(Buddies.user_initiated == u[0], Buddies.user_target == u[0])).all() msgs = DBSession.query(Message).filter( or_(Message.uto == u[0], Message.ufrom == u[0])).all() try: buds = DBSession.query(Buddies).filter( or_(Buddies.user_initiated == u[0], Buddies.user_target == u[0])).all() msgs = DBSession.query(Message).filter( or_(Message.uto == u[0], Message.ufrom == u[0])).all() except: DBSession.close() redirect('/logout_handler') DBSession.delete(u[0]) for b in buds: DBSession.delete(b) for m in msgs: DBSession.delete(m) DBSession.commit() DBSession.close() redirect('/logout_handler')