示例#1
0
def login():
    if not request.is_json:
        return jsonify({"message": "Missing JSON in request"}), 400

    email = request.json.get('email', None)
    password = request.json.get('password', None)
    raspberry_id = request.json.get('raspberry_id', None)
    if raspberry_id:
        raspberry = Raspberry.query.filter_by(id=raspberry_id).first()
        if not raspberry:
            return jsonify({"message": "Bad raspberry pi id"}), 401
        ret = {
            'access_token': create_access_token(identity=raspberry.id),
        }
        return jsonify(ret), 200
    else:
        if not email:
            return jsonify({"message": "Missing email parameter"}), 400
        if not password:
            return jsonify({"message": "Missing password parameter"}), 400

        user = User.query.filter_by(email=email).first()
        if not user or not bcrypt.check_password_hash(user.password, password):
            return jsonify({"message": "Bad email or password"}), 401

        # Identity can be any data that is json serializable
        ret = {
            'access_token': create_access_token(identity=user.id),
            'user': user
        }
        return jsonify(ret), 200
示例#2
0
    def authenticate(cls, username, password):
        select_query = "SELECT `username`, `user_id`, `rating`, `password` from `user` WHERE `username` = %s"
        update_token_query = "UPDATE `user` SET `player_token` = %s WHERE `username` = %s"

        cur = mysql.connection.cursor(DictCursor)
        cur.execute(select_query, (username))
        rv = cur.fetchall()

        # check username exists
        if len(rv) != 1:
            return None
        user_data = rv[0]

        # check password
        pw_correct = bcrypt.check_password_hash(user_data["password"],
                                                password)
        if not pw_correct:
            return None

        # Generate new player-token for sessions
        new_player_token = uuid.uuid4()
        cur.execute(update_token_query, (new_player_token, username))

        return User(user_data["user_id"], new_player_token,
                    user_data["username"], user_data["rating"])
示例#3
0
 def post(self):
     if not request.json:
         return abort(
             403,
             description=
             'Brakujące argumenty, prosze wypełnić wszystkie pola.')
     loginData = {
         'username': request.json['username'],
         'password': request.json['password']
     }
     if not loginData['username'] or not loginData['password']:
         return abort(
             403,
             description=
             'Brakujące argumenty, prosze wypełnić wszystkie pola.')
     user = User.objects(username=loginData['username']).first()
     if user and bcrypt.check_password_hash(user.password,
                                            loginData['password']):
         login_user(user)
     else:
         return abort(
             403,
             description=
             'Dane logowania są niepoprawne! Spradz poprawność wprowadzonych danych!'
         )
     return jsonify(message='Zostałeś pomyślnie zalogowany do serwisu!')
示例#4
0
 def authenticate(cls, username, password):
     found_user = cls.query.filter_by(username=username).first()
     if found_user:
         authenticated_user = bcrypt.check_password_hash(
             found_user.password, password)
         if authenticated_user:
             return found_user
     return False
示例#5
0
文件: auth.py 项目: LSDkk5/asd
 def post(self):
     loginData = {
         'username': request.json['username'],
         'password': request.json['password']}
     user = User.query.filter_by(username=loginData['username']).first()
     if user and bcrypt.check_password_hash(
         user.password, loginData['password']):
         login_user(user)
     else:
         return abort(401, description='Dane logowania są niepoprawne! Spradz poprawność wprowadzonych danych!')
     return jsonify(message='Zostałeś pomyślnie zalogowany do serwisu!')
示例#6
0
文件: routes.py 项目: muk124/flaskp
def login():

    if current_user.is_authenticated:
        return redirect(url_for('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):
            login_user(user, remember=form.remember.data)
            return redirect(url_for('home'))
        else:
            flash('Login Unscusseful', 'danger')
    return render_template('login.html', title='login', form=form)
示例#7
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = Login()
    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 = request.args.get('next')
            return redirect(next) if next else redirect(url_for('home'))
        else:
            flash('Logged Failed check username and password', 'danger')
    return render_template('login.html', title='Login', form=form)
示例#8
0
def doctorlogin():
    form = LoginForm()
    if form.validate_on_submit():
        doctor = Doctor.query.filter_by(email=form.email.data).first()
        if doctor and bcrypt.check_password_hash(doctor.password,
                                                 form.password.data):
            login_user(doctor, remember=form.remember.data)
            return redirect(url_for('doctor_profile'))
        else:
            flash('Login Unsuccessful. Please check Email and Password',
                  'danger')

    #elif request.method == 'GET':
    #return redirect(url_for('doctor_login'))
    return render_template('doctorlogin.html', title='Login', form=form)
示例#9
0
文件: routes.py 项目: LSDkk5/app
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home.home_page'))
    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)
            flash('Zostałeś pomyślnie zalogowany!', 'info')
            return redirect(url_for('home.home_page'))
        else:
            flash(
                'Błędny login lub hasło, sprawdz poprawność wprowadzonych danych',
                'danger')
    return render_template('/auth/login.html', form=form)
示例#10
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    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)
            next_page = request.args.get('next')
            db.session.commit()
            return redirect(next_page) if next_page else redirect(
                url_for('index'))
        else:
            flash('Login Unsuccessful. Please check email and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)
示例#11
0
def patient_login():
    form = PatientLoginForm()
    global pname
    if form.validate_on_submit():
        patient = Patient.query.filter_by(email=form.email.data).first()

        if patient and bcrypt.check_password_hash(patient.password,
                                                  form.password.data):
            login_user(patient, remember=form.remember.data)
            form.email = patient.email
            print(patient.username)
            #return redirect(url_for('patient_profile'))
            pname = patient.username
            return render_template('PatientProfile.html', form=form)
        else:
            flash('Login Unsuccessful. Please check Email and Password',
                  'danger')
    return render_template('plogin.html', title='Login', form=form)
示例#12
0
 def verify_password(self, password):
     return bcrypt.check_password_hash(self.password_hash, password)