def main(eval_name, ml): uc = UserController() followers = uc.getFollowers(eval_name) directory = "followers_{}".format(eval_name) full_directory = "data/{}".format(directory) if not os.path.exists(full_directory): os.makedirs(full_directory) for name in followers: user = User(name, "{}/unknown".format(directory, name)) if user.valid: user.writeFile() path = "data/followers_{}".format(eval_name) follower_files = [f for f in listdir(path) if isfile(join(path, f))] result = {} for i in range(2): for j in range(2): for k in range(2): for l in range(2): type = [i, j, k, l] result[decodeType(type)] = [] for file in follower_files: follower = Sample("{}/{}".format(path, file)) type = ml.predict(follower.data) result[decodeType(type)].append(follower.twitName) with open("evaluated/follower_types_{}.json".format(eval_name), "w") as f: json.dump(result, f)
def test_GetFriendRecord(self): userController = UserController() print("\nsample message") print(userController.getFriendRecord(1, 2).id) # assert er baam pashe expected output, daan pashe actual output
def login(): email = request.form.get('email', None) password = request.form.get('password', None) message = [] if email is None or password is None: return jsonify({"error": "check your input"}), 403 userController = UserController() return jsonify(userController.loginUser(email=email, password=password))
def registration(): name = request.form.get('name', None) email = request.form.get('email', None) password = request.form.get('password', None) message = [] if name is None or email is None or password is None: return jsonify({"error": "check your input"}), 403 userController = UserController() return jsonify( userController.registerUser(name=name, email=email, password=password))
def main(): mbti_types_list = [ 'INFP', 'INFJ', 'INTJ', 'INTP', 'ISFJ', 'ISFP', 'ISTJ', 'ISTP', 'ENFJ', 'ENFP', 'ENTJ', 'ENTP', 'ESFJ', 'ESFP', 'ESTJ', 'ESTP' ] print(mbti_types_list) for mbti_type in mbti_types_list: print("Getting Users for " + mbti_type) uc = UserController() user_ids = uc.getUsersBySearchTerm("mbti " + mbti_type) n = 1 for id in user_ids: print n, " of 100 ", mbti_type, " Users" user = User(id, mbti_type) n = 1 + n
def test_create_regular_user(self): print("Create a regular user") assert UserController.create_user({ 'username': '******', 'password': '******', 'firstName': 'John', 'lastName': 'Doe', 'email': '*****@*****.**' }) is not None
def login(): make_test(lambda: UserController.login({ 'username': '******', 'password': '******' }))(UserTest, 'Login success', False) make_test(lambda: UserController.login({ 'password': '******', 'username': '******' }))(UserTest, 'Login success with unordered fields', False) make_test(lambda: UserController.login({ 'username': '******', 'password': '******' }))(UserTest, 'Login with wrong pwd', True) make_test(lambda: UserController.login({ 'username': '******', 'password': '' }))(UserTest, 'Login with empty pwd', True) make_test(lambda: UserController.login({ 'username': '******' }))(UserTest, 'Login with missing pwd', True) make_test(lambda: UserController.login({ 'username': '******', 'password': '******' }))(UserTest, 'Login with wrong username', True) make_test(lambda: UserController.login({ 'username': '******', 'password': '******' }))(UserTest, 'Login with inexisting username', True) make_test(lambda: UserController.login({ 'username': '', 'password': '******' }))(UserTest, 'Login with empty username', True) make_test(lambda: UserController.login({ 'password': '******' }))(UserTest, 'Login with missing username', True) make_test(lambda: UserController.login({ }))(UserTest, 'Login with all missing fields', True) make_test(lambda: UserController.login({ }))(UserTest, 'Login with all missing fields', True)
def test_IsMyRoleAdmin(self): userController = UserController() isUserAdmin = userController.isMyRoleAdmin( "b''n0\xfa\xdd\xceHT\xce\xaf\xbe\xee\xcc\xff\x9e\x10\xc5x|\xb2\xed''" ) print(isUserAdmin)
def test_GetFriendRecord(self): userController = UserController() print("\nsample message") print(userController.getFriendRecord(1, 2).id)
users = [ fake.profile(fields=['username'], sex=None)['username'] for u in range(users_count) ] threads = [] try: for i in range(users_count): threads.append( EmulationController(users[i], users, users_count, random.randint(100, 5000))) for thread in threads: thread.start() AdminController() for thread in threads: if thread.is_alive(): thread.stop() except Exception as e: View.show_error(str(e)) if __name__ == "__main__": choice = Controller.make_choice(["Main", "Emulation"], "Program mode") if choice == 0: UserController() elif choice == 1: emulation()
def create_tables(): Base.metadata.create_all(pUnit.engine) UserRoleController.create_all_roles() UserController.create_admin()
def get_connected_user(auth_info): user = UserController.get_user_by_id(auth_info['user_id']) return ResponseOK(user)
def create_user(): created_user = UserController.create_user( {key: request.form.get(key) for key in request.form.keys()}) return ResponseCreated(created_user)
def login(): token = UserController.login( {key: request.form.get(key) for key in request.form.keys()}) return ResponseOK(token)
def create_user(): print('\033[01m## Creation ##\033[0m') make_test(lambda: UserController.create_user({ 'username': '******', 'password': '******', 'firstName': 'John', 'lastName': 'Doe', 'email': '*****@*****.**' }))(UserTest, 'Normal Creation case', False) make_test(lambda: UserController.create_user({ 'username': '******', 'password': '******', 'firstName': 'John', 'lastName': 'Doe', 'email': '*****@*****.**' }))(UserTest, 'Empty username', True) make_test(lambda: UserController.create_user({ 'username': '******', 'password': '******', 'firstName': 'John', 'lastName': '', 'email': '[email protected]' }))(UserTest, 'Empty field', True) make_test(lambda: UserController.create_user({ 'username': '******', 'password': '******', 'firstName': 'John', 'email': '[email protected]' }))(UserTest, 'Missing Field', True) make_test(lambda: UserController.create_user({ 'username': '******', 'password': '******', 'firstName': 'John', 'lastName':'Doe', 'email': '[email protected]', 'fake:':'fake' }))(UserTest, 'Add Erronate Ignored Field', False) make_test(lambda: UserController.create_user({ 'username': '******', 'password': '******', 'firstName': 'John', 'lastName':'Doe', 'lastName':'Doe1', 'email': '[email protected]', }))(UserTest, 'Add Duplicate Param Takes the last one', False) make_test(lambda: UserController.create_user({ 'username': '******', 'password': '******', 'firstName': 'John', 'lastName': 'Doe', 'email': '[email protected]' }))(UserTest, 'Duplicate username', True) make_test(lambda: UserController.create_user({ 'username': '******', 'password': '******', 'firstName': 'John', 'lastName': 'Doe', 'email': '*****@*****.**' }))(UserTest, 'Duplicate email', True) make_test(lambda: UserController.create_user({ 'username': '******', 'password': '******', 'firstName': 'John', 'lastName': 'Doe', 'email': '*****@*****.**' }))(UserTest, 'Duplicate username and email', True) make_test(lambda: UserController.create_user({ 'username': '******', 'lastName': 'Doe', 'firstName': 'John', 'password': '******', 'email': '*****@*****.**' }))(UserTest, 'Other normal case with unordered fields', False)
from library.DatabaseConnection import DatabaseConnection from model.User import User from model.GameTable import GameTable from controller.UserController import UserController import os userController = UserController() # pc er random byte generator # userSalt = os.urandom(20) # databaseConnection = DatabaseConnection.getConnection() # databaseConnection.create_tables([User,GameTable]) # ayon = User.create(email = "*****@*****.**",salt = str(userSalt), password = userController.hashPassword(str(userSalt) + "password"), currentSessionCookie = userController.createCurrentUserSessionCookie()) # print(ayon) # golam = User.create(email = "*****@*****.**",salt = str(userSalt), password = userController.hashPassword(str(userSalt) + "password"), currentSessionCookie = userController.createCurrentUserSessionCookie()) # print(golam) # eva = User.create(email = "*****@*****.**",salt = str(userSalt), password = userController.hashPassword(str(userSalt) + "password"), currentSessionCookie = userController.createCurrentUserSessionCookie()) # print(eva) # saad = User.create(email = "*****@*****.**",salt = str(userSalt), password = userController.hashPassword(str(userSalt) + "password"), currentSessionCookie = userController.createCurrentUserSessionCookie()) # print(saad) # try: # print(userController.findUserWithEmail('*****@*****.**')) # except: # print("user is unavailable")
def get_user(user_id): user = UserController.get_user_by_id(user_id) return ResponseOK(user)
from flask import Flask, request, render_template, make_response, redirect, url_for, Response import hashlib, binascii, peewee, mysql.connector as mysql from library.DatabaseConnection import DatabaseConnection from model.User import User from controller.UserController import UserController app = Flask("twentynine",template_folder='templates', static_folder='',static_url_path='/') userController = UserController() @app.route('/') def welcomeScreen(): return render_template('welcomeScreen.html') # eikhane, duita different route er jonno eki function execute hocche. # /login, /login/... eirokom duita pailei ei login function execute kore # /login/... eikhane jai thakbe, loginfailed er moddhe save korbe. @app.route('/login') @app.route('/login/<loginfailed>') def login(loginfailed = ""): currentSessionCookie = request.cookies.get('currentSessionCookie') if currentSessionCookie is not None: return redirect(url_for('homePage')) loginForm = render_template('loginForm.html', action = "authenticate", loginfailed = loginfailed, pageHeader = "Log In", buttonValue = "Log In") return loginForm
def add_privileged_user(auth_info): user = UserController.create_privileged_user( {key: request.form.get(key) for key in request.form.keys()}, auth_info) return ResponseOK(user)