コード例 #1
0
def authenticate(username, password):
    #user = username_mapping.get(username,None)
    user = UserModel.find_by_username(username)
    #if user and user.password = password:
    if user and safe_str_cmp(user.password, password):
        #return {"Good Job": user}
        return user
コード例 #2
0
    def post(self):
        data = UserRegister.parser.parse_args()

        if UserModel.find_by_username(data['username']):
            return {"message": "A user with that username already exists"}, 400

        user = UserModel(data['username'], data['password'])
        user.save_to_db()

        return {"message": "User created successfully"}, 201
コード例 #3
0
    def post(self):

       data = UserRegister.parser.parse_args()
       if  UserModel.find_by_username(data['username']):
            return {"message":"User name already exist"}, 400
       user = UserModel(data['username'], data['password']) # OR Just user = UserModel(**data)
       user.save_to_db()

        #connection = sqlite3.connect('samdata.db')
       # cursor = connection.cursor()
       #
       # query = " INSERT INTO users VALUES (NULL, ?, ?)"
       # cursor.execute(query,( data['username'], data['password']) )
       # connection.commit()
       # connection.close()

       return {"message": "User created sucessfully"}, 201
コード例 #4
0
    def post(self):
        data = parser.parse_args()

        if UserModel.find_by_username(data["username"]):
            return {"message": f"User {data['username']} already exists!"}, 400

        new_user = UserModel(username=data["username"],
                             password=UserModel.generate_hash(
                                 data["password"]))
        try:
            new_user.save_to_db()
            access_token = create_access_token(identity=data["username"])
            refresh_token = create_refresh_token(identity=data["username"])
            return {
                "message": f"User {data['username']} was created!",
                "access_token": access_token,
                "refresh_token": refresh_token,
            }, 200
        except Exception as e:
            print(f"DEBUG: {e}")
            return {"message": "Something went wrong"}, 500
コード例 #5
0
    def post(self):
        data = parser.parse_args()
        current_user = UserModel.find_by_username(data["username"])

        if not current_user:
            return {"message": f"User {data['username']} does not exist!"}, 401

        try:
            if UserModel.verify_hash(data["password"], current_user.password):
                access_token = create_access_token(identity=data["username"])
                refresh_token = create_refresh_token(identity=data["username"])
                return {
                    "message": f"Logged as {current_user.username}",
                    "access_token": access_token,
                    "refresh_token": refresh_token,
                }, 200
        except Exception as e:
            print(f"DEBUG: {e}")
            return {"message": "Something went wrong."}, 500

        else:
            return {"message": "Wrong credentials"}, 401
コード例 #6
0
def authenticate(username, password):
    user = UserModel.find_by_username(username)
    # safe_str_cmp function provides safe string comparison
    if user and safe_str_cmp(user.password, password):
        return user