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)
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)