<s> import os <EOL> from flask import Flask , render_template_string , request <EOL> from flask_mail import Mail <EOL> from flask_sqlalchemy import SQLAlchemy <EOL> from flask_user import login_required , SQLAlchemyAdapter , UserManager , UserMixin <EOL> from flask_user import roles_required <EOL> class ConfigClass ( object ) : <EOL> SECRET_KEY = os . getenv ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> SQLALCHEMY_DATABASE_URI = os . getenv ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> CSRF_ENABLED = True <EOL> MAIL_USERNAME = os . getenv ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> MAIL_PASSWORD = os . getenv ( '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> MAIL_DEFAULT_SENDER = os . getenv ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> MAIL_SERVER = os . getenv ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> MAIL_PORT = int ( os . getenv ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> MAIL_USE_SSL = int ( os . getenv ( '<STR_LIT>' , True ) ) <EOL> USER_APP_NAME = "<STR_LIT>" <EOL> def create_app ( test_config = None ) : <EOL> app = Flask ( __name__ ) <EOL> app . config . from_object ( __name__ + '<STR_LIT>' ) <EOL> try : app . config . from_object ( '<STR_LIT>' ) <EOL> except : pass <EOL> if test_config : <EOL> app . config . update ( test_config ) <EOL> mail = Mail ( app ) <EOL> db = SQLAlchemy ( app ) <EOL> class User ( db . Model , UserMixin ) : <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> user_profile_id = db . Column ( db . Integer ( ) , db . ForeignKey ( '<STR_LIT>' , ondelete = '<STR_LIT>' ) ) <EOL> username = db . Column ( db . String ( <NUM_LIT:50> ) , nullable = False , unique = True ) <EOL> password = db . Column ( db . String ( <NUM_LIT:255> ) , nullable = False , server_default = '<STR_LIT>' ) <EOL> reset_password_token = db . Column ( db . String ( <NUM_LIT:100> ) , nullable = False , server_default = '<STR_LIT>' ) <EOL> active = db . Column ( '<STR_LIT>' , db . Boolean ( ) , nullable = False , server_default = '<STR_LIT:0>' ) <EOL> email = db . Column ( db . String ( <NUM_LIT:255> ) , nullable = False , unique = True ) <EOL> confirmed_at = db . Column ( db . DateTime ( ) ) <EOL> user_profile = db . relationship ( '<STR_LIT>' , uselist = False , foreign_keys = [ user_profile_id ] ) <EOL> class UserProfile ( db . Model ) : <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> first_name = db . Column ( db . String ( <NUM_LIT:50> ) , nullable = False , default = '<STR_LIT>' ) <EOL> last_name = db . Column ( db . String ( <NUM_LIT:50> ) , nullable = False , default = '<STR_LIT>' ) <EOL> roles = db . relationship ( '<STR_LIT>' , secondary = '<STR_LIT>' , <EOL> backref = db . backref ( '<STR_LIT>' , lazy = '<STR_LIT>' ) ) <EOL> class Role ( db . Model ) : <EOL> id = db . Column ( db . Integer ( ) , primary_key = True ) <EOL> name = db . Column ( db . String ( <NUM_LIT:50> ) , unique = True ) <EOL> class UserRoles ( db . Model ) : <EOL> id = db . Column ( db . Integer ( ) , primary_key = True ) <EOL> user_profile_id = db . Column ( db . Integer ( ) , db . ForeignKey ( '<STR_LIT>' , ondelete = '<STR_LIT>' ) ) <EOL> role_id = db . Column ( db . Integer ( ) , db . ForeignKey ( '<STR_LIT>' , ondelete = '<STR_LIT>' ) ) <EOL> db . create_all ( ) <EOL> db_adapter = SQLAlchemyAdapter ( db , User , UserProfileClass = UserProfile ) <EOL> user_manager = UserManager ( db_adapter , app ) <EOL> if not User . query . filter ( User . username == '<STR_LIT>' ) . first ( ) : <EOL> user_profile1 = UserProfile ( first_name = '<STR_LIT>' , last_name = '<STR_LIT>' ) <EOL> db . session . add ( user_profile1 ) <EOL> user1 = User ( user_profile = user_profile1 , username = '<STR_LIT>' , <EOL> email = '<STR_LIT>' , password = user_manager . hash_password ( '<STR_LIT>' ) , <EOL> active = True ) <EOL> db . session . add ( user1 ) <EOL> user_profile1 . roles . append ( Role ( name = '<STR_LIT>' ) ) <EOL> user_profile1 . roles . append ( Role ( name = '<STR_LIT>' ) ) <EOL> db . session . commit ( ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def home_page ( ) : <EOL> return render_template_string ( """<STR_LIT>""" ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ login_required <EOL> def members_page ( ) : <EOL> return render_template_string ( """<STR_LIT>""" ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ roles_required ( '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def special_page ( ) : <EOL> return render_template_string ( """<STR_LIT>""" ) <EOL> return app <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app = create_app ( ) <EOL> app . run ( host = '<STR_LIT>' , port = <NUM_LIT> , debug = True ) </s>
