コード例 #1
0
 def test_email_sent(self):
     name = 'user'
     password = '******'
     active = True
     roles = ['Admin']
     authentication_method = 'hash'
     os.remove("users.json")
     user_manager = UserManager('')
     hash_user = user_manager.add_user(name, password, active, roles,
                                       authentication_method)
     hash_user.set('authenticated', True)
     hash_user.set('email', '*****@*****.**')
     url = "test"
     alreadySub = False
     with open("content/subscriptions.txt", mode='r') as contacts_file:
         for a_contact in contacts_file:
             if (a_contact.split()[1] == str(hash_user.get_id())):
                 if (a_contact.split()[0] == str(url)):
                     alreadySub = True
     if (not alreadySub):
         f = open('content/subscriptions.txt', 'a+')
         f.write(u'' + url + ' ' + str(hash_user.get_id()) + '\n')
         f.close()
     is_caught = False
     try:
         email(url, hash_user)
     except:
         is_caught = True
     assert is_caught is False
コード例 #2
0
    def test_new_json_file(self):
        """
            Tests creating a new json file, and tries to create a new file when one is already made
        """
        um = UserManager("")

        um = UserManager("")
コード例 #3
0
ファイル: routes.py プロジェクト: konzy/CSC440-Wiki-Project
def newUser(url):
    val = request.form['value']
    vals = val.split(",")
    name = vals[0].lstrip().rstrip()
    password = vals[1].lstrip().rstrip()
    new = UserManager('user')
    new.add_user(name, password)
    return redirect(url)
コード例 #4
0
def user_create():
    username = request.form.get('name')
    password = request.form.get('password')
    m = UserManager(current_app.config['USER_DIR'])
    if not m.add_user(username, password, authentication_method='cleartext'):
        flash("Error creating user. Try again.", "error")
        return redirect(url_for('wiki.user_signup'))
    else:
        return redirect(url_for('wiki.user_login'))
コード例 #5
0
def user_delete():
    form = UnregisterForm()
    if form.validate_on_submit():
        user = UserProfile('user.db')
        user.delete_profile(form.name.data)
        manager = UserManager('users.json')
        manager.delete_user(form.name.data)
        current_users.delete_user(form.name.data)
        flash('User deleted.', 'success')
        return redirect(request.args.get("next") or url_for('wiki.index'))
    return render_template('unregister.html', form=form)
コード例 #6
0
    def test_add_favorite(self):
        """
            Make sure the add favorite works
        """
        manager = UserManager("hash", "tests")

        user = manager.get_user("testUser1")
        url = "testURL"
        title = "testTitle"
        favorite = Favorites()
        response = favorite.add_favorite(user.name, url, title)
        assert True (response)
コード例 #7
0
    def test_user_get(self):
        """
            Tests creating a user with cleartext password
        """
        username = "******"
        password = "******"
        um = UserManager("")

        cleartext_user = um.add_user(username, password, True, ["admin"],
                                     "cleartext")

        assert um.get_user(username) is not None
コード例 #8
0
    def test_user_creation_cleartext(self):
        """
            Tests creation of a user using UserManager
        """
        username = "******"
        password = "******"
        um = UserManager("")

        cleartext_user = um.add_user(username, password, True, ["admin"],
                                     "cleartext")

        assert cleartext_user is not None
コード例 #9
0
    def test_same_name(self):
        """
            Tests whether you can create two users with the same name
        """
        username = "******"
        password = "******"
        um = UserManager("")

        cleartext_user = um.add_user(username, password, True, ["admin"],
                                     "cleartext")

        assert cleartext_user is not None
コード例 #10
0
    def test_user_creation_hash(self):
        """
            Tests creating a user with hashed password
        """
        # print(os.getcwd())

        username = "******"
        password = "******"
        um = UserManager("")

        hash_user = um.add_user(username, password, True, ["admin"], "hash")

        assert hash_user is not None
コード例 #11
0
    def test_get_favorites(self):
        """
            Make sure the get favorites works
        """
        manager = UserManager("hash", "tests")

        user = manager.get_user("testUser1")
        url = "testURL"
        title = "testTitle"
        favorite = Favorites()
        favorite.add_favorite(user.name, "test", "test")
        fav_pages = favorite.get_favorites(user.name)
        size = len(fav_pages)
        assert size > 0
コード例 #12
0
    def test_user_update(self):
        """
        Tests updating a user
        """
        username = "******"
        password = "******"
        um = UserManager("")

        cleartext_user = um.add_user(username, password, True, ["admin"],
                                     "cleartext")

        data = cleartext_user.data

        um.update(username, data)
