示例#1
0
def login():
    """
    Login user.

    :return: status(True : Login Success | False : Login Failed)
        email(user's email when status is True.)
    """
    if users.is_authenticated():
        return {'msg': 'login.already'}, 400

    if request.form:
        form = LoginForm(MultiDict(request.form))
    else:
        form = LoginForm()

    if form.validate_on_submit():
        remember = True if request.form.get('rememberMe') else False
        users.login_user(form.user, remember=remember)
    status = users.is_authenticated()
    # print(verify_password(request.form.get('loginPassword'), user.password))
    # for h in request.headers:
    #     print(h)
    # for k in request.form:
    #     print(k)
    return {
        'status': status,
        'email': request.form.get('loginEmail'),
        'msg': form.errors[0]
    }
def login():
    """
    Login user.

    :return: status(True : Login Success | False : Login Failed)
        email(user's email when status is True.)
    """
    if users.is_authenticated():
        return {'msg': 'login.already'}, 400

    if request.form:
        form = LoginForm(MultiDict(request.form))
    else:
        form = LoginForm()

    if form.validate_on_submit():
        remember = True if request.form.get('rememberMe') else False
        users.login_user(form.user, remember=remember)
    status = users.is_authenticated()
    # print(verify_password(request.form.get('loginPassword'), user.password))
    # for h in request.headers:
    #     print(h)
    # for k in request.form:
    #     print(k)
    return {'status': status, 'email': request.form.get('loginEmail'), 'msg': form.errors[0]}
示例#3
0
def find_user_current():
    """
    Returns current user or empty object.
    :return: user
    """
    if users.is_authenticated():
        return {'user': users.me(), 'has_admin': users.has_admin()}
    return {}
def find_user_current():
    """
    Returns current user or empty object.
    :return: user
    """
    if users.is_authenticated():
        return {'user': users.me(), 'has_admin': users.has_admin()}
    return {}
def registration():
    """
    Register user.

    :return:
    """
    provider_id = request.form.get('provider_id', None)
    data = request.form
    data = MultiDict()
    for k in request.form:
        data.add(k, request.form.get(k, None))
    print("provider_id : "+str(provider_id))
    if provider_id:
        data.pop('provider_id')
        provider = get_provider_or_404(provider_id)
        connection_values = session.get('failed_login_connection', None)
    else:
        provider = None
        connection_values = None
    if data:
        form = RegistrationForm(MultiDict(data))
    else:
        form = RegistrationForm()

    if users.is_authenticated():
        return jsonify(), 400

    if form.validate_on_submit():
        user = users.create_user(**data)
        # See if there was an attempted social login prior to registering
        # and if so use the provider connect_handler to save a connection
        connection_values = session.pop('failed_login_connection', None)
        if connection_values and provider_id:
            connection_values['user_id'] = user.id
            connect_handler(connection_values, provider)
        if user:
            login_user(user)
    status = users.is_authenticated()
    email = users.me().email if status else ""
    return jsonify(status=status, email=email)
示例#6
0
def registration():
    """
    Register user.

    :return:
    """
    provider_id = request.form.get('provider_id', None)
    data = request.form
    data = MultiDict()
    for k in request.form:
        data.add(k, request.form.get(k, None))
    print("provider_id : " + str(provider_id))
    if provider_id:
        data.pop('provider_id')
        provider = get_provider_or_404(provider_id)
        connection_values = session.get('failed_login_connection', None)
    else:
        provider = None
        connection_values = None
    if data:
        form = RegistrationForm(MultiDict(data))
    else:
        form = RegistrationForm()

    if users.is_authenticated():
        return jsonify(), 400

    if form.validate_on_submit():
        user = users.create_user(**data)
        # See if there was an attempted social login prior to registering
        # and if so use the provider connect_handler to save a connection
        connection_values = session.pop('failed_login_connection', None)
        if connection_values and provider_id:
            connection_values['user_id'] = user.id
            connect_handler(connection_values, provider)
        if user:
            login_user(user)
    status = users.is_authenticated()
    email = users.me().email if status else ""
    return jsonify(status=status, email=email)