Beispiel #1
0
def home_signin(request):
    result = home(request)

    if "sign_out" in request.POST.keys():
        request.session.invalidate()
        result["u_name"] = None

    else:
        email = request.POST["mail"]
        password = request.POST["pass"]

        session = DBSession()
        user = (
            session.query(User)
            .filter(User.email == email, User.password == User.password_hash(password, "rte45EWRRT"))
            .first()
        )
        if user:
            request.session["sk"] = generate_session_id()
            request.session["u_name"] = user.display_name
            request.session["u_id"] = user.id
            request.response.set_cookie("sk", value=request.session["sk"], max_age=86400)
            result["u_name"] = user.display_name
        session.close()

    result["static_version"] = request.registry.settings["static_version"]

    return result
Beispiel #2
0
def home_signin(request):
    result = home(request)

    if 'sign_out' in request.POST.keys():
        request.session.invalidate()
        result['u_name'] = None

    else:
        email = request.POST['mail']
        password = request.POST['pass']
        session = DBSession()
        user = session.query(User) \
            .filter(User.email == email, User.password == User.password_hash(password, 'rte45EWRRT')) \
            .first()
        if user:
            request.session['sk'] = generate_session_id()
            request.session['u_name'] = user.display_name
            request.session['u_id'] = user.id
            request.response.set_cookie('sk',
                                        value=request.session['sk'],
                                        max_age=86400)
            result['u_name'] = user.display_name

    result['static_version'] = request.registry.settings['static_version']

    return result
Beispiel #3
0
def home(request):
    user_name = None
    if hasattr(request, 'cookies') and 'sk' in request.cookies.keys() and 'sk' in request.session and \
                    request.session['sk'] == request.cookies['sk'] and 'u_name' in request.session:
        user_name = request.session['u_name']

    session = DBSession()
    geocoding_precisions = session.query(GeocodingPrecision).order_by(asc(GeocodingPrecision.id)).all()

    return {
        'u_name': user_name,
        'project': 'uik_ru',
        'geocoding_precisions': geocoding_precisions,
        'static_version': request.registry.settings['static_version']
    }
Beispiel #4
0
def home(request):
    user_name = None
    if hasattr(request, 'cookies') and 'sk' in request.cookies.keys() and 'sk' in request.session and \
                    request.session['sk'] == request.cookies['sk'] and 'u_name' in request.session:
        user_name = request.session['u_name']

    session = DBSession()
    geocoding_precisions = session.query(GeocodingPrecision).order_by(
        asc(GeocodingPrecision.id)).all()

    return {
        'u_name': user_name,
        'project': 'uik_ru',
        'geocoding_precisions': geocoding_precisions,
        'static_version': request.registry.settings['static_version']
    }
Beispiel #5
0
def register_post(request):
    session = DBSession()
    errors = []
    info = ''

    if not request.POST['name']:
        errors.append(u'Вы не указали ваше имя')

    if request.POST['email']:
        import re
        if not re.match(r"[^@]+@[^@]+\.[^@]+", request.POST['email']):
            errors.append(
                u'Неправильный формат адреса электронной почты - адрес должен иметь вид [email protected]'
            )
        existed_email = session.query(
            User.email).filter(User.email == request.POST['email']).count()
        if existed_email > 0:
            errors.append(
                u'Пользователь с таким адресом электронной почты (%s) уже существует'
                % request.POST['email'])
    else:
        errors.append(u'Вы не указали адрес вашей электронной почты')

    if 'password' in request.POST.keys() or request.POST['pass']:
        if not request.POST[
                'pass2'] or request.POST['pass'] != request.POST['pass2']:
            errors.append(u'Введенные вами пароли не совпадают')
        if len(request.POST['pass']) < 5:
            errors.append(u'Длина пароля должна быть больше 4 символов')
    else:
        errors.append(u'Вы не указали пароль')

    if not errors:
        user = User()
        user.display_name = request.POST['name']
        user.email = request.POST['email']
        user.password = User.password_hash(request.POST['pass'], 'rte45EWRRT')
        user.registered_time = datetime.datetime.now()
        session.add(user)
        transaction.commit()
        info = u'Вы зарегистрированы. Поздравляем!'
    return {'errors': errors, 'info': info}
