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
        session.close()

    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()

    fields = session.query(EntityProperty)\
        .options(joinedload('reference_book_values'))\
        .order_by(EntityProperty.visible_order)\
        .all()

    app = session.query(Application).one()
    session.close()

    return {
        'u_name': user_name,
        'project': 'ngcrowd',
        'fields': fields,
        'static_version': request.registry.settings['static_version'],
        'app': app
    }
Beispiel #4
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:
        with transaction.manager:
            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)
        info = u'Вы зарегистрированы. Поздравляем!'

    session.close()

    return {'errors': errors, 'info': info}
Beispiel #5
0
def get_logs(context, request):
    session = DBSession()
    user_entities_count_sbq = session \
        .query(EntityVersions.user_id.label('user_id'), func.count(EntityVersions.entity_id.distinct()).label('count_entities')) \
        .group_by(EntityVersions.user_id) \
        .subquery()

    user_entities_logs = session.query(User, user_entities_count_sbq.c.count_entities) \
        .outerjoin(user_entities_count_sbq, User.id == user_entities_count_sbq.c.user_id) \
        .order_by(desc(user_entities_count_sbq.c.count_entities))

    # count_editable_uiks = session.query(func.count(UikVersions.uik_id.distinct())).scalar()
    count_approved_entities = session.query(func.count(Entity.id)).filter(Entity.approved == True).scalar()
    count_all_entities = session.query(func.count(Entity.id)).scalar()
    results = {
        'count': {
            'all': count_all_entities,
            # 'editable': count_editable_uiks,
            'approved': count_approved_entities
        },
        'entities_by_users': []}
    rank = 1
    for user_entities_log in user_entities_logs:
        registered_time = ''
        if user_entities_log[0].registered_time:
            registered_time = user_entities_log[0].registered_time.strftime('%Y-%m-%d %H:%m')
        if user_entities_log[1]:
            results['entities_by_users'].append({
                'user_name': user_entities_log[0].display_name,
                'registered_time': registered_time,
                'count_entities': user_entities_log[1],
                'rank': rank
            })
            rank += 1

    session.close()

    return {
        'results': results
    }
Beispiel #6
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:
        with transaction.manager:
            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)
        info = u'Вы зарегистрированы. Поздравляем!'

    session.close()

    return {
        'errors': errors,
        'info': info
    }
Beispiel #7
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()

    fields = session.query(EntityProperty)\
        .options(joinedload('reference_book_values'))\
        .order_by(EntityProperty.visible_order)\
        .all()

    app = session.query(Application).one()
    session.close()

    return {
        'u_name': user_name,
        'project': 'ngcrowd',
        'fields': fields,
        'static_version': request.registry.settings['static_version'],
        'app': app
    }