Ejemplo n.º 1
0
def login():
    # todo redirect to the page request login
    session["return_url"] = request.args.get("return_url")
    return render("/login.html",
                  error=None,
                  providers=safe_get_config("login.provider_enabled",
                                            ["github", "qq", "gitcafe", "weibo", "live", "alauda"]))
Ejemplo n.º 2
0
def login():
    session["return_url"] = request.args.get("return_url")
    provider = request.args.get("provides")
    prs = ["github", "qq", "gitcafe", "weibo", "live", "alauda"]
    if provider is None:
        provider = safe_get_config("login.provider_enabled", prs)
    else:
        provider = provider.split(",")
    return render("/login.html", error=None, providers=provider)
Ejemplo n.º 3
0
def login():
    session["return_url"] = request.args.get("return_url")
    provider = request.args.get("provides")
    prs = ["github", "qq", "wechat", "weibo", "live", "alauda"]
    if provider is None:
        provider = safe_get_config("login.provider_enabled", prs)
    else:
        provider = provider.split(',')
    return render("/login.html", error=None, providers=provider)
Ejemplo n.º 4
0
 def __generate_api_token(self, admin):
     token_issue_date = get_now()
     token_expire_date = token_issue_date + timedelta(
         minutes=safe_get_config("login/token_expiration_minutes", 1440))
     user_token = UserToken(token=str(uuid.uuid1()),
                            user=admin,
                            expire_date=token_expire_date,
                            issue_date=token_issue_date)
     self.db.add_object(user_token)
     return user_token
Ejemplo n.º 5
0
 def __generate_api_token(self, admin):
     token_issue_date = get_now()
     token_expire_date = token_issue_date + timedelta(
         minutes=safe_get_config("login/token_expiration_minutes", 1440))
     user_token = UserToken(token=str(uuid.uuid1()),
                            user=admin,
                            expire_date=token_expire_date,
                            issue_date=token_issue_date)
     self.db.add_object(user_token)
     return user_token
Ejemplo n.º 6
0
def __get_uri(path):
    if path.startswith("/"):
        path = path.lstrip("/")
    return "%s/%s" % (safe_get_config('endpoint.hackathon_api',
                                      'http://localhost:15000'), path)
Ejemplo n.º 7
0
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# -----------------------------------------------------------------------------------

import sys

sys.path.append("..")
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from db_adapters import SQLAlchemyAdapter
from client.functions import safe_get_config

MYSQL_CONNECTION = 'mysql.connection'
DEFAULT_URL = 'mysql://*****:*****@localhost/hackathon'

engine = create_engine(safe_get_config(MYSQL_CONNECTION, DEFAULT_URL),
                       convert_unicode=True,
                       pool_size=50,
                       max_overflow=100,
                       echo=False)
db_session = scoped_session(
    sessionmaker(autocommit=False, autoflush=False, bind=engine))
Base = declarative_base()
Base.query = db_session.query_property()
db_adapter = SQLAlchemyAdapter(db_session)
Ejemplo n.º 8
0
def unauthorized_log():
    return render(
        "/login.html",
        error=None,
        providers=safe_get_config("login.provider_enabled", ["github", "qq", "gitcafe", "weibo", "live", "alauda"]),
    )
Ejemplo n.º 9
0
def make_session_permanent():
    g.user = current_user
    session.permanent = True
    app.permanent_session_lifetime = timedelta(minutes=safe_get_config("login.session_valid_time_minutes", 60))
Ejemplo n.º 10
0
def make_session_permanent():
    g.user = current_user
    session.permanent = True
    app.permanent_session_lifetime = timedelta(
        minutes=safe_get_config("login.session_valid_time_minutes", 60))
Ejemplo n.º 11
0
def unauthorized_log():
    return render("/login.html",
                  error=None,
                  providers=safe_get_config(
                      "login.provider_enabled",
                      ["github", "qq", "wechat", "weibo", "live", "alauda"]))
Ejemplo n.º 12
0

import sys

sys.path.append("..")
from sqlalchemy import create_engine, exc, event, select
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base

from db_adapters import SQLAlchemyAdapter
from client.functions import safe_get_config

MYSQL_CONNECTION = 'mysql.connection'
DEFAULT_URL = 'mysql://*****:*****@localhost/hackathon'

engine = create_engine(safe_get_config(MYSQL_CONNECTION, DEFAULT_URL),
                       convert_unicode=True,
                       pool_size=50,
                       pool_recycle=3600,
                       max_overflow=100,
                       echo=False)


@event.listens_for(engine, "engine_connect")
def ping_connection(connection, branch):
    if branch:
        # "branch" refers to a sub-connection of a connection,
        # we don't want to bother pinging on these.
        return

    try:
Ejemplo n.º 13
0
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# -----------------------------------------------------------------------------------


import sys

sys.path.append("..")
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from db_adapters import SQLAlchemyAdapter
from client.functions import safe_get_config

MYSQL_CONNECTION = "mysql.connection"
DEFAULT_URL = "mysql://*****:*****@localhost/hackathon"

engine = create_engine(
    safe_get_config(MYSQL_CONNECTION, DEFAULT_URL), convert_unicode=True, pool_size=50, max_overflow=100, echo=False
)
db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine))
Base = declarative_base()
Base.query = db_session.query_property()
db_adapter = SQLAlchemyAdapter(db_session)
Ejemplo n.º 14
0
# -*- coding: utf-8 -*-
"""
This file is covered by the LICENSING file in the root of this project.
"""

from flask import Flask
from flask_debugtoolbar import DebugToolbarExtension

from client.functions import safe_get_config

# flask
app = Flask(__name__)

app.config['SECRET_KEY'] = safe_get_config("app.secret_key", "secret_key")

app.config['DEBUG_TB_ENABLED'] = False
toolbar = DebugToolbarExtension(app)


class Context(object):
    """Helper class for JSON. We can access dict similarly as literal in JS

    Essentially a collection of parameters that will be passed through threads/databases
    NEVER put complex object in Context such as instance of db models or business manager

    ::Example:
        dic = {"a": "va", "b": {"b1": "b1", "b2": [1, 2, 3], "b3": [{"b3a": "b3a"}]}}
        c = Context.from_object(dic) # convert existing obj to Context

        print c.a
        print c["a"] # exactly the same as c.a. But it allows you pass values to key