def befriend(self, login): try: requester = Session.query(User).filter(User.login == request.environ["REMOTE_USER"]).one() except (NoResultFound, KeyError): abort(401) try: acceptor = Session.query(User).filter(User.login == login).one() except NoResultFound: abort(404) # Check if this side already requested friendship try: existing = ( Session.query(Friendship) .filter((Friendship.requester_id == requester.id) & (Friendship.acceptor_id == acceptor.id)) .one() ) except NoResultFound: pass else: if existing.accepted: c.message = u"Już jesteś przyjacielem tego użytkownika" else: c.message = u"Już wysłałeś zaproszenie do tego użytkownika. Poczekaj na akceptację" return render("users/request_done.mako") # Check if the other side already requested friendship try: existing = ( Session.query(Friendship) .filter((Friendship.requester_id == acceptor.id) & (Friendship.acceptor_id == requester.id)) .one() ) except NoResultFound: friendship = Friendship(requester_id=requester.id, acceptor_id=acceptor.id) Session.add(friendship) Session.commit() c.message = u"Wysłano zaproszenie do użytkownika %s." % acceptor.login else: if existing.accepted: c.message = u"Już jesteś przyjacielem tego użytkownika" else: existing.accepted = True Session.commit() c.message = u"Zostałeś przyjacielem użytkownika %s." % acceptor.login return render("users/request_done.mako")
def validate_python(self, value, state): if len(value) > 32: raise fe.Invalid(self.message("too_many", state), value, state) if len(value) < 3: raise fe.Invalid(self.message("too_few", state), value, state) if Session.query(User).filter(User.login == value).count(): raise fe.Invalid(self.message("taken", state), value, state)
def authenticate(self, environ, identity): if identity.has_key('login'): try: user = Session.query(User).filter( User.login == identity['login'] ).one() except NoResultFound: return if user.check_passwd(identity['passwd']): return user.login
def display(self, login): try: user = Session.query(User).filter(User.login == login).one() except NoResultFound: abort(404) c.login = user.login if is_friend(user.login).is_met(request.environ): return render("/users/display_full.mako") else: return render("users/suggest_friend.mako")
def evaluate(self, environ, credentials): print credentials, self.username if credentials['repoze.what.userid'] == self.username: return # It's always ok to view your own data try: user = Session.query(User).filter( User.login == credentials['repoze.what.userid'] ).one() except NoResultFound: self.unmet() if self.username in [u.login for u in user.friends]: return if self.username in [u.login for u in user.back_friends]: return self.unmet()