コード例 #1
0
def login_user():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        user = UserModel.find_by_username(username)

        try:
            #if user and safe_str_cmp(password, user.password):
            if user and Utils.check_hashed_password(password, user.password):
                session['username'] = user.username
                if user.username in current_app.config.get('ADMIN',
                                                           '').split(','):
                    session['admin'] = True
                else:
                    session['admin'] = None

                return redirect(url_for("webmodels.index"))
            else:
                session['username'] = None
                session['admin'] = None
                return "Invalid credentials! please try again."
        except:
            session['username'] = None
            session['admin'] = None
            return "Invalid credentials! please try again."

    return render_template("users/login.html")
コード例 #2
0
def authenticate(username, password):
    user = UserModel.find_by_username(username)  # PostgrsqlDB User Model
    userDynamoDB = UserModelDynamoDB.find_by_username(
        username)  # aws Dynamo DB User Model
    # user = username_mapping.get(username, None)
    if userDynamoDB and userDynamoDB.password == password:
        return userDynamoDB
コード例 #3
0
def authenticate(username, password):
    user = UserModel.find_by_username(username)
    print("coba ya")
    if user and safe_str_cmp(
            user.password, password
    ):  # this is simple way for not  using safe_str_cmp"if user and user.password == password :"******"bisa nih")
        return user
コード例 #4
0
def authenticate(username, password):
    #.get() gets values of te key 'username'; useful for setting a default value
    #username_mapping['username'] <-- similar to .get without having a default
    #user = username_mapping.get(username, None) #replacing userid_mapping with database

    user = UserModel.find_by_username(username)
    if user and safe_str_cmp(user.password, password):
        return user
コード例 #5
0
def authenticate(
    username, password
):  ## This is used at the beginning that is when authenticating initially
    #user=username_mapping.get(username,None) # if there is no key for this username, it would return None
    user = UserModel.find_by_username(username)

    if user and safe_str_cmp(user.password, password):
        #safe_str_cmp(a,b) takes care of different encoding schemes used by a and b and compares them
        return user
コード例 #6
0
def authenticate(username, password):
    #   user = username_mapping.get(username)
    # .get will return a value from a dictionary, and "None" is a default value, if
    # there is no user returned

    user = UserModel.find_by_username(username)

    if user and safe_str_cmp(
            user.password,
            password):  # was before:    user.password == password:
        return user
コード例 #7
0
    def test_register_user(self):
        with self.app() as client:
            with self.app_context():
                response = client.post('/register',
                                       data={
                                           'username': '******',
                                           'password': '******'
                                       })

                self.assertEqual(response.status_code, 201)
                self.assertIsNotNone(UserModel.find_by_username('test'))
                self.assertDictEqual({'message': 'User created successfully.'},
                                     json.loads(response.data))
コード例 #8
0
ファイル: web_user.py プロジェクト: ramchakka/flask_compose
def register_user():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        #email = request.form['email']

        if UserModel.find_by_username(username):
            return "Username already exists! Try with another name."
        else:
            hashed_password=Utils.hash_password(password)
            user = UserSchema().load({"username":username, "password":hashed_password})
            user.save_to_db()
            session['username'] = user.username
            return redirect(url_for("webmodels.index"))

    return render_template("users/register.html")  
コード例 #9
0
def authenticate(username, password):
    user = UserModel.find_by_username(
        username)  #using the Class.method(argument)
    if user and safe_str_cmp(user.password, password):
        return user
コード例 #10
0
def authenticate(username, password):
    # user = username_mapping.get(username, None)
    user = UserModel.find_by_username(username)
    if user is not None and safe_str_cmp(user.password, password):
        return user
コード例 #11
0
def authenticate(username, password):
    user = UserModel.find_by_username(username)

    if user and user.password == password:
        return user
コード例 #12
0
ファイル: security.py プロジェクト: vikramshinde12/flask
def authenticate(username, password):
    user = UserModel.find_by_username(username)
    print(f'I am calling in authentication of {username}')
    print(user)
    if user and user.password == password:
        return user
コード例 #13
0
def authenticate(username, password):
    user = UserModel.find_by_username(username)
    if user and bcrypt.checkpw(password.encode('utf-8'), user.password):
        return user
コード例 #14
0
def authenticate(username, password):
    user = UserModel.find_by_username(username)
    if user and safe_str_cmp(
            user.password,
            password):  # safer way to compare strings in different encodings
        return user
コード例 #15
0
ファイル: security.py プロジェクト: uchenna-j-edeh/genericAPI
def authenticate(username, password):
    user = UserModel.find_by_username(username)
    if user and safe_str_cmp(user.password, password):
        return user  # Everything is alright. So generate a JWT token
コード例 #16
0
def authenticate(username, password):
    # getting username from database
    user = UserModel.find_by_username(username)
    if user and safe_str_cmp(user.password, password):
        return user
コード例 #17
0
ファイル: security.py プロジェクト: Gatolini/rest-api
def authenticate(username,password):
    user = UserModel.find_by_username(username)
    # in this case, we are using the Model, not the Resource
    if user and safe_str_cmp(user.password, password):
        # to avoid problems in different characters sets or python version
        return user
コード例 #18
0
def authenticate(username, password):
    user = UserModel.find_by_username(username)
    if user and safe_str_cmp(
            user.password,
            password):  # safe_str_cmp() helps in comparing string safely
        return user
コード例 #19
0
def authenticate(username, password):
    user = UserModel.find_by_username(
        username)  #if username_mapping finds nothing, we return None
    if user and safe_str_cmp(user.password, password):
        return user
コード例 #20
0
ファイル: security.py プロジェクト: fastgrowing/flaskcourse
def authenticate(username, password):
    user = UserModel.find_by_username(
        username)  # using get we can set default value
    if user and safe_str_cmp(user.password, password):
        return user
コード例 #21
0
ファイル: security.py プロジェクト: zazyzm/dbcourse
def authenticate(username, password):
    user = UserModel.find_by_username(username)
    # print(f'username: {username}, password: {password}')
    # if user and safe_str_cmp(user.password, password):
    if user and user.password == password:
        return user
コード例 #22
0
def authenticate(username: str, password: str) -> Optional[UserModel]:
    user = UserModel.find_by_username(username)
    if user and safe_str_cmp(password.encode('utf-8'), user.password.encode('utf-8')):
        return user
    else:
        return None
コード例 #23
0
def authenticate(username, password):
    user = UserModel.find_by_username(username)
    if user and safe_str_cmp(user.password, password):
        return user
コード例 #24
0
def authenticate(username, password):
    # if no user found return none
    user = UserModel.find_by_username(username)
    # safer way of comparing strings, taking care of any encoding problems
    if user and safe_str_cmp(user.password, password):
        return user