Exemplo n.º 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")
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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))
Exemplo n.º 8
0
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")  
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
Exemplo n.º 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
Exemplo n.º 11
0
def authenticate(username, password):
    user = UserModel.find_by_username(username)

    if user and user.password == password:
        return user
Exemplo n.º 12
0
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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 15
0
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
Exemplo n.º 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
Exemplo n.º 17
0
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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 20
0
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
Exemplo n.º 21
0
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
Exemplo n.º 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
Exemplo n.º 23
0
def authenticate(username, password):
    user = UserModel.find_by_username(username)
    if user and safe_str_cmp(user.password, password):
        return user
Exemplo n.º 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