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)
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
def test_add_update_delete_user(self): """ Ensure users are added to the database correctly """ manager = UserManager("hash", "tests") #Add Users manager.add_user("testUserAdd", "password", True, [], "cleartext") manager.add_user("testUserAddWithRoles", "password2", True, ["testAddRole1", "testAddRole2"], "cleartext") user = manager.get_user("testUserAdd") assert user is not None assert user.name == "testUserAdd" assert user.get("password") == "password" assert user.get("roles") == [] user2 = manager.get_user("testUserAddWithRoles") assert user2 is not None assert user2.name == "testUserAddWithRoles" assert user2.get("password") == "password2" assert user2.get("roles") == ["testAddRole1", "testAddRole2"] #Update Users userdata = {} userdata["password"] = "******" userdata["authenticated"] = 0 userdata["active"] = 1 userdata["authentication_method"] = "cleartext" userdata["roles"] = ["testRoleUpdate"] manager.update("testUserAdd", userdata) user = manager.get_user("testUserAdd") assert user is not None assert user.name == "testUserAdd" assert user.get("password") == "password" assert user.get("roles") == ["testRoleUpdate"] #Delete Users manager.delete_user("testUserAdd") manager.delete_user("testUserAddWithRoles") user = manager.get_user("testUserAdd") user2 = manager.get_user("testUserAddWithRoles") assert user is None assert user2 is None
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
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
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'))
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
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
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
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
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')
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
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)
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)
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
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)
def test_delete_user(self): m = UserManager(TEST_FILE_PATH) m.add_user('nick', 'securepassword', authentication_method='hash') self.assertTrue(m.delete_user('nick'))
def test_add_user(self): m = UserManager(TEST_FILE_PATH) self.assertIsNotNone(m.add_user('nick', 'securepassword', authentication_method='hash'))
def makeUser(username, password): new = UserManager('user') new.add_user(username, password)
def test_add_user(self): m = UserManager(TestFilePath) self.assertIsNotNone( m.add_user('Ryan', 'pass', authentication_method='hash'))
def test_delete_user(self): m = UserManager(TestFilePath) m.add_user('Ronnie', 'password', authentication_method='hash') self.assertTrue(m.delete_user('Ronnie'))
def test_user_create_with_hash(self): manager = UserManager(TEST_USER_DIR) manager.add_user('User', 'Password'.encode()) user = manager.get_user('User') self.assertIsNotNone(user) self.assertNotEqual('Password', user.get('hash'))