Example #1
0
def view_frontend(path=None):
    return render_template('index.html',
        page_attributes=u' '.join(page_attributes() + ['issue-tracker-app']),
        user=current_user.to_dict() if is_logged_in() else None,
        current_user=jsonify(current_user.to_dict() if is_logged_in() else None),
        anonymous_gravatar=gravatar(''),
        issues=jsonify([create_issue_read_dict(issue, last_read) for (issue,last_read) in uncompleted_issues()]),
        labels=jsonify([label.to_dict() for label in labels()]))
Example #2
0
def view_frontend(path=None):
    return render_template(
        'index.html',
        page_attributes=u' '.join(page_attributes() + ['issue-tracker-app']),
        user=current_user.to_dict() if is_logged_in() else None,
        current_user=jsonify(
            current_user.to_dict() if is_logged_in() else None),
        anonymous_gravatar=gravatar(''),
        issues=jsonify([issue.to_dict() for issue in uncompleted_issues()]),
        labels=jsonify([label.to_dict() for label in labels()]))
Example #3
0
def user():
    result = {
        'response': 'ok',
        'customer': '',
        'customer_discount': '',
        'info': ''
    }
    try:
        if current_user.is_authenticated():
            with get_session() as db_session:
                user_discount = db_session.query(CustomerDiscount).filter(
                    CustomerDiscount.customer_id == current_user.id).first()
                if user_discount:
                    discount = db_session.query(Discount).get(
                        user_discount.discount_id)
                    if discount:
                        customer_discount_dict = user_discount.to_dict()
                        customer_discount_dict['discount_name'] = discount.name
                        result.update(
                            {'customer_discount': customer_discount_dict})
                customer_dict = current_user.to_dict()
                result.update({'customer': customer_dict})
        return jsonify(result)
    except Exception as e:
        print e
 def get(self):
     try:
         dict = current_user.to_dict()
         return {"logged": dict}
         # return {"logged": current_user.to_dict()}
     except AttributeError:
         return {'logged': None}
Example #5
0
def sync_github():
    """Sync the current session User with GitHub."""
    from kaput.auth.user import sync_github_user

    sync_github_user(current_user)

    return json.dumps(current_user.to_dict(), cls=EntityEncoder), 200
Example #6
0
def index():
    if current_user.is_anonymous:
        return redirect(url_for('login'))

    return render_template('index.jade', bootstrap=json.dumps({
        'current_user': current_user.to_dict()
    }))
Example #7
0
def me():
    res = ajax_response()

    user_dict = current_user.to_dict() if current_user.is_authenticated(
    ) else {}
    user_dict.update(self_home=False)

    res.update(data={'user': user_dict})
    return jsonify(res)
Example #8
0
def update_user():
    """Update the current session User."""

    user_data = json.loads(request.data)

    current_user.update(user_data)
    current_user.put()

    return json.dumps(current_user.to_dict(), cls=EntityEncoder), 200
Example #9
0
def index():
    site_url = current_app.config['SITE_URL']
    user_info = current_user.to_dict()
    user_info = json.dumps(user_info)
    menus = g.user.get_menus()
    menus = json.dumps(menus)
    return render_template('index.html',
                           site_url=site_url,
                           user_info=user_info,
                           menus=menus)
Example #10
0
def me():
    res = ajax_response()

    user_dict = current_user.to_dict() if current_user.is_authenticated() else {}
    user_dict.update(self_home=False)

    res.update(data={
        'user': user_dict
    })
    return jsonify(res)
def status():
    """Get the login status of the current user session.
    Return: status dictionary"""
    app.logger.debug("status current_user is '%s'" % (str(current_user)))
    if session.get('logged_in'):
        if session['logged_in']:
            return jsonify({
                'status': True,
                'a': current_user.admin,
                'user': current_user.to_dict()
            })
    else:
        return jsonify({'status': False, 'a': False, 'user': None})
Example #12
0
def get_cur_user():
    result = {'response': 'ok', 'user': ''}
    try:
        if current_user.is_authenticated():
            user = current_user.to_dict()
            result.update({'response': 'active', 'user': user})
        else:
            result.update({
                'response': 'needLogin',
            })
        return jsonify(result)
    except Exception as e:
        print e
        abort(400)
Example #13
0
def make_admin(user_id):
    form = ConfirmPasswordForm()
    user = User.query.filter_by(id=user_id).first_or_404()
    if form.validate_on_submit():
        if current_user.check_password(form.password.data):
            user.admin = not user.admin
            db.session.commit()
            return redirect(url_for('view_frontend'))
        else: 
            form.password.errors.append('Wrong password')
    return render_template('confirm.html',
        user=current_user.to_dict() if is_logged_in() else None, 
        form=form,
        title='Change Admin Status',
        target=url_for('make_admin', user_id=user_id))
Example #14
0
def make_admin(user_id):
    form = ConfirmPasswordForm()
    user = User.query.filter_by(id=user_id).first_or_404()
    if form.validate_on_submit():
        if current_user.check_password(form.password.data):
            user.admin = not user.admin
            db.session.commit()
            return redirect(url_for('view_frontend'))
        else:
            form.password.errors.append('Wrong password')
    return render_template(
        'confirm.html',
        user=current_user.to_dict() if is_logged_in() else None,
        form=form,
        title='Change Admin Status',
        target=url_for('make_admin', user_id=user_id))
