示例#1
0
def adduser(provider_id=None):

    provider = get_provider_or_404(provider_id)

    form = RegisterForm()
    print form
    connection_values = session.get('failed_login_connection', None)
    print connection_values
    access_token = connection_values['access_token']
    graph = facebook.GraphAPI(access_token)
    profile = graph.get_object("me")
    email = profile["email"]
    print email

    #ds = security.user_datastore
    user = ds.create_user(email=email, password="******")
    ds.commit()
            # 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:
        connection_values['user_id'] = user.id
        connect_handler(connection_values, provider)

    if login_user(user):
        ds.commit()
        flash('Account created successfully', 'info')
        return redirect(url_for('profile'))

    return abort(404)
示例#2
0
文件: views.py 项目: genmon/glanc1ng
def register(provider_id=None):
	if current_user.is_authenticated():
		return redirect(request.referrer or '/')

	if provider_id:
		provider = get_provider_or_404(provider_id)
		connection_values = session.pop('failed_login_connection', None)
	else:
		provider = None
		connection_values = None

	app.logger.debug("Attemption to register with connection_values: %s" % repr(connection_values))

	if connection_values is not None:
		ds = app.security.datastore
		fake_email = connection_values['provider_user_id'] + "*****@*****.**"
		user = ds.create_user(email=fake_email, password="******")

		ds.commit()
		
		connection_values['user_id'] = user.id
		connect_handler(connection_values, provider)

		login_user(user)
		ds.commit()
		flash('Account created successfully', 'info')
		return redirect(url_for('index'))

	return abort(404)
示例#3
0
def register(provider_id=None):
    print 'REGISTER'
    if current_user.is_authenticated():
        return redirect(request.referrer or '/')

    print 'HELLLLLLOOOOO'
    form = RegisterForm()

    if provider_id:
        print provider_id
        provider = get_provider_or_404(provider_id)
        connection_values = session.get('failed_login_connection', None)
    else:
        provider = None
        connection_values = None
  
    print 'true?'
    print provider
    print connection_values
    print form.validate_on_submit()
    print form.email.data

    if provider and connection_values and form.validate_on_submit():
        char_set = string.ascii_uppercase + string.digits
        ds = current_app.security.datastore
        user = ds.create_user(
          email=form.email.data,
          password=''.join(random.sample(char_set*32,32))
        )
        user.api_key = ''.join(random.sample(char_set*32,32))

        ds.commit()

        # 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:
            connection_values['user_id'] = user.id
            connect_handler(connection_values, provider)

        if login_user(user):
            ds.commit()
            flash('Account created successfully', 'info')
            return redirect(url_for('profile'))

        return render_template('thanks.html', user=user)

    login_failed = int(request.args.get('login_failed', 0))
    print "login failed? "
    print login_failed

    return render_template('register.html',
                           form=form,
                           provider=provider,
                           login_failed=login_failed,
                           connection_values=connection_values)
示例#4
0
def register(provider_id=None):
    print 'REGISTER'
    if current_user.is_authenticated():
        return redirect(request.referrer or '/')

    print 'HELLLLLLOOOOO'
    form = RegisterForm()

    if provider_id:
        print provider_id
        provider = get_provider_or_404(provider_id)
        connection_values = session.get('failed_login_connection', None)
    else:
        provider = None
        connection_values = None

    print 'true?'
    print provider
    print connection_values
    print form.validate_on_submit()
    print form.email.data

    if provider and connection_values and form.validate_on_submit():
        char_set = string.ascii_uppercase + string.digits
        ds = current_app.security.datastore
        user = ds.create_user(email=form.email.data,
                              password=''.join(random.sample(
                                  char_set * 32, 32)))
        user.api_key = ''.join(random.sample(char_set * 32, 32))

        ds.commit()

        # 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:
            connection_values['user_id'] = user.id
            connect_handler(connection_values, provider)

        if login_user(user):
            ds.commit()
            flash('Account created successfully', 'info')
            return redirect(url_for('profile'))

        return render_template('thanks.html', user=user)

    login_failed = int(request.args.get('login_failed', 0))
    print "login failed? "
    print login_failed

    return render_template('register.html',
                           form=form,
                           provider=provider,
                           login_failed=login_failed,
                           connection_values=connection_values)
示例#5
0
def on_login_failed(sender, provider, oauth_response):
    connection_values = get_connection_values_from_oauth_response(
        provider, oauth_response)
    ds = app.security.datastore
    email = connection_values.pop('email', None)
    user = ds.create_user(email=email)
    ds.commit()
    connection_values['user_id'] = user.id
    connect_handler(connection_values, provider)
    login_user(user)
    db.session.commit()
示例#6
0
def on_login_failed(sender, provider, oauth_response):
    connection_values = get_connection_values_from_oauth_response(
        provider, oauth_response)
    connection_values['display_name'] = connection_values['display_name'][
        'givenName'] + " " + connection_values['display_name']['familyName']
    connection_values['full_name'] = connection_values['display_name']
    session['google_id'] = connection_values['provider_user_id']
    user = user_datastore.create_user(google_id=session['google_id'])
    user_datastore.commit()
    connection_values['user_id'] = user.id
    connect_handler(connection_values, provider)
    login_user(user)
    db.session.commit()
    return render_template('index.html')
