Beispiel #1
0
def loginapi():
    json_data = request.json
    user = User.query.filter_by(email=json_data['email']).first()
    if user and bcrypt.check_password_hash(
            user.password, json_data['password']):
        session['logged_in'] = True
        status = True
        return jsonify(token=create_token(user)), 200
    else:
        status = False
        
    return jsonify({'result': status})
Beispiel #2
0
    def post(self):
        data = request.get_json(force=True)
        print(data)
        username = data['username']
        password = data['password']
        user = User.query.filter_by(username=username).first()
        if user == None:
            response = make_response(
                jsonify({"message": "invalid username/password"}))
            response.status_code = 401
            return response
        if bcrypt.check_password_hash(user.password, password):

            token = create_token(user)
            return {'token': token}
        else:
            response = make_response(
                jsonify({"message": "invalid username/password"}))
            response.status_code = 401
            return response
Beispiel #3
0
    def post(self):
        """
        This endpoint takes the login data from the Angular login form
        and returns a token or a login error
        """
        json_data = request.json
        user = User.query.filter_by(email=json_data['email']).first()
        if user is not None and bcrypt.check_password_hash(
                user.password, json_data['password']):
            status = True
            ret = {
                'token': create_access_token(identity=user.email, fresh=True),
                'refresh_token': create_refresh_token(identity=user.email)
            }
            return jsonify(ret)
        else:
            status = False
            return 'email or password is incorrect', 400

        return jsonify({'result': status})
Beispiel #4
0
 def check_password(self, value):
     """Check password."""
     return bcrypt.check_password_hash(self.password, value)
Beispiel #5
0
 def check_password(self, value):
     return bcrypt.check_password_hash(self.password, value)
 def check_password(self, value):
     return bcrypt.check_password_hash(self.password, value)
Beispiel #7
0
 def check_password(self, value):
     """Check password."""
     return bcrypt.check_password_hash(self.password, value)