def dispatch_request(self, *args, **kwargs): form = RegisterForm(request.form) if request.method == "POST": if form.validate_on_submit(): test_service_account = get_service_account( name=form.email.data) if test_service_account is not None: service = USER.AUTH_SERVICE[test_service_account.service] flash( 'This %s email address already exists. Please use it to log ' 'in.' % service) return redirect(url_for('users.login_email')) if not app.config['USER_REGISTRATION_REQUIRE_ACTIVATION']: # require activation status = USER.ACTIVE else: status = USER.NEW user = create_user(first_name=form.first_name.data, last_name=form.last_name.data, email=form.email.data, phone=form.phone.data, status=status) service_account = create_service_account( name=form.email.data, password=generate_password_hash(form.password.data), service=USER.LOCAL) if app.config['USER_REGISTRATION_EMAIL']: # TODO: send an email pass flash(USER.REGISTRATION_SUCCESSFUL, 'success') return redirect(url_for('users.login_email')) else: print "NOT VALIDATED" print form.errors return render_template(self.template_name, form=form)
def dispatch_request(self, *args, **kwargs): resp = kwargs['data'] access_token = resp['access_token'] session['access_token'] = access_token, '' from urllib2 import Request, urlopen, URLError import json headers = {'Authorization': 'OAuth ' + access_token} req = Request('https://www.googleapis.com/oauth2/v1/userinfo', None, headers) try: res = urlopen(req) except URLError: return req.read() #TODO: Handle this data = json.loads(res.read()) service_account = get_service_account(name=data['email'], service=USER.GOOGLE) next_url = request.args.get('next') or url_for('users.login') if g.user: if service_account: connect_service_account_to_user(g.user, service_account) else: service_account = create_service_account( name=data['email'], oauth_token=access_token, service=USER.GOOGLE) connect_service_account_to_user(g.user, service_account) session['session_token'] = create_session(service_account) flash( USER.ASSOCIATION_COMPLETE % (USER.AUTH_SERVICE[USER.GOOGLE], data['email']), 'success') next_url = url_for('users.home') else: if service_account is not None: user = get_user(service_account=service_account) if user is not None: # create session session['session_token'] = create_session(service_account) flash(u'Welcome %s %s' % (user.first_name, user.last_name)) else: # Service account exists, but no user. session['session_token'] = create_session(service_account) flash( u'Welcome back, %s. Please consider becoming a member.' % service_account.name) else: service_account = create_service_account( name=data['email'], oauth_token=access_token, service=USER.GOOGLE) session['session_token'] = create_session(service_account) flash(u'Your %s ID %s has been saved.' % (USER.AUTH_SERVICE[USER.GOOGLE], data['email'])) if resp is None: flash(USER.LOGIN_DENIED) return redirect(next_url)
def dispatch_request(self, *args, **kwargs): form = EmailLoginForm(request.form) if request.method == "POST": if form.validate_on_submit(): service_account = get_service_account(name=form.email.data, service=USER.LOCAL) if service_account and check_password_hash( service_account.password, form.password.data): token = create_session(service_account) if token: session['session_token'] = token return redirect(url_for('users.home')) flash('Wrong email or password', 'error-message') return render_template("login_email.html", email_login_form=form)
def dispatch_request(self, *args, **kwargs): resp = kwargs['data'] service_account = get_service_account(name=resp['screen_name'], service=USER.TWITTER) next_url = request.args.get('next') or url_for('users.login') if g.user: if service_account: connect_service_account_to_user(g.user, service_account) else: service_account = create_service_account( name=resp['screen_name'], oauth_token=resp['oauth_token'], oauth_secret=resp['oauth_token_secret'], service=USER.TWITTER) connect_service_account_to_user(g.user, service_account) session['session_token'] = create_session(service_account) flash( USER.ASSOCIATION_COMPLETE % (USER.AUTH_SERVICE[USER.TWITTER], resp['screen_name']), 'success') next_url = url_for('users.home') else: if service_account is not None: user = get_user(service_account=service_account) if user is not None: session['session_token'] = create_session(service_account) flash(u'Welcome %s %s' % (user.first_name, user.last_name)) else: session['session_token'] = create_session(service_account) flash( u'Welcome back, %s. Please consider becoming a member.' % service_account.name) else: service_account = create_service_account( name=resp['screen_name'], oauth_token=resp['oauth_token'], oauth_secret=resp['oauth_token_secret'], service=USER.TWITTER) session['session_token'] = create_session(service_account) flash(u'Your %s ID %s has been saved.' % (USER.AUTH_SERVICE[USER.TWITTER], resp['screen_name'])) if resp is None: flash(USER.LOGIN_DENIED) return redirect(next_url)
def decorator(*args, **kwargs): g.user = None g.service_account = None g.is_admin = False if 'session_token' in session: import application.users.constants as USER from application.users.storage import get_service_account, \ get_session, get_user sess = get_session(token=session['session_token']) if sess is not None: service_account = get_service_account(id=sess.service_account) if service_account is not None: g.service_account = service_account user = get_user(service_account=service_account) if user is not None: g.user = user for test_service_account in g.user.service_accounts: if test_service_account.service == USER.LOCAL: g.username = test_service_account.name if user.getRole() == USER.ADMIN: g.is_admin = True return f(*args, **kwargs)