Exemplo n.º 1
0
def signup():
    form = SignUpForm(request.form)
    if request.method == "POST":
        if form.validate():
            username = form.username.data
            email = form.email.data
            password = form.password.data
            connection = pymongo.Connection(CONNECTION_STRING,
                                            safe=True)

            message = {"error": None}
            if not user.newuser(connection[DATABASE],
                                username, email, password, message):
                pigeon.error(message["error"])
            else:
                pigeon.success(u"Welcome to Office! Your local gist!")

                # Set cookies to client.
                session_id = user.start_session(connection[DATABASE], username)
                cookie = user.make_secure_val(session_id)
                redirect_to_home = redirect_back("index")
                response = app.make_response(redirect_to_home)
                response.set_cookie(COOKIE, value=cookie)

                # Mark this user has logged in.
                session["logged_in"] = True
                session["username"] = username
                return response

    return render_template("signup.html", form=form, status="signup")
Exemplo n.º 2
0
def signin():
    form = SignInForm(request.form)
    if request.method == "POST":
        if form.validate():
            username = form.username.data
            password = form.password.data
            remember = form.remember.data
            connection = pymongo.Connection(CONNECTION_STRING,
                                            safe=True)
            response = None
            try:
                username = user.validate_login(connection[DATABASE],
                                               username, password)
            except DoesNotExist:
                pigeon.error("You haven't registered yet!")
                response = app.make_response(redirect_back("signup"))
            except UserPasswordNotMatch:
                pigeon.error("Wrong username/password combination!")
                response = app.make_response(render_template("signin.html",
                                                             form=form))
            if not response:
                session_id = user.start_session(connection[DATABASE],
                                                username)
                if session_id == -1:
                    pigeon.error("Internal error!")
                else:
                    cookie = user.make_secure_val(session_id)

                    # Set cookies to client.
                    session_id = user.start_session(connection[DATABASE],
                                                    username)
                    cookie = user.make_secure_val(session_id)
                    redirect_to_home = redirect_back("index")
                    response = app.make_response(redirect_to_home)
                    response.set_cookie(COOKIE, value=cookie)

                    # Mark this user has logged in.
                    session["logged_in"] = True
                    session["username"] = username
                    return response
            else:
                return response

    return render_template("signin.html", form=form, status="signin")
Exemplo n.º 3
0
def index():
    pigeon.info(request, "Hello")
    pigeon.error(request, "Hello")
    pigeon.success(request, "Hello")
    pigeon.warning(request, "HellO")
    return render_template("home.html")