コード例 #13
0
ファイル: routes.py プロジェクト: Mike-Huber/Projects
def delete_user():
    user = UserManager('')
    if request.method == 'GET':
        return render_template('user_delete.html')
    elif request.method == 'POST':
        username = request.form['username']
        if not user.get_user(username):
            flash('Deleted user successfully', 'success')
            user.delete_user(username)
        else:
            flash('Error deleting user', 'failure')
        return render_template('settings.html')
    else:
        flash('Something went horribly wrong, redirected to home page.', 'failure')
        return render_template('home.html')
コード例 #14
0
def user_update(user_name):
    usermanager = UserManager(current_app.config["USER_DIR"])
    user = usermanager.get_user(user_name)
    form = UserForm()

    if form.validate_on_submit():
       
        if form.admin.data:
            userdata = {"active": True, "authentication_method": "cleartext", "password":form.password.data, "authenticated": True, "roles":['admin']}
        else:
            userdata = {"active": True, "authentication_method": "cleartext", "password":form.password.data, "authenticated": True, "roles":[]}
        usermanager.update(user_name, userdata)
        return redirect(url_for("wiki.user_index"))

    return render_template('update.html', form = form, user_name = user_name, password = user.get('password'))
コード例 #15
0
ファイル: connor_test.py プロジェクト: heilgraeham/CheekiWiki
class TestUser(WikiBaseTestCase):

    dir_path = os.path.dirname(os.path.realpath(__package__))
    user = UserManager(dir_path + '/user/')

    def test_get_user(self):
        assert 'name' == self.user.get_user('name').name

    def test_check_password(self):
        assert self.user.get_user('name').check_password('1234') is True
        assert self.user.get_user('name').check_password('4321') is False

    def test_add_user(self):
        assert self.user.add_user('name', '5678') is False

    def test_update(self):
        rand = random()
        user = self.user.get_user('test')
        data = {
            u'active': False,
            u'authentication_method': u'cleartext',
            u'password': str(rand),
            u'authenticated': True,
            u'roles': ['unit test']
        }
        self.user.update(user.name, data)
        assert self.user.get_user(user.name).data == data
コード例 #16
0
    def test_not_implemented_auth(self):
        """
            Tests the encryption scheme not implemented exception
        """
        username = "******"
        password = "******"
        um = UserManager("")

        is_caught = False

        try:
            um.add_user(username, password, True, ["admin"], "asdf")
        except NotImplementedError:
            is_caught = True

        assert is_caught is True
コード例 #17
0
    def test_get_user(self):
        """
            Assert that users are retrieved and data is correct
        """
        manager = UserManager("hash", "tests")

        user = manager.get_user("testUser1")
        assert user is not None
        assert user.name == "testUser1"
        assert user.get("password") == "password1"
        assert user.get("roles") == []

        user2 = manager.get_user("testUser2")
        assert user2 is not None
        assert user2.name == "testUser2"
        assert user2.get("password") == "password2"
        assert user2.get("roles") == ["testRole1", "testRole2"]
コード例 #18
0
 def test_invalid_authentication_method(self):
     m = UserManager(TestFilePath)
     self.assertRaises(NotImplementedError,
                       m.add_user,
                       m,
                       'Elizabeth',
                       12345,
                       authentication_method='this will cause an error')
コード例 #19
0
def makeUser():
    try:
        name = request.form['username']
        password = request.form['password']
        newUser = UserManager('user')
        newUser.add_user(name, password)
        flash('User created.', 'success')
        return redirect(url_for('wiki.home'))
    except RuntimeError:
        newUser = UserManager('user')
        newUser.add_user('test', 'testpassword')
        return
コード例 #20
0
ファイル: routes.py プロジェクト: tieugene/wiki
def user_create():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = form.name.data
        password = form.password.data
        UserManager(current_app.config['CONTENT_DIR']).add_user(
            name=user, password=password)
        # user.set('authenticated', True)
        flash('Registration successful.', 'success')
        return redirect(request.args.get("next") or url_for('wiki.index'))
    return render_template('register.html', form=form)
コード例 #21
0
    def test_simple_user(self):
        """
            Assert a simple User is created correctly.
        """
        name = 'Hash'
        password = '******'
        active = True
        roles = ['Admin']
        authentication_method = 'hash'
        user_manager = UserManager('')
        hash_user = user_manager.add_user(name, password, active, roles,
                                          authentication_method)

        assert hash_user.is_active()

        assert hash_user.is_authenticated() is False

        hash_user.set('authenticated', True)
        assert hash_user.get('authenticated')

        assert hash_user.get_id() == name

        assert hash_user.is_anonymous() is True

        assert hash_user.check_password(password)

        name2 = 'Test2'
        authentication_method2 = 'cleartext'
        clear_user = user_manager.add_user(name2, password, active, roles,
                                           authentication_method2)
        assert clear_user.check_password(password)

        assert hash_user.check_password('hi') is False

        hash_user.set('authentication_method', 'hi')
        is_caught = False
        try:
            hash_user.check_password('hi')
        except NotImplementedError:
            is_caught = True
        assert is_caught
