示例#1
0
文件: users.py 项目: zefciu/social
    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")
示例#2
0
文件: users.py 项目: zefciu/social
 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)
示例#3
0
文件: auth.py 项目: zefciu/social
 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
示例#4
0
文件: users.py 项目: zefciu/social
    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")
示例#5
0
    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()