def login(): if current_user.is_authenticated: return redirect(url_for('main.index')) form = LoginForm() if form.validate_on_submit(): login_user(form.user, form.remember_me.data) session['access'] = current_user.generate_auth_token() session['refresh'] = current_user.generate_auth_token( expiration=3600 * 24 * 31, token_type='refresh') next = request.args.get('next') if next is None or not next.startswith('/'): next = url_for('main.index') return redirect(next) return render_template('auth/login.html', form=form)
def login(): if current_user.is_authenticated: abort(400) form = LoginForm(request.form) if form.validate_on_submit(): global USERS username = form.username.data user = load_user_from_name(username) if user is None: return flask.render_template('login.html', form=form) else: login_user(user, form.remember_me.data) token = current_user.generate_auth_token() # Generate a token for the logged in user token = str(token) token = token[2:] token = token[:-1] flask.session['api_session_token'] = token # Store that token as a session variable nextUrl = flask.request.args.get('next') if nextUrl is None: return flask.redirect(flask.url_for('index')) if is_safe_url(nextUrl): return flask.redirect(nextUrl) return flask.abort(400) return flask.render_template('login.html', form=form)
def get_token(): if current_user.is_anonymous: return unauthorized('Invalid credentials') return jsonify({ 'token': current_user.generate_auth_token(expiration=36000000), 'expiration': 36000000, 'user_id': current_user.id})
def get_token() -> 'token': """Lấy token""" if current_user.is_anonymous: return unauthorized('Thông tin không hợp lệ') return jsonify({ 'token': current_user.generate_auth_token(expiration=3600), 'expiration': 3600 })
def before_request(): if current_user.is_authenticated: current_user.ping() if not current_user.confirmed and request.endpoint[:5] != 'auth.': return redirect(url_for('auth.unconfirmed')) if current_user is not AnonymousUser and not g.get('token'): # FIXME: "Basic ..." remove " g.token = 'Basic ' + base64.b64encode(bytes(current_user.generate_auth_token(expiration=3600).decode('utf-8') + ':', 'utf-8')).decode('utf-8')
def user_playground(page): """ Show the user backoffice. If the user is not logged in, he is redirected to a login/register page. If logged in, show the user API token. """ api_token = current_user.generate_auth_token().decode('ascii') try: return render_template('%s.html' % page, api_token=api_token) except TemplateNotFound: abort(404)
def get_auth_token(): token = current_user.generate_auth_token() return jsonify({'token': token.decode('ascii')})
def token(): t = current_user.generate_auth_token() return jsonify({"token": t})
def get_auth_token(): token = current_user.generate_auth_token() return jsonify({"token": token.decode("ascii")})
def get(self): token = current_user.generate_auth_token() return {'token': token.decode()}