Exemplo n.º 1
0
def add_agent():
    if request.method == 'POST':
        NewAgent = Agent(FirstName=request.form['FirstName'],
                         LastName=request.form['LastName'],
                         Password=bcrypt.generate_password_hash(
                             request.form['Password']).decode('utf-8'),
                         PhoneNumber=request.form['PhoneNumber'],
                         Address=request.form['Address'],
                         IdService=request.form['Service'],
                         Enabled=request.form['Status'],
                         Time=request.form['Time'],
                         lat=request.form['lat'],
                         lon=request.form['lon'])
        try:
            db.session.add(NewAgent)
            db.session.commit()
            flash(
                'Yes !! Agent inserted successfully. Great Job ' +
                current_user.FirstName + Happy, 'success')
            return redirect(url_for('agent.get_agent'))
        except Exception as err:
            flash(
                'No !! ' + Sad +
                ' Agent did not insert successfully . Please check insertion ',
                'danger')

    return redirect(url_for('agent.get_agent'))
Exemplo n.º 2
0
def register():
    if current_user.is_authenticated:
        return redirect (url_for('main.home'))
    form= RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf_8')
        user =  User(username = form.username.data, email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! you can be able to login','success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register', form=form)
Exemplo n.º 3
0
def edit_password_user(IdUser):
    if request.method == 'POST':
        EditUser = db.session.query(Users).filter_by(IdUser = IdUser).one()
        EditUser.Pasword = bcrypt.generate_password_hash(request.form['Pasword']).decode('utf-8')
        try :
            db.session.add(EditUser)
            db.session.commit()
            flash('Yes !! Password is edited successfully '+ Happy , 'success')
            return redirect(url_for('users.get_users'))
        except Exception as err :
            flash('No !! ' + Sad + ' Password did not edit successfully . Please check insertion ' , 'danger')

    return redirect(url_for('users.get_users'))
Exemplo n.º 4
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('dashboard'))

    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf8')
        dam = Dam.query.filter_by(name=form.dam.data).first()
        user = User(username=form.username.data, password=hashed_password, dam_id=dam.id)
        db.session.add(user)
        db.session.commit()
        flash("Your account has been created. You can now login", 'flash_success')

    return render_template("register.html", form=form)
Exemplo n.º 5
0
def add_device():
    form = DeviceForm()
    if form.validate_on_submit():
        api_key = secrets.token_urlsafe(32)
        hashed_key = bcrypt.generate_password_hash(api_key)
        device = Device(name=form.name.data,
                        mac=form.mac.data,
                        data_measured=form.data_measured.data,
                        api_key=hashed_key,
                        dam_id=current_user.works_at.id)
        db.session.add(device)
        db.session.commit()

        flash(f"API Key: {api_key}, Device Id: {device.id}", 'flash_success')

    return render_template("device.html", form=form)
Exemplo n.º 6
0
def edit_agent(IdAgent):
    if request.method == 'POST':
        EditAgent = db.session.query(Agent).filter_by(IdAgent=IdAgent).one()
        EditAgent.FirstName = request.form['FirstName']
        EditAgent.LastName = request.form['LastName']
        EditAgent.Password = bcrypt.generate_password_hash(
            request.form['Password']).decode('utf-8')
        EditAgent.PhoneNumber = request.form['PhoneNumber']
        EditAgent.Address = request.form['Address']
        EditAgent.IdService = request.form['Service']
        EditAgent.Enabled = request.form['Status']
        EditAgent.Time = request.form['Time']
        try:
            db.session.add(EditAgent)
            db.session.commit()
            flash('Yes !! Agent is edited successfully ' + Happy, 'success')
            return redirect(url_for('agent.get_agent'))
        except Exception as err:
            flash(
                'No !! ' + Sad +
                ' Agent did not edit successfully . Please check insertion ',
                'danger')

    return redirect(url_for('agent.get_agent'))
Exemplo n.º 7
0
def add_users():
    if request.method == 'POST':
        NewUser = Users(FirstName=request.form['FirstName'],
                        LastName=request.form['LastName'],
                        Email=request.form['Email'],
                        PhoneNumber=request.form['PhoneNumber'],
                        Address=request.form['Address'],
                        Pasword=bcrypt.generate_password_hash(
                            request.form['Pasword']).decode('utf-8'),
                        Enabled=request.form['Status'])
        try:
            db.session.add(NewUser)
            db.session.commit()
            flash(
                'Yes !! User inserted successfully. Great Job ' +
                current_user.FirstName + Happy, 'success')
            return redirect(url_for('users.get_users'))
        except Exception as err:
            flash(
                'No !! ' + Sad +
                ' User did not insert successfully . Please check insertion ',
                'danger')

        return redirect(url_for('users.get_users'))