Exemplo n.º 1
0
 def mergeWithDefaultStatistics(statistics, defaultStatistics,
                                appendToDefaultStatistics,
                                hideStatisticsByDefault):
     if not hideStatisticsByDefault and not statistics:
         Print.logWarning(
             'Please provide \'statistics\' keyword for all relevant pages')
     if statistics is None or not defaultStatistics:
         return statistics
     if isinstance(statistics, str):
         defaultStatistics['title'] = statistics
         return defaultStatistics
     if not appendToDefaultStatistics:
         return statistics
     s = {
         'substatistics': [],
     }
     if 'key' in statistics:
         s['key'] = statistics['key']
     if 'title' in statistics:
         s['title'] = statistics['title']
     if not 'substatistics' in statistics and 'substatistics' in defaultStatistics:
         if 'key' in defaultStatistics:
             s['key'] = defaultStatistics['key']
         if 'title' in defaultStatistics:
             s['title'] = defaultStatistics['title']
     s['substatistics'].extend(StatisticsTools.statisticsToList(statistics))
     s['substatistics'].extend(
         StatisticsTools.statisticsToList(defaultStatistics,
                                          prefixToKey='default'))
     return s
Exemplo n.º 2
0
 def init(app, password):
   if password is None:
     Print.log('No password for the statistics website provided. The')
     Print.log2('page will be disabled.')
   elif not Authenticate._validPassword(password):
     Print.logWarning('The password for the statistics websites needs to be')
     Print.log2Warning('six characters in length at the minimum. The page will')
     Print.log2Warning('be disabled.')
   app.config.update(SECRET_KEY='Empiric!', USE_SESSION_FOR_NEXT=True)
   loginManager = LoginManager()
   loginManager.init_app(app)
   loginManager.login_view = 'login'
   defaultUser = '******'
   class User(UserMixin):
     def __init__(self, username):
       self.id = username
     def __repr__(self):
       return self.username
   @app.route('/login', methods=['GET', 'POST'])
   def login():
     if request.method == 'POST':
       if 'password' in request.form and Authenticate._validPassword(password) and request.form['password'] == password:
         login_user(User(defaultUser))
         return redirect(url_for('statistics'))
       else:
         return render_template('login.html', message='Wrong password. Please try again.')
     elif request.method == 'GET':
       return render_template('login.html')
     return render_template('login.html', message='Bad login request.')
   @app.route('/logout')
   @login_required
   def logout():
     logout_user()
     return redirect(url_for('login'))
   @loginManager.user_loader
   def loader_user(username):
     return User(username)