Entries from 2021-05-04 to 1 day

current user Section 11, Lecture 52

ログインしてるのにログイン画面に飛べるのを処理する。 以下のコードを設定するだけ良い。 if current_user.is_authenticated:はもしすでにログイン済みの場合はフラッシュメッセージを表示する。 @at.route('/login', methods=['GET', 'POST']) def do_the…

logging users out Section 11, Lecture 51

layout.htmlに以下を追加で記述して、各ファンクションとリンクさせる。 <li><a href="{{ url_for('main.display_books') }}"> Home </a></li> <li><a href="{{ url_for('authentication.register_user') }}"> Register </a></li> <li> {% if current_user.is_authenticated %} <a href="{{ url_for('authentication.log_out_user') }}"> SignOut </a> {…</li>

display login status Section 11, Lecture 50

ログイン状態か表示する方法 app/catalog/templates/layout.htmlに以下を追記する。 <a href=""> {% if current_user.is_authenticated %} Logged-In as <b style="color: deeppink"> {{ current_user.user_name.title() }} </b> {% else %} Not Logged-In {% endif %} </a> 実際にやってみる ログイン状態…

よくわkラン letting users login Section 11, Lecture 49

ログイン機能を改善する。 models.pyに以下を追記する ユーザーが入力したpasswordを渡すことでdbにあるハッシュと一致するかをチェックする。 def check_password(self, password): return bcrypt.check_password_hash(self.user_password, password) もし…

Flask-loginの説明 login manager and usermixin classes Section 11, Lecture 48

Flask Loginに関して models.pyに以下を記述することで login managerのloaderが使える。 int(id)にする必要がある。 今回はこの4つについて学ぶ 1. LoginManager 2. @login_manager.user_loader 3. load_user()custom method 4. UserMixin() auth/forms.py…