Example #15
0
def header_info():
    result = {
        'response': 'ok',
        'user': {},
        'website_url': ''
    }
    try:
        if current_user.is_authenticated():
            # 模块url
            module_list = config.MODULES
            user_dict = current_user.to_dict()
            result['module_list'] = module_list
            result['user'] = user_dict
            result['website_url'] = config.WEBSITE_URL
        return jsonify(result)
    except Exception as e:
        app.my_logger.error(traceback.format_exc(e))
        abort(400)
def get_current_user():
    person = organisations_service_proxy.get_person(
        current_user.person_id,
        auth_token_username=current_user.user_id
    )

    person["person_uri"] = person["uri"]
    user = current_user.to_dict()
    person.update(user)
    person["name"] = "n/a"

    first_name = person.get("first_name", None)
    last_name = person.get("last_name", None)

    if first_name and last_name:
        person["name"] = "%s %s" % (first_name, last_name)

    return person
Example #17
0
def change_password(user_id=None):
    form = ChangePasswordForm()
    if user_id is not None and not is_admin():
        return 'You are not authorised', 403
    if user_id is None:
        user_id = current_user.get_id()
    user = User.query.filter_by(id=user_id).first_or_404()
    if form.validate_on_submit():
        if current_user.check_password(form.current_password.data):
            user.set_password(form.new_password.data)
            db.session.commit()
            return redirect(url_for('view_frontend'))
        else: 
            form.current_password.errors.append('Wrong password')
    return render_template('user_change_password.html',
        form=form,
        user=current_user.to_dict() if is_logged_in() else None,
        user_id=user_id)
Example #18
0
def change_password(user_id=None):
    form = ChangePasswordForm()
    if user_id is not None and not is_admin():
        return 'You are not authorised', 403
    if user_id is None:
        user_id = current_user.get_id()
    user = User.query.filter_by(id=user_id).first_or_404()
    if form.validate_on_submit():
        if current_user.check_password(form.current_password.data):
            user.set_password(form.new_password.data)
            db.session.commit()
            return redirect(url_for('view_frontend'))
        else:
            form.current_password.errors.append('Wrong password')
    return render_template(
        'user_change_password.html',
        form=form,
        user=current_user.to_dict() if is_logged_in() else None,
        user_id=user_id)
def get_current_person():
    if current_user.authentication_type == 'id_porten':
        person = organisations_service_proxy.get_person(
            current_user.person_id,
            auth_token_username=current_user.user_id
        )

        person["person_uri"] = person["uri"]
        user = current_user.to_dict()
        person.update(user)
        person["name"] = "n/a"

        first_name = person.get("first_name", None)
        last_name = person.get("last_name", None)

        if first_name and last_name:
            person["name"] = "%s %s" % (first_name, last_name)

    else:
        person = {'person_uri': '', 'name': 'n/a'}

    return person
Example #20
0
def index():
    site_url = current_app.config['SITE_URL']
    user_info = current_user.to_dict()
    user_info = json.dumps(user_info)
    menus = g.user.get_menus()
    menus = json.dumps(menus)

    subjects = get_subjects()
    qtypes = QType.query.all()
    qtypes = [{
        'id': t.id,
        'subject_id': t.subject_id,
        'text': t.name
    } for t in qtypes]
    qtypes = json.dumps(qtypes)

    return render_template('index.html',
                           site_url=site_url,
                           user_info=user_info,
                           menus=menus,
                           subjects=subjects,
                           qtypes=qtypes)
def update_my_password():
    """Update the user's password associated with the given user_id
    From Data: email (str), admin (bool), password (str), active (bool)
    Return: user dictionary"""

    old_password = request.json.get("old_password", None)
    new_password1 = request.json.get("new_password1", None)
    new_password2 = request.json.get("new_password2", None)

    if not old_password or not new_password1 or not new_password2:
        abort(404)

    if not bcrypt.check_password_hash(current_user.password, old_password):
        abort(401)

    if not new_password1 == new_password2:
        abort(400, description="New passwords not identical.")

    current_user.password = bcrypt.generate_password_hash(new_password1)
    db.session.add(current_user)
    db.session.commit()

    return jsonify(current_user.to_dict()), 200
Example #22
0
def get_user_from_auth():
    return current_user.to_dict()
Example #23
0
 def get(self):
     if current_user.is_authenticated():
         return current_user.to_dict(),200
     return  'Login Required',401
Example #24
0
def list_users():
    users = User.query.all()
    return render_template('users.html',
        user=current_user.to_dict() if is_logged_in() else None, 
        users=users)
Example #25
0
def index():
    u = current_user.to_dict() if current_user.is_authenticated() else None
    return render_template('index.html', user=json.dumps(u, cls=EntityEncoder))
Example #26
0
def list_users():
    users = User.query.all()
    return render_template(
        'users.html',
        user=current_user.to_dict() if is_logged_in() else None,
        users=users)
Example #27
0
def get_current_user():
    if current_user and hasattr(current_user, 'company_name'):
        return jsonify(current_user.to_dict())
    return ''
Example #28
0
def current_user_view():
    res = current_user.to_dict()
    return jsonify(res);
Example #29
0
 def get(self):
     if current_user.is_authenticated():
         return current_user.to_dict(), 200
     return 'Login Required', 401
Example #30
0
def get_user():
    """Get the current session User."""

    return json.dumps(current_user.to_dict(), cls=EntityEncoder), 200