def test_login(self):
        username = "******"
        password = "******"
        hashed_password = bcrypt.hashpw(password.encode('utf8'),
                                        bcrypt.gensalt())

        with db_connection.create_connection(self.database_path) as conn:
            db_connection.create_user(conn, (username, hashed_password))

        self.login_session.login_user(username, password, self.database_path)

        self.assertTrue(self.login_session.logged_in, 'Not logged in')
def phone(update: Update, _: CallbackContext) -> int:
    not_validate = True
    user = update.message.from_user
    logger.info("phone of %s: %s", user.first_name, update.message.text)
    if not validate_phone(update.message.text):
        update.message.reply_text('נא הכנס מספר טלפון תקין המכיל 10 ספרות')
        return PHONE

    for item in sessions_data:
        if item['id'] == update.message.chat.id:
            item['details']['phone'] = update.message.text
            create_user(item['details'])

    update.message.reply_text('ההרשמה בוצעה בהצלחה. ניצור איתך קשר בהקדם!')
    print(sessions_data)

    return ConversationHandler.END
Beispiel #3
0
 def create_new_user(self, credentials: tuple, database: str = None):
     if database is None:
         database = self.database_path
     with db_connection.create_connection(database) as conn:
         user_id = db_connection.create_user(conn, credentials)
     self.user = User(user_id, credentials[0], credentials[1])
     self.logged_in = True
     print(f"User {self.user.user_id} with username {self.user.username} has been created and logged in.")
    def create_test_user(self):
        username = "******"
        password = "******"
        hashed_password = bcrypt.hashpw(password.encode('utf8'),
                                        bcrypt.gensalt())

        with db_connection.create_connection(self.database_path) as conn:
            user_id = db_connection.create_user(conn,
                                                (username, hashed_password))
            self.login_session.user = login.User(user_id, username,
                                                 hashed_password)
            self.login_session.logged_in = True
Beispiel #5
0
def insert_user():
    """Insert user page"""
    if request.method == "POST":
        username = request.form.get("username", "")
        password = request.form.get("password", "")
        email = request.form.get("email", "")
        is_admin = request.form.get("is_admin", "") == "on"

        if not password:
            return render_template("new_user.html",
                                   username=username,
                                   error="Invalid password")
        if create_user(username, password, email, is_admin) is False:
            # Name already in use
            return render_template("new_user.html",
                                   client_name=username,
                                   error="Username already in use")
        return redirect("/")
    else:
        return render_template("new_user.html", username="", error="")