점프투플라스크) 세션관련??
최초 로그인한 뒤 로그인 상태에서 뒤로가기 했을때, /auth/login 페이지가 보여집니다. (pybo.kr 도 동일함)
사용자 경험상 홈에 머무르거나, 세션 만료 확인창을 띄우고 싶은데
어떻게 검색하면 될까요?
cwh3767 님 339
2021년 6월 3일 2:06 오후
1개의 답변이 있습니다. 1 / 1 Page
/auth/login 에 대응되는 함수의 GET 방식 처리부분에서 로그인이 되어 있는지 확인해 보고 로그인이 이미 되어 있다면 홈으로 리다이렉션 시키면 될것 같습니다.
예를들어
@bp.route('/login/', methods=('GET', 'POST'))
def login():
form = UserLoginForm()
if request.method == 'POST' and form.validate_on_submit():
error = None
user = User.query.filter_by(username=form.username.data).first()
if not user:
error = "존재하지 않는 사용자입니다."
elif not check_password_hash(user.password, form.password.data):
error = "비밀번호가 올바르지 않습니다."
if error is None:
session.clear()
session['user_id'] = user.id
return redirect(url_for('main.index'))
flash(error)
elif request.method == 'GET' and g.user:
return redirect(url_for('main.index'))
return render_template('auth/login.html', form=form)
위처럼 테스트 해 보지는 않았지만 다음 두줄을 삽입하면 될것 같습니다.
elif request.method == 'GET' and g.user:
return redirect(url_for('main.index'))
박응용 님
M 2021년 6월 4일 7:49 오전