Beispiel #6
0
def home(request):
    user_name = None
    if (
        hasattr(request, "cookies")
        and "sk" in request.cookies.keys()
        and "sk" in request.session
        and request.session["sk"] == request.cookies["sk"]
        and "u_name" in request.session
    ):
        user_name = request.session["u_name"]

    session = DBSession()
    geocoding_precisions = session.query(GeocodingPrecision).order_by(asc(GeocodingPrecision.id)).all()
    session.close()

    return {
        "u_name": user_name,
        "project": "uik_ru",
        "geocoding_precisions": geocoding_precisions,
        "static_version": request.registry.settings["static_version"],
    }
Beispiel #7
0
def register_post(request):
    session = DBSession()
    errors = []
    info = ''

    if not request.POST['name']:
        errors.append(u'Вы не указали ваше имя')

    if request.POST['email']:
        import re
        if not re.match(r"[^@]+@[^@]+\.[^@]+", request.POST['email']):
            errors.append(u'Неправильный формат адреса электронной почты - адрес должен иметь вид [email protected]')
        existed_email = session.query(User.email).filter(User.email == request.POST['email']).count()
        if existed_email > 0:
            errors.append(u'Пользователь с таким адресом электронной почты (%s) уже существует' % request.POST['email'])
    else:
        errors.append(u'Вы не указали адрес вашей электронной почты')

    if 'password' in request.POST.keys() or request.POST['pass']:
        if not request.POST['pass2'] or request.POST['pass'] != request.POST['pass2']:
            errors.append(u'Введенные вами пароли не совпадают')
        if len(request.POST['pass']) < 5:
            errors.append(u'Длина пароля должна быть больше 4 символов')
    else:
        errors.append(u'Вы не указали пароль')

    if not errors:
        user = User()
        user.display_name = request.POST['name']
        user.email = request.POST['email']
        user.password = User.password_hash(request.POST['pass'], 'rte45EWRRT')
        user.registered_time = datetime.datetime.now()
        session.add(user)
        transaction.commit()
        info = u'Вы зарегистрированы. Поздравляем!'
    return {
        'errors': errors,
        'info': info
    }
Beispiel #8
0
def home_signin(request):
    result = home(request)

    if 'sign_out' in request.POST.keys():
        request.session.invalidate()
        result['u_name'] = None

    else:
        email = request.POST['mail']
        password = request.POST['pass']
        session = DBSession()
        user = session.query(User) \
            .filter(User.email == email, User.password == User.password_hash(password, 'rte45EWRRT')) \
            .first()
        if user:
            request.session['sk'] = generate_session_id()
            request.session['u_name'] = user.display_name
            request.session['u_id'] = user.id
            request.response.set_cookie('sk', value=request.session['sk'], max_age=86400)
            result['u_name'] = user.display_name

    result['static_version'] = request.registry.settings['static_version']

    return result
Beispiel #9
0
parser.add_option("--d", dest="database")
parser.add_option("--h", dest="host")
parser.add_option("--u", dest="user")
parser.add_option("--p", dest="password")
parser.add_option("--s", dest="shp_file")
parser.add_option("--tik", dest="csv_file_tik")
parser.add_option("--reg", dest="csv_file_reg")
parser.add_option("--config", dest="config_file")

(options, args) = parser.parse_args()

# Read SQLAlchemy config:
# ----------------------------------------
config_uri = options.config_file
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)

# !!!
# Next 2 lines kill all data! Delete them from final version!!!:
# ----------------------------------------
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)

print file2model.addToGeocodingPrecision(session=DBSession())

print file2model.addToRegion(options.csv_file_reg, session=DBSession())
print file2model.addToTik(options.csv_file_tik,    session=DBSession())
print file2model.addToUik(options.shp_file,        session=DBSession())

Beispiel #10
0
uik_parser = subparsers.add_parser('uik')
uik_parser.add_argument('--region',
                        dest='region',
                        type=int,
                        help='code of region (ex. 77 for Moscow)')
uik_parser.add_argument('--sqlt',
                        dest='sqlite',
                        help='path to sqlite database file')
uik_parser.add_argument('--conf',
                        dest='sql_config',
                        help='path to sqlalchemy config')

args = parser.parse_args()

# Read SQLAlchemy config:
# ----------------------------------------

if args.sql_config:
    config_uri = args.sql_config
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
else:
    raise 'sql_config parameter (--conf) is required'

if 'csv' in args:
    import tik2model
    tik2model.addToTik(args.csv, session=DBSession())
elif 'sqlite' in args:
    import uik2model
    uik2model.addToUik(args.sqlite, session=DBSession(), regionID=args.region)