Example #1
0
    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")
Example #2
0
    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")
Example #3
0
 def register(self):
     if hasattr(self, "form_result"):
         user = User(self.form_result["login"], self.form_result["passwd"])
         Session.add(user)
         Session.commit()
         redirect("/")
     else:
         return render("/users/register.mako")
Example #4
0
    def login(self):
        c.message = ""
        who_api = get_api(request.environ)
        if "login" in request.POST:
            authenticated, headers = who_api.login({"login": request.POST["login"], "passwd": request.POST["passwd"]})
            if authenticated:
                response.headers = headers
                return redirect("/")
            c.message = "Zły login lub hasło"
        else:
            # Forcefully forget any existing credentials.
            authenticated, headers = who_api.login({})

        if "REMOTE_USER" in request.environ:
            del request.environ["REMOTE_USER"]

        return render("/users/login.mako")
Example #5
0
 def welcome(self):
     if not request.environ.has_key("REMOTE_USER"):
         abort(401)
     else:
         c.username = request.environ["REMOTE_USER"]
         return render("/users/welcome.mako")