Beispiel #1
0
    def test_get_by_id(self):
        """Get user by ID."""
        user = User('foo', '*****@*****.**')
        user.save()

        retrieved = User.get_by_id(user.id)
        assert retrieved == user
Beispiel #2
0
def register():
    """Register new user."""
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        user = User.create(username=form.username.data,
                           email=form.email.data,
                           password=form.password.data,
                           active=True)
        pers_tag = Tags.create(name='Personnel',
                               parent_id=None,
                               user_id=user.id,
                               rank=1)
        Tags.create(name='Environnement',
                    parent_id=None,
                    user_id=user.id,
                    rank=1)
        for cat in [
                'Vie sociale', 'Vie familiale', 'Vie professionnelle', 'Santé',
                'Développement personnel', 'Vie sentimentale', 'Loisirs',
                'Argent'
        ]:
            Tags.create(name=cat,
                        parent_id=pers_tag.id,
                        user_id=user.id,
                        rank=2)
        flash('Thank you for registering. You can now log in.', 'success')
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_template('public/register.html', form=form)
Beispiel #3
0
def user_action_done(user_action_id):
    user_action = UserAction.get_by_id(user_action_id)
    if user_action is None:
        return '{}', 404
    user_action = user_action.realised()

    user_inst = User.get_by_id(user_action.user_id)
    if user_inst is None:
        return '{}', 404
    user_inst.points += 1
    user_inst.save()
    return UserAction.to_json(user_action)
Beispiel #4
0
def like(action_id):
    user = User.find(current_user.id)
    action_inst = Action.get_by_id(action_id)
    if user is None or action_inst is None:
        return jsonify({}), 404
    user.update({'like_date': dt.datetime.now().isoformat()})
    user.pop('password')
    user_as_str = json.dumps(user)
    db.engine.execute(
        text(
            'begin transaction;'
            'update actions set '
            'user_likes = COALESCE(user_likes, \'[]\'::jsonb) || (:user_like)::jsonb where actions.id = :action_id;'
            'end transaction; commit;',
        ),
        **{'user_like': user_as_str, 'action_id': action_id}
    )
    return '{}', 200
Beispiel #5
0
def get_participants_for_action(action_id):
    """get participants of action"""
    page = request.args.get('page', 1)
    per_page = request.args.get('per_page', 20)

    if Action.get_by_id(action_id) is None:
        return '{\"message\": not found}', 404

    total_count = (db.session.query(func.count(User.id))
                   .join(UserAction)
                   .filter(UserAction.action_id == action_id)
                   .scalar())
    result = (User.query
              .join(UserAction)
              .join(Action)
              .filter(UserAction.action_id == action_id).all())

    # response = query.paginate() # paginate(query, page, total_count, User)
    # logging.DEBUG('participants for action send response: \n' + str(response))
    return User.arr_to_json(result, exclude=set('password')), 200
Beispiel #6
0
 def test_check_password(self):
     """Check password."""
     user = User.create(username='******', email='*****@*****.**',
                        password='******')
     assert user.check_password('foobarbaz123') is True
     assert user.check_password('barfoobaz') is False
Beispiel #7
0
 def test_password_is_nullable(self):
     """Test null password."""
     user = User(username='******', email='*****@*****.**')
     user.save()
     assert user.password is None
Beispiel #8
0
 def test_created_at_defaults_to_datetime(self):
     """Test creation date."""
     user = User(username='******', email='*****@*****.**')
     user.save()
     assert bool(user.created_at)
     assert isinstance(user.created_at, dt.datetime)
Beispiel #9
0
def load_user(user_id):
    return User.get_by_id(int(user_id))