<s> from flask import ( <EOL> Blueprint , <EOL> redirect , <EOL> request , <EOL> flash , <EOL> url_for , <EOL> render_template ) <EOL> from flask_login import ( <EOL> login_required , <EOL> login_user , <EOL> current_user , <EOL> logout_user ) <EOL> from flask_babel import gettext as _ <EOL> from catwatch . lib . safe_next_url import safe_next_url <EOL> from catwatch . blueprints . user . decorators import anonymous_required <EOL> from catwatch . blueprints . user . models import User <EOL> from catwatch . blueprints . user . forms import ( <EOL> LoginForm , <EOL> BeginPasswordResetForm , <EOL> PasswordResetForm , <EOL> SignupForm , <EOL> WelcomeForm , <EOL> UpdateCredentials , <EOL> UpdateLocale ) <EOL> user = Blueprint ( '<STR_LIT:user>' , __name__ , template_folder = '<STR_LIT>' ) <EOL> @ user . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> @ anonymous_required ( ) <EOL> def login ( ) : <EOL> form = LoginForm ( next = request . args . get ( '<STR_LIT>' ) ) <EOL> if form . validate_on_submit ( ) : <EOL> u = User . find_by_identity ( request . form . get ( '<STR_LIT>' ) ) <EOL> if u and u . authenticated ( password = request . form . get ( '<STR_LIT:password>' ) ) : <EOL> if login_user ( u , remember = True ) : <EOL> u . update_activity_tracking ( request . remote_addr ) <EOL> next_url = request . form . get ( '<STR_LIT>' ) <EOL> if next_url : <EOL> return redirect ( safe_next_url ( next_url ) ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> else : <EOL> flash ( _ ( '<STR_LIT>' ) , '<STR_LIT:error>' ) <EOL> else : <EOL> flash ( _ ( '<STR_LIT>' ) , '<STR_LIT:error>' ) <EOL> return render_template ( '<STR_LIT>' , form = form ) <EOL> @ user . route ( '<STR_LIT>' ) <EOL> @ login_required <EOL> def logout ( ) : <EOL> logout_user ( ) <EOL> flash ( _ ( '<STR_LIT>' ) , '<STR_LIT:success>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> @ user . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> @ anonymous_required ( ) <EOL> def begin_password_reset ( ) : <EOL> form = BeginPasswordResetForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> u = User . initialize_password_reset ( request . form . get ( '<STR_LIT>' ) ) <EOL> flash ( _ ( '<STR_LIT>' , <EOL> email = u . email ) , '<STR_LIT:success>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> return render_template ( '<STR_LIT>' , form = form ) <EOL> @ user . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> @ anonymous_required ( ) <EOL> def password_reset ( ) : <EOL> form = PasswordResetForm ( reset_token = request . args . get ( '<STR_LIT>' ) ) <EOL> if form . validate_on_submit ( ) : <EOL> u = User . deserialize_token ( request . form . get ( '<STR_LIT>' ) ) <EOL> if u is None : <EOL> flash ( _ ( '<STR_LIT>' ) , <EOL> '<STR_LIT:error>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> form . populate_obj ( u ) <EOL> u . password = User . encrypt_password ( request . form . get ( '<STR_LIT:password>' , None ) ) <EOL> u . save ( ) <EOL> if login_user ( u ) : <EOL> flash ( _ ( '<STR_LIT>' ) , '<STR_LIT:success>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> return render_template ( '<STR_LIT>' , form = form ) <EOL> @ user . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> @ anonymous_required ( ) <EOL> def signup ( ) : <EOL> form = SignupForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> u = User ( ) <EOL> form . populate_obj ( u ) <EOL> u . password = User . encrypt_password ( request . form . get ( '<STR_LIT:password>' , None ) ) <EOL> u . save ( ) <EOL> if login_user ( u ) : <EOL> flash ( _ ( '<STR_LIT>' ) , '<STR_LIT:success>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> return render_template ( '<STR_LIT>' , form = form ) <EOL> @ user . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> @ login_required <EOL> def welcome ( ) : <EOL> if current_user . username : <EOL> flash ( _ ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> form = WelcomeForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> current_user . username = request . form . get ( '<STR_LIT:username>' ) <EOL> current_user . save ( ) <EOL> flash ( _ ( '<STR_LIT>' ) , '<STR_LIT:success>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> return render_template ( '<STR_LIT>' , form = form ) <EOL> @ user . route ( '<STR_LIT>' ) <EOL> @ login_required <EOL> def settings ( ) : <EOL> return render_template ( '<STR_LIT>' ) <EOL> @ user . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> @ login_required <EOL> def update_credentials ( ) : <EOL> form = UpdateCredentials ( current_user , uid = current_user . id ) <EOL> if form . validate_on_submit ( ) : <EOL> new_password = request . form . get ( '<STR_LIT:password>' , '<STR_LIT>' ) <EOL> current_user . email = request . form . get ( '<STR_LIT:email>' ) <EOL> if new_password : <EOL> current_user . password = User . encrypt_password ( new_password ) <EOL> current_user . save ( ) <EOL> flash ( _ ( '<STR_LIT>' ) , '<STR_LIT:success>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> return render_template ( '<STR_LIT>' , form = form ) <EOL> @ user . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> @ login_required <EOL> def update_locale ( ) : <EOL> form = UpdateLocale ( locale = current_user . locale ) <EOL> if form . validate_on_submit ( ) : <EOL> form . populate_obj ( current_user ) <EOL> current_user . save ( ) <EOL> flash ( _ ( '<STR_LIT>' ) , '<STR_LIT:success>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> return render_template ( '<STR_LIT>' , form = form ) </s>
