Example #1
0
def check_registration():
    user = User.get(login='******')
    if user is None:
        user = User(login='******', vk_id=1)
        user.save('123456')
    print(user.check_user('123456'))
    print(user.vk_user)
Example #2
0
def match(form, field):
    user = None
    if cur_user():
        user = cur_user()
    elif form.login.data is not '':
        user = User.get(login=form.login.data)
    if user and not user.check_pass(field.data):
        raise ValidationError("Неправильный пароль")
def cabinet(usr, tab=0):
    """
    Отвечает за вывод страницы личного кабинета
    :return: Страница личного кабинета
    """

    video_list = Video.get()
    user = cur_user()
    cabinet_owner = User.get(login=usr)
    is_cabinet_settings_available = False

    if user == cabinet_owner:
        is_cabinet_settings_available = True

    items = cabinet_owner.videos

    form = UserProfileForm()
    form_acc = AccountSettingsForm()
    if request.method == 'POST':
        form_name = request.form['form-name']
        tab = 2
        if form_name == 'form':
            tab = 1
        if form_name == 'form' and form.validate():
            tab = 1
            user = cur_user()
            folder = str(user.id)
            if form.change_name.data:
                user.change_name(form.change_name.data)
            if form.channel_info.data:
                user.change_channel_info(form.channel_info.data)
            if 'avatar' in request.files:
                avatar_url = avatars.save(form.avatar.data, folder=folder)
                user.update_avatar(json.dumps({"url": avatar_url}))
            if 'background' in request.files:
                background_url = backgrounds.save(form.background.data,
                                                  folder=folder)
                user.update_background(json.dumps({"url": background_url}))
            return redirect(
                url_for("cabinet", usr=cabinet_owner.login, tab=tab))
        elif form_name == 'form_acc' and form_acc.validate():
            tab = 2
            user = cur_user()
            if form_acc.change_password.data:
                user.save(form_acc.change_password.data)
            return redirect(
                url_for("cabinet", usr=cabinet_owner.login, tab=tab))
    now = time = datetime.now(tz=None)
    return render_template('user/cabinet.html',
                           form=form,
                           form_acc=form_acc,
                           user=user,
                           items=items,
                           settings=is_cabinet_settings_available,
                           usr=cabinet_owner,
                           subscribed=(user in cabinet_owner.subscribers),
                           now=now,
                           tab=tab)
Example #4
0
def check_information():
    author = User.get(login='******').vk_user

    unexp_inf = Information(
        author_id=author.vk_id,
        text='This is the most valuable information in the world.')
    unexp_inf.save()
    exp_inf = Information(
        author_id=author.vk_id,
        text='This is the most valuable information in the world for now.',
        expiration_time=datetime.utcnow() + timedelta(0, 0, 2))
    exp_inf.save()
Example #5
0
def parse_signed_cookie(cookie_str):
    try:
        L = cookie_str.split('-')
        if len(L) != 3:
            return None
        id, expires, md5 = L
        if int(expires) < time.time():
            return None
        user = User.get(id)
        if user is None:
            return None
        if md5 != hashlib.md5('%s-%s-%s-%s' % (id, user.password, expires, _COOKIE_KEY)).hexdigest():
            return None
        return user
    except:
        return None
def play(vid):
    video = Video.get(video_id=vid)
    if not video:
        abort = Aborter()
        return abort(404)

    user = cur_user()
    usr = User.get(login=video.user.login)

    if user and user not in video.viewers:
        video.add_viewer(user)

    likened = 0
    if user in video.likes:
        likened = 1
    if user in video.dislikes:
        likened = -1
    return render_template('video_page.html',
                           user=user,
                           vid=vid,
                           video=video,
                           lkd=likened,
                           usr=usr,
                           subscribed=(user in usr.subscribers))
Example #7
0
def not_exist(form, field):
    if User.get(login=field.data) is None:
        raise ValidationError("Такого пользователя не существует")
Example #8
0
def exist(form, field):
    if User.get(login=field.data):
        raise ValidationError("Такой пользователь уже существует")
Example #9
0
def cur_user():
    if 'Login' in session:
        return User.get(login=session['Login'])
    return None
Example #10
0
 def test_is_get_method_work(self):
     self.assertEqual(User.get(self.user.id), self.user)
Example #11
0
def check_auth_password(form, field):
    user = User.get(login=form.login.data)
    if user is None:
        pass
    elif not user.check_user(field.data):
        raise ValidationError('Неправильный пароль')
Example #12
0
def check_auth_login(form, field):
    user = User.get(login=field.data)
    if user is None:
        raise StopValidation('Неизвестный логин.')
Example #13
0
def validate_login_is_uniq(form, field):
    user = User.get(login=field.data)
    if user is not None:
        raise ValidationError('Пользователь с таким логином уже существует.')
Example #14
0
def validate_vk_id_is_uniq(form, field):
    vk_id = get_numeric_id(field.data)
    if User.get(vk_id=vk_id) is not None:
        raise ValidationError('Пользователь с таким ID уже зарегистрирован.')