예제 #1
0
    def put(self, device_id):
        device = Device.query.filter_by(id=device_id).first()
        if device:
            args = data_args.parse_args()
            if bcrypt.check_password_hash(device.api_key, args['api_key']):
                if args.get('timestamp'):
                    data = Data(data=args['data'],
                                device_id=device_id,
                                timestamp=datetime.datetime.strptime(
                                    args['timestamp'], "%Y-%m-%d %H:%M:%S"))
                else:
                    cur_time_str = datetime.datetime.now().strftime(
                        "%Y-%m-%d %H:%M:%S")
                    data = Data(data=args['data'],
                                device_id=device_id,
                                timestamp=datetime.datetime.strptime(
                                    cur_time_str, "%Y-%m-%d %H:%M:%S"))
                db.session.add(data)
                db.session.commit()
            else:
                abort({'message': 'Invalid API Key', 'success': 0})
        else:
            abort({'message': 'Invalid device id', 'success': 0})

        return {'message': 'Data successfully added', 'success': 1}, 201
예제 #2
0
def login():
    data = request.json
    email = data.get("email")
    password = data.get("password")

    user = User.query.filter_by(email=email).first()
    if user and bcrypt.check_password_hash(user.password, password):
        login_user(user)
        return jsonify({"login": True, "role": user.role, "author": user.name})

    else:
        return jsonify({"login": False})
예제 #3
0
파일: routes.py 프로젝트: zahraSG/PlAIster
def login():
    if current_user.is_authenticated:
        return redirect (url_for('main.home'))
    form= LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):  # if the user exists and the password that is entered is valid with what is saved in the databse log the user in
            login_user(user, remember = form.remember.data)
            return redirect(url_for('main.home'))
        else:
            flash('Login Unsuccessful, Please check email and password','danger')
    return render_template('login.html', title='login', form=form)
예제 #4
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    if request.method == 'POST':
        User = db.session.query(Users).filter_by(
            Email=request.form['Email']).first()
        if User and bcrypt.check_password_hash(User.Pasword,
                                               request.form['Pasword']):
            login_user(User)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(
                url_for('main.index'))
        else:
            return render_template('login.html')
    return render_template('login.html')
예제 #5
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('dashboard'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            flash(f'Hi {user.name}, you have been logged in.', 'success')
            return redirect(url_for('dashboard'))
        else:
            flash('Login Unsuccessful. Please check email and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
예제 #6
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('dashboard'))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(url_for('dashboard'))
        else:
            flash("Incorrect username or password", 'flash_fail')

    return render_template("login.html", form=form)