Example #1
0
 def initialize(self, *a, **kw):
     webapp2.RequestHandler.initialize(self, *a, **kw)
     self.user = None
     uid = self.read_secure_cookie(self._cookie_name_user_id)
     self.user = uid and User.by_id(int(uid))
     if not self.user:
         self.del_cookie_user()
Example #2
0
def register():
    user = User(request.form['username'], request.form['password'],
                request.form['email'])
    db.session.add(user)
    db.session.commit()
    flash('User successfully registered')
    # TODO add an email confirmation
    return redirect(url_for('login'))
Example #3
0
    def post(self):
        user_name = self.request.get(self._id_username)
        user_password = self.request.get(self._id_password)
        user = None
        
        if user_name and user_password:
            user = User.get_verified_user(user_name, user_password)

        if user:
            self.set_cookie_user(user.key().id())
            self.redirect('/')
        else:
            template_values = {self._tp_login_error_msg: 'Invalid login'}
            self.render_front(self.set_template_values(template_values))
Example #4
0
 def post(self):
     user_name = self.request.get(self._id_username)
     user_password = self.request.get(self._id_password)
     user_verify = self.request.get(self._id_verify)
     user_email = self.request.get(self._id_email)
     
     newuser, val_errors = User.create_user(user_name, user_password, user_verify, user_email)
     
     if not newuser:
         templates_values = {self._tp_username: user_name, self._tp_email: user_email}
         self._set_error_msgs(val_errors, templates_values)
         self.render_front(self.set_template_values(templates_values))
     else:
         self.set_cookie_user(newuser.key().id())
         self.redirect('/')
Example #5
0
def populate():
    init_db()

    # populate all tables
    result = vol_reader("../data/vols.csv")
    #print(result)
    for line in result:
        vol = Vol(line['date'], line['heure'], line['noVol'],
                  line['noVol'][:2], line['aeronef'], line['od'],
                  line['secteur'], line['status'])
        db.session.add(vol)
    db.session.commit()

    result = airport_reader("../data/airports.csv")
    for line in result:
        airport = Airport(line['city'], line['airportCode'], line['level2'],
                          line['level3'])
        db.session.add(airport)
    db.session.commit()

    result = fc_reader("../data/fc.csv")
    for line in result:
        fc = FlightCompany(line['fc'])
        db.session.add(fc)
    db.session.commit()

    result = cap_pool_reader("../data/cap_pool.csv")
    for line in result:
        cap_pool = CapPool(line['cap_pool_name'])
        db.session.add(cap_pool)
    db.session.commit()

    result = cap_horaire_reader("../data/cap_horaire.csv")
    for line in result:
        cap_horaire = CapHoraire(line['cap_value'], line['cap_timestamp'],
                                 line['user_id'])
        db.session.add(cap_horaire)
    db.session.commit()

    result = group_reader("../data/group.csv")
    for line in result:
        priority_group = Group(line['fc_code'], line['group_name'],
                               line['group_type'], line['group_class'])
        db.session.add(priority_group)
    db.session.commit()

    result = regle_aff_reader("../data/tbl_algo_regles_affaire.csv")
    for line in result:
        regle_aff = RegleAff(line['drag_capacity_from'],
                             line['drag_capacity_to'], line['drag_type'],
                             line['drag_value'], line['propagation'],
                             line['condition_type'], line['condition_value'])
        db.session.add(regle_aff)
    db.session.commit()

    result = populateUser("../data/users.csv")
    for line in result:
        user = User(line['username'], line['password'], line['email'])
        #print(line['isAdmin'])
        db.session.add(user)
        if (line['isAdmin'].lower() == 'true'):
            db.session.commit()
            user = User.query.filter_by(username=line['username']).first()
            admin = Admin(user.id)
            db.session.add(admin)
        if (line['isNav'].lower() == 'true'):
            db.session.commit()
            user = User.query.filter_by(username=line['username']).first()
            nav = Nav(user.id)
            db.session.add(nav)
        if (line['fc'] != ''):
            db.session.commit()
            user = User.query.filter_by(username=line['username']).first()
            nav = User_Fc(user.id, line['fc'])
            db.session.add(nav)

    db.session.commit()

    result = priorite_reader("../data/priorite.csv")
    for line in result:
        #print(line)
        priorite = Priorite(line['fc_code'], line['group_id'], line['rank'])
        db.session.add(priorite)
        #print(priorite)
    db.session.commit()

    return redirect(url_for('index'))
Example #6
0
app.secret_key = 'super secret key'

app.config['SQLALCHEMY_DATABASE_URI'] = postUrl
db.init_app(app)

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'

CORS(app)

# TODO with postgresql
h = md5()
h.update(b'user123')
h.hexdigest()
u = User("default", h.hexdigest(), "*****@*****.**")
userlist = [u]
print(u in userlist)


@login_manager.user_loader
def load_user(id):
    return User.query.get(ord(id))


@app.route('/')
def index():
    return "Hello, World!"


@app.route('/assets', methods=['GET'])