コード例 #1
0
ファイル: routes.py プロジェクト: pavelsaman/Skills
def delete_account():
    user_to_be_deleted = current_user.social_id
    if current_user.email is not None:
        send_bye_email(current_user.email)
    logout_user()
    User.delete_user_account(user_to_be_deleted)
    flash(ErrorMessages.USER_DELETION)
    return redirect(url_for('main.index'))
コード例 #2
0
def get_skill_by_id(skill_id):
    response = User.check_token(request)
    if response == 200:
        return jsonify(
            Skill.query.filter_by(
                id_skill=skill_id).first_or_404().to_dict('id'))
    return error_response(response)
コード例 #3
0
def get_skill_by_name(skill_name):
    response = User.check_token(request)
    if response == 200:
        return jsonify(
            Skill.query.filter_by(
                skill_name=skill_name).first_or_404().to_dict('name'))
    return error_response(response)
コード例 #4
0
def get_category_by_id(category_id):
    response = User.check_token(request)
    if response == 200:
        return jsonify(
            Category.query.filter_by(
                id_skill_cat=category_id).first_or_404().to_dict('id'))
    return error_response(response)
コード例 #5
0
def get_category_by_name(category_name):
    response = User.check_token(request)
    if response == 200:
        return jsonify(
            Category.query.filter_by(
                category_name=category_name).first_or_404().to_dict('name'))
    return error_response(response)
コード例 #6
0
def delete_category_by_name(category_name):
    response = User.check_token(request)
    if response == 200 \
            and User.query.filter_by(token=request.headers.get('Authorization')).first().email == Config.ADMIN_EMAIL:
        if Category.delete_category(category_name):
            response = jsonify(Config.API_DELETION_SUCCESS)
            response.status_code = 200
            return response
        else:
            return bad_request(ErrorMessages.API_DELETE_CATEGORY_FAILURE)
    return error_response(response if response != 200 else 401)
コード例 #7
0
def delete_skill_by_id(skill_id):
    response = User.check_token(request)
    if response == 200 \
            and User.query.filter_by(token=request.headers.get('Authorization')).first().email == Config.ADMIN_EMAIL:
        skill_to_be_deleted = Skill.query.filter_by(id_skill=skill_id).first()
        if skill_to_be_deleted is None:
            return bad_request(ErrorMessages.API_DELETE_SKILL_FAILURE)
        if Skill.delete_skill(skill_to_be_deleted.skill_name):
            response = jsonify(Config.API_DELETION_SUCCESS)
            response.status_code = 200
            return response
        else:
            return bad_request(ErrorMessages.API_DELETE_SKILL_FAILURE)
    return error_response(response if response != 200 else 401)
コード例 #8
0
ファイル: routes.py プロジェクト: pavelsaman/Skills
def oauth_callback(provider):
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    oauth = OAuthSignIn.get_provider(provider)
    social_media, social_id, first_name, last_name, username, email, preferred_language = oauth.callback()
    if (social_id is None and social_media == 'facebook') or (last_name is None and social_media == 'linkedin'):
        flash(ErrorMessages.UNSUCCESSFUL_AUTHORIZATION)
        return redirect(url_for('main.index'))
    user = User.query.filter_by(social_id=social_id).first()
    if not user:
        if not User.insert_new_user(social_media, social_id, first_name, last_name, username, email,
                                    preferred_language):
            flash(ErrorMessages.UNSUCCESSFUL_NEW_USER)
            return redirect(url_for('main.index'))
        user = User.query.filter_by(social_id=social_id).first()
    login_user(user, True)
    user.update_visits()
    if user.email is not None and user.first_name is not None and not user.get_welcome_email_sent():
        send_welcome_email(user.first_name, user.email)
        user.set_welcome_email_sent(True)
    return redirect(url_for('content.index'))
コード例 #9
0
def create_category():
    response = User.check_token(request)
    if response == 200 \
            and User.query.filter_by(token=request.headers.get('Authorization')).first().email == Config.ADMIN_EMAIL:
        data = request.get_json() or {}
        if not validate_category_json(data):
            return bad_request(ErrorMessages.API_FORMAT_NOT_ALLOWED)
        if not validate_new_category_name(data['category_name']):
            return bad_request(ErrorMessages.API_CATEGORY_NAME_ERROR)
        if Category.insert_new_category(data['category_name'],
                                        data.get('is_shown', 1)):
            response = jsonify(
                Category.query.filter_by(category_name=data['category_name']).
                first().to_dict('name'))
            response.status_code = 201
            response.headers['Location'] = url_for(
                'api.get_category_by_name',
                category_name=data['category_name'])
            return response
        else:
            return bad_request(ErrorMessages.API_CATEGORY_INSERT_ERROR)
    return error_response(response if response != 200 else 401)
コード例 #10
0
def get_categories():
    response = User.check_token(request)
    if response == 200:
        return jsonify(to_collection_dict(Category))
    return error_response(response)
コード例 #11
0
def get_skills():
    response = User.check_token(request)
    if response == 200:
        return jsonify(to_collection_dict(Skill))
    return error_response(response)