コード例 #22
0
ファイル: routes.py プロジェクト: starrn1/SEWiki
def user_create():
    form = CreateUserForm()
    if form.is_submitted():
        if form.username.data == '':
            flash('You must enter a username!', 'error')
            return render_template('createuser.html', form=form)
        if form.password.data == '':
            flash('You must enter a password!', 'error')
            return render_template('createuser.html', form=form)
        um = UserManager(config.USER_DIR)
        user = um.add_user(form.username.data, form.password.data)
        if user == False:
            flash('That username is already in use!')
            return render_template('createuser.html', form=form)
        login_user(user)
        user.set('authenticated', True)
        user.set('active', True)
        flash('Login successful.', 'success')
        return redirect(request.args.get("next") or url_for('wiki.home'))

    return render_template('createuser.html', form=form)
コード例 #23
0
def user_index():
    user = current_users
    usermanager = UserManager.read(user)

    if 'admin' not in current_user.get("roles") :
        flash("You do not have the permissions to see this page")
        return render_template('index.html')

    if current_user.get("roles") != ["admin"]:
        flash("You do not have the permissions to see this page")
        return render_template('index.html')


    return render_template('user.html', usermanager = usermanager)
コード例 #24
0
    def test_user_delete(self):
        """
            Tests deleting a user
        """
        username = "******"
        password = "******"
        um = UserManager("")

        cleartext_user = um.add_user(username, password, True, ["admin"],
                                     "cleartext")

        assert um.get_user(username) is not None

        um.delete_user(username)

        assert um.get_user(username) is None

        assert um.delete_user("user never has been created") is False
コード例 #25
0
    def test_user_read_write_json(self):
        """
            Tests reading and writing back a json users file
        """
        um = UserManager("")
        json = um.read()

        assert json is not None

        um.write(json)

        assert um.read() is not None
コード例 #26
0
ファイル: routes.py プロジェクト: Mike-Huber/Projects
def user_create():
    user = UserManager('')
    if request.method == 'GET':
        return render_template('user_add.html')
    elif request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        if not username:
            flash('Username cannot be blank!', 'failure')
        elif not password:
            flash('Password cannot be blank!', 'failure')
        else:
            user.add_user(username, password)
            if user.get_user(username):
                print user.get_user(username).name
                flash('Created user successfully', 'success')
            else:
                flash('Error creating user, try again', 'failure')
        return render_template('settings.html')
    else:
        flash('Something went horribly wrong, redirected to home page.', 'failure')
        return render_template('home.html')
コード例 #27
0
def user_create():
    form = UserForm()
    user = UserManager(current_app.config['USER_DIR'])


    if form.validate_on_submit():
        if form.admin.data:
            roles = ['admin']
        else:
            roles = ''
        user.add_user(form.name.data, form.password.data, True, roles, form.authenticationMethod.data)
        return redirect(url_for("wiki.user_index"))

    if form.validate_on_submit():
        if form.admin.data:
            roles = ['admin']
        else:
            roles = ''
        user.add_user(form.name.data, form.password.data, True, roles, None)
        return redirect(url_for("wiki.user_index"))


    return render_template('usercreate.html', form=form)
コード例 #28
0
def get_users():
    users = getattr(g, '_users', None)
    if users is None:
        users = g._users = UserManager(current_app.config['CONTENT_DIR'])
    return users
コード例 #29
0
# Check if the file was converted.

if os.path.exists(filename):
    print("Pass - feature 2 - wiki to pdf")
else:
    print("Fail - feature 2 - wiki to pdf")

# Feature 3 - Create new user
# Create a new wiki user.
with app.app_context():
    makeUser()

# Set up UserManager to check list of users.
with app.app_context():
    newUser = UserManager('user')
    user = newUser.get_user('test')

# Check if the test user exists.
if user is not None:
    print("Pass - feature 3 - user creation")
else:
    print("Fail - feature 3 - user creation")

# Feature 4 - Create PDF and email
# Convert the current page to a PDF and email it.
with app.app_context():
    convertPDF('test')

# Store the location where the converted file should be stored.
filename = "content/createdpdfs/test.pdf"
コード例 #30
0
ファイル: test_web.py プロジェクト: starrn1/SEWiki
 def test_check_password(self):
     m = UserManager(TEST_FILE_PATH)
     u = m.get_user('name')
     self.assertTrue(u.check_password('1234'))
     self.assertFalse(u.check_password('dingdong'))