Ejemplo n.º 1
0
def signup():
    error = None
    req = request.json
    request_email = req['email'].lower()
    password = req['password']
    entry = user.findSingleUser({'email': request_email})

    if entry is not None:
        error = 'Email is already in use'
        return jsonify(LoggedIn=False, error=error), HTTP_400_BAD_REQUEST
    try:
        invite_code = req['invite']
        if not invite.is_valid(invite_code):
            raise Exception("Invalid invite code")
        new_user = user.create_user(req)
        if (new_user is None):
            raise Exception()

        database_wrapper.save_entity(new_user)
        invite.consume(invite_code, new_user['_id'])

        # We need to log in the just-registered user.
        status = Auth.login(new_user, password)
        return jsonify(user.get_basic_info_from_users([new_user])[0])
    except Exception as e:
        return jsonify(error=str(e)), HTTP_400_BAD_REQUEST
def signup():
    error = None
    req = request.json
    request_email = req['email'].lower()
    password = req['password']
    entry = user.findSingleUser({'email': request_email})

    if entry is not None:
        error = 'Email is already in use'
        return jsonify(LoggedIn=False, error=error), HTTP_400_BAD_REQUEST
    try:
        invite_code = req['invite']
        if not invite.is_valid(invite_code):
            raise Exception("Invalid invite code")
        new_user = user.create_user(req)
        if (new_user is None):
            raise Exception()

        database_wrapper.save_entity(new_user)
        invite.consume(invite_code, new_user['_id'])

        # We need to log in the just-registered user.
        status = Auth.login(new_user, password)
        return jsonify(user.get_basic_info_from_users([new_user])[0])
    except Exception as e:
        return jsonify(error=str(e)), HTTP_400_BAD_REQUEST
Ejemplo n.º 3
0
def prepare(attributes):
    attributes_copy = copy.deepcopy(attributes)
    attributes_copy['password'] = Auth.hash_password(attributes['password'])
    attributes_copy['email'] = attributes['email'].lower()
    attributes_copy['permissionLevel'] = Auth.GHOST if config[
        'ENABLE_ACCOUNT_APPROVALS'] else Auth.USER
    return attributes_copy
Ejemplo n.º 4
0
def login_social():
    req = request.json
    try:
        social_type = req['socialType']
        token = req['token']
    except:
        return '', HTTP_400_BAD_REQUEST

    error = Auth.login_social(social_type, token)
    if error:
        return jsonify(LoggedIn=False, error=error), HTTP_400_BAD_REQUEST
    return user.get_basic_info_with_security(current_user)
def login_social():
    req = request.json
    try:
        social_type = req['socialType']
        token = req['token']
    except:
        return '', HTTP_400_BAD_REQUEST

    error = Auth.login_social(social_type, token)
    if error:
        return jsonify(LoggedIn=False, error=error), HTTP_400_BAD_REQUEST
    return user.get_basic_info_with_security(current_user)
Ejemplo n.º 6
0
def login():
    req = request.json
    try:
        email = req['email'].lower()
        password_hash = req['password']
    except:
        return '', HTTP_400_BAD_REQUEST

    user_object = user.findSingleUser({'email': email})
    error = Auth.login(user_object, password_hash)
    if error:
        return jsonify(LoggedIn=False, error=error), HTTP_400_BAD_REQUEST
    return user.get_basic_info_with_security(user_object)
def login():
    req = request.json
    try:
        email = req['email'].lower()
        password_hash = req['password']
    except:
        return '', HTTP_400_BAD_REQUEST

    user_object = user.findSingleUser({'email': email})
    error = Auth.login(user_object, password_hash)
    if error:
        return jsonify(LoggedIn=False, error=error), HTTP_400_BAD_REQUEST
    return user.get_basic_info_with_security(user_object)
from project.services.elastic import Elastic
from project.services.auth import Auth
from project.services.cors import Cors
from project.services.api import API

app = Flask(__name__)

Cors.init_app(app, config)

app.config['CORS_HEADERS'] = 'Content-Type'
app.secret_key = config['SECRET_KEY']
app.debug = config['DEBUG']
app.json_encoder = CustomJSONEncoder

# Init services


Elastic.connect(config)

Auth.init_app(app, config)

API.configure(config)

API.register_blueprints(app, config)


@app.errorhandler(404)
def not_found(error=None):
    return jsonify(error='Not Found'), HTTP_404_NOT_FOUND
Ejemplo n.º 9
0
def logout():
    Auth.logout()
    return jsonify(LoggedIn=False, error=None)
def prepare(attributes):
    attributes_copy = copy.deepcopy(attributes)
    attributes_copy['password'] = Auth.hash_password(attributes['password'])
    attributes_copy['email'] = attributes['email'].lower()
    attributes_copy['permissionLevel'] = Auth.GHOST if config['ENABLE_ACCOUNT_APPROVALS'] else Auth.USER
    return attributes_copy
def logout():
    Auth.logout()
    return jsonify(LoggedIn=False, error=None)
Ejemplo n.º 12
0
Database.connect(config)

from project.services.elastic import Elastic
from project.services.auth import Auth
from project.services.cors import Cors
from project.services.api import API

app = Flask(__name__)

Cors.init_app(app, config)

app.config['CORS_HEADERS'] = 'Content-Type'
app.secret_key = config['SECRET_KEY']
app.debug = config['DEBUG']
app.json_encoder = CustomJSONEncoder

# Init services

Elastic.connect(config)

Auth.init_app(app, config)

API.configure(config)

API.register_blueprints(app, config)


@app.errorhandler(404)
def not_found(error=None):
    return jsonify(error='Not Found'), HTTP_404_NOT_FOUND