2016-07-04 5 views
1

는 내가 Stormpath 워드 프로세서에서 이걸 발견 : 그래서 플라스크 - 로그인에서와 같이 작동하지 않는 것 is_authenticatedStormpath에는 간단한 'is_authenticated'솔루션이 있습니까?

is_authenticated() (http://flask-stormpath.readthedocs.io/en/latest/api.html) 
All users will always be authenticated, so this will always return True. 

합니다. 해결 방법을 수행해야합니까, 아니면 이미이 API에 미리 빌드되어있는 유사한 기능이 있습니까?

--- 수정 --- 대답에 대한

감사합니다,하지만 여전히 작동하지 않습니다. 내가 뭘하려고 이것이다 :

navbar.html

<div class="navbar-right"> 
    {% if user %} 
    <p class="navbar-text">Signed in as <a href="#" class="navbar-link">{{ result }}</a></p> 
    {% else %} 
    <button id="registerbtn" type="button" class="btn btn-default navbar-btn">Sign up</button> 
    {% endif %} 
</div> 

app.py

@app.route('/navbar') 
    def navbar(): 
    if user: 
     return render_template('navbar.html', result=user.given_name) 
    else: 
     return render_template('navbar.html') 

그리고이 오류 메시지가 얻을 :

AttributeError: 'AnonymousUserMixin' object has no attribute 'given_name' 

답변

1

당신이 =이 원하는 걸 얻을 것이다.

if user: 
    return render_template('index.html', given_name=user.given_name) 
return render_template('index.html') 

과 영업 이익에서와 같은 오류를 얻을 것이다 :

AttributeError: 'AnonymousUserMixin' object has no attribute 'given_name' 

나는에 코드를 변경하여 고정 : 그 위에서 규정 된 나는 유사한 코드를 사용

if user.is_anonymous() == False: 
    return render_template('index.html', given_name=user.given_name) 
return render_template('index.html') 

이 오류는 사용자 개체가 항상 사실로 확인된다는 것인데 이는 사용자 개체가 flask.ext.stormpath에서 사용자를 가져올 때 어떤 방법으로 인스턴스화 되었기 때문입니다.

0

저는이 도서관의 저자입니다. 실제로 사용자가 인증되었는지 여부를 확인하는 방법이 있습니다. 찾은 코드는 실제로 내부 Flask-Login API의 일부이며 공용으로 사용하기위한 것이 아닙니다.

은 당신이하고 싶은 것은 이것이다 :

from flask_stormpath import user 

def my_view(): 
    if user: 
     # there is a user who is authenticated! 
    else: 
     # nobody has authenticated :(

그건 내가뿐만 아니라이 오류를했다)

+0

여전히 작동하지 않는 것 같습니다. 제 질문을 업데이트했습니다. 어쩌면 당신이 나를 다시 도울 수 있습니다. :) – Yhun

+0

플라스크 스톰 패스가 아닌 다른 플러그인을 사용하고 있습니까? 업데이트 된 질문을 보면,'user' 객체를 덮어 쓰는 뭔가가있는 것 같습니다. – rdegges

+0

아니요,이 애플리케이션의 Flask-Stormpath 이외의 다른 플러그인은 없습니다. – Yhun