def register(provider_id=None):
    if current_user.is_authenticated():
        return redirect(request.referrer or '/')

    form = RegisterForm()

    if provider_id:
        provider = get_provider_or_404(provider_id)
        connection_values = session.get('failed_login_connection', None)
    else:
        provider = None
        connection_values = None

    if form.validate_on_submit():
        ds = current_app.security.datastore
        user = ds.create_user(email=form.email.data,
                              password=form.password.data)
        user.age = form.age.data
        user.twitter_handle = form.twitter_handle.data
        user.name = form.name.data
        user.study = u'no'
        user.work = u'no'
        user.sex = form.sex.data
        ds.commit()

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

        print form.next.data

        if connection_values:
            connection_values['user_id'] = user.id
            connect_handler(connection_values, provider)

        if login_user(user):
            ds.commit()
            flash('Cuenta creada correctamente!', 'info')
            return redirect(form.next.data or '/')

        return render_template('thanks.html', user=user)
    login_failed = int(request.args.get('login_failed', 0))

    return render_template('register.html',
                           form=form,
                           provider=provider,
                           login_failed=login_failed,
                           connection_values=connection_values,
                           next=request.args.get('next'))
示例#8
0
    def register_new_user(**kwargs):
        from survaider.security.controller import user_datastore

        reg_dat = get_connection_values_from_oauth_response(kwargs['provider'], kwargs['oauth_response'])

        user = user_datastore.create_user(email = reg_dat['email'], password = str(uuid.uuid4()))
        user.metadata['full_name'] = reg_dat['full_name'] if 'full_name' in reg_dat else reg_dat['display_name'] if 'display_name' in reg_dat else None

        user.save()

        reg_dat['user_id'] = str(user)
        connect_handler(reg_dat, kwargs['provider'])
        login_user(user)

        return True
示例#9
0
    def register_new_user(**kwargs):
        from survaider.security.controller import user_datastore

        reg_dat = get_connection_values_from_oauth_response(
            kwargs['provider'], kwargs['oauth_response'])

        user = user_datastore.create_user(email=reg_dat['email'],
                                          password=str(uuid.uuid4()))
        user.metadata['full_name'] = reg_dat[
            'full_name'] if 'full_name' in reg_dat else reg_dat[
                'display_name'] if 'display_name' in reg_dat else None

        user.save()

        reg_dat['user_id'] = str(user)
        connect_handler(reg_dat, kwargs['provider'])
        login_user(user)

        return True
示例#10
0
def register(provider_id=None):
    if current_user.is_authenticated():
        return redirect(request.referrer or '/')

    form = RegisterForm()

    if provider_id:
        provider = get_provider_or_404(provider_id)
        connection_values = session.get('failed_login_connection', None)
    else:
        provider = None
        connection_values = None

    if form.validate_on_submit():
        ds = current_app.security.datastore
        user = ds.create_user(email=form.email.data,
                              password=form.password.data)
        ds.commit()

        # 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:
            connection_values['user_id'] = user.id
            connect_handler(connection_values, provider)

        if login_user(user):
            ds.commit()
            flash('Account created successfully', 'info')
            return redirect(url_for('profile'))

        return render_template('thanks.html', user=user)

    login_failed = int(request.args.get('login_failed', 0))

    return render_template('register.html',
                           form=form,
                           provider=provider,
                           login_failed=login_failed,
                           connection_values=connection_values)
示例#11
0
    def auto_add_user(sender, provider, oauth_response):
        connection_values = get_connection_values_from_oauth_response(
            provider, oauth_response)
        email = connection_values['email']
        if not email or not email.strip():
            email = ''

        if provider.name.lower() == 'facebook':
            fname = connection_values['full_name']
            email = fb.get_email(oauth_response)
        elif provider.name.lower() == 'twitter':
            fname = connection_values['display_name'][1:]  # cut off leading @
        else:
            fname = connection_values['display_name']

        user = user_datastore.create_user(
            email=email,
            name=fname,
            active=True,
            confirmed_at=datetime.now(),
        )

        role_query = mdl.DB.session.query(mdl.Role).filter_by(
            name='authenticated')
        try:
            role = role_query.one()
        except NoResultFound:
            role = mdl.Role(name='authenticated')

        user.roles.append(role)
        user_datastore.commit()
        connection_values['user_id'] = user.id
        connect_handler(connection_values, provider)
        login_user(user)
        mdl.DB.session.commit()
        flash(gettext(
            'Successfully linked login with {}. '
            'Ignore the message saying: "{}"').format(
            provider.name, '... account not associated with an existing user'),
            'info')
        return redirect(url_for('root.profile'))
示例#12
0
def register(provider_id=None):
    if current_user.is_authenticated():
        return redirect(request.referrer or '/')

    form = RegisterForm()

    if provider_id:
        provider = get_provider_or_404(provider_id)
        connection_values = session.get('failed_login_connection', None)
    else:
        provider = None
        connection_values = None

    if form.validate_on_submit():
        ds = current_app.security.datastore
        user = ds.create_user(email=form.email.data, password=form.password.data)
        ds.commit()

        # 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:
            connection_values['user_id'] = user.id
            connect_handler(connection_values, provider)

        if login_user(user):
            ds.commit()
            flash('Account created successfully', 'info')
            return redirect(url_for('profile'))

        return render_template('thanks.html', user=user)

    login_failed = int(request.args.get('login_failed', 0))

    return render_template('register.html',
                           form=form,
                           provider=provider,
                           login_failed=login_failed,
                           connection_values=connection_values)