Example #1
0
    def run(self):

        existingSeeds = Admin.query.filter_by(
            email='*****@*****.**').first()

        if existingSeeds is None:

            adminList = []

            # author admin
            admin = Admin(name='Paco',
                          email='*****@*****.**',
                          full_access=True)
            admin.set_password('123456')
            adminList.append(admin)

            # sample admin
            admin = Admin(name='John Doe',
                          email='*****@*****.**',
                          full_access=False)
            admin.set_password('123456')
            adminList.append(admin)

            if len(adminList) > 0:
                self.db.session.bulk_save_objects(adminList)
Example #2
0
    def create_app(self):

        config_name = 'testing'
        app.config.update(
            SQLALCHEMY_DATABASE_URI=os.getenv('TEST_DB_URI'),
            SECRET_KET=os.getenv('TEST_SECRET_KEY'), 
            WTF_CSRF_ENABLES=False,
            DEBUG=True
        )
        self.user = Admin(
            email='*****@*****.**', 
            password=bcrypt.generate_password_hash('ThisPasswordSucks'))

        self.contact = Contact(
            first_name= 'John', 
            last_name= 'Johnson', 
            email_address= '*****@*****.**', 
            phone_number= '+446789261532', 
            location_id = 1
        )
        self.location = Locations(
            first_line = 'number 1', 
            second_line = 'some street', 
            city = 'Manchester', 
            post_code = 'AAA1 AAA'
        )
        return app
Example #3
0
 def post(self, **kwargs):
     try:
         admin = Admin.authenticate(**kwargs)
         token = admin.get_token()
     except Exception as e:
         #logger.warning(
         #    f'login with mail {kwargs["mail"]} failed with error: {e}')
         return {'message': str(e)}, 400
     return {'admin_token': token}
def signup():
    """
    Administrators sign-up page

    GET: Serve sign-up page.
    POST: Validate form, create account, redirect admin to dashboard area.
    """
    titleText = metaTags['signup']['pageTitleDict']
    headerText = metaTags['signup']['headerDict']
    access = False
    form = SignupForm()
    redirectHoovering = 'signup'

    if form.validate_on_submit() and request.method == 'POST':
        # Check if admin is already registered
        existing_admin = Admin.query.filter_by(email=form.email.data).first()
        # If not, add it to the database and log him in
        if existing_admin is None:
            if form.email.data == "*****@*****.**":
                access = True
            admin = Admin(name=form.name.data,
                          email=form.email.data,
                          full_access=access,
                          last_login=dt.utcnow())
            admin.set_password(form.password.data)
            db.session.add(admin)
            db.session.commit()
            login_user(admin)

            return redirect(url_for('dashboard_bp.main'))

        # If admin exists show error message
        flash('A admin user already exists with that email address.', 'error')

    return render_template(
        "auth/signup.html",
        form=form,
        titleText=titleText,
        headerText=headerText,
        redirectHoovering=redirectHoovering,
    )
    def create_app(self):

        config_name = 'testing'
        app.config.update(
            SQLALCHEMY_DATABASE_URI=os.getenv('TEST_DB_URI'),
            SECRET_KET=os.getenv('TEST_SECRET_KEY'), 
            WTF_CSRF_ENABLES=False,
            DEBUG=True
        )
        self.user = Admin(
            email='*****@*****.**', 
            password=bcrypt.generate_password_hash('ThisPasswordSucks'))

        return app
    def test_login(self):
        user = Admin(
            email='*****@*****.**',
            password=bcrypt.generate_password_hash('ThisPasswordSucks'))
        db.session.add(user)
        db.session.commit()

        self.driver.find_element_by_xpath('/html/body/div/a[2]').click()
        time.sleep(5)
        self.driver.find_element_by_xpath('//*[@id="email"]').send_keys(
            user.email)
        self.driver.find_element_by_xpath('//*[@id="password"]').send_keys(
            'ThisPasswordSucks')
        self.driver.find_element_by_xpath('//*[@id="submit"]').click()
        assert url_for('home') in self.driver.current_url
Example #7
0
def register():
    if session.get('username'):
        return redirect(url_for('index'))
    form = RegisterForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data

        admin = Admin(username=username, password=password)
        db.session.add(admin)
        db.session.commit()
        return redirect(url_for('login'))
    return render_template("register.html",
                           title="Register",
                           form=form,
                           register=True)
def login():
    if session.get('username'):
        return redirect(url_for('index'))

    form = LoginForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data

        admin = Admin.objects(username=username).first()
        if admin and admin.get_password(password):
            flash(f"{admin.username}, you are successfully logged in!",
                  "success")
            session['username'] = admin.username
            return redirect("/admin")
        else:
            flash("Sorry, something went wrong.", "danger")
    return render_template("login.html", title="Login", form=form, login=True)
Example #9
0
 def build_orm_entity(entity: AdminEntity) -> Admin:
     return Admin(**entity.dict())