def decorated_function(*args, **kwargs): ''' Gets called in place of handler ''' session = get_session() if not 'nonce' in session: session['nonce'] = new_key() resp = make_response(handle(*args, **kwargs)) app.save_session(session, resp) return resp
def loginPOST(next): form = request.form usernm = form.get('username', '') passwd = form.get('password', '') # check information if not authenticate(usernm, passwd): return redirect(url_for('login', next=next)) # All ok, register user session = get_session() session['user'] = usernm resp = redirect(next) app.save_session(session, resp) return resp
def login_with(provider_name): """ The below is login page action using OAuth with Google :param provider_name: The provider name. google by default """ response = make_response() authomatic = Authomatic(app.config['SOCIAL_LOGIN'], app.secret_key) result = authomatic.login( WerkzeugAdapter(request, response), provider_name, None, session=session, session_saver=lambda: app.save_session(session, response)) if result and result.user and result.user.credentials: response = result.provider.access( authomatic.config.get(provider_name).get('url')) if response.status == 200: """ Create a new user if the provided email is not exists. Otherwise, update the current user """ user = User.first_or_new(email=response.data.get('email')) user.name = response.data.get('name') user.save() login_user(user) return redirect(url_for('index')) return response