def getOptions(): client = MongoClient("10.72.100.5", 8027) db = client.admin db.authenticate("double", "double") dblist = client.list_database_names() # 服务器上除系统数据库外的所有数据库 print('所有的数据库:', dblist) j = 0 for i in range(len(dblist)): if dblist[j] == 'admin': dblist.pop(j) elif dblist[j] == 'config': dblist.pop(j) elif dblist[j] == 'local': dblist.pop(j) else: j += 1 print(dblist) options_list = [] for i in range(len(dblist)): db = dblist[i] database = client[db] collection_list = database.list_collection_names() # 指定数据库中的所有集合 child_list0 = [] for j in range(len(collection_list)): coll = collection_list[j] collection = database[coll] document = collection.find_one() field_list = list(document.keys())[1:] # 指定数据库中的所有字段(除了"_id") child_list1 = [] for k in range(len(field_list)): child_list1.append({ 'value': field_list[k], 'label': field_list[k] }) child_list0.append({ 'value': collection_list[j], 'label': collection_list[j], 'children': child_list1 }) options_list.append({ 'value': dblist[i], 'label': dblist[i], 'children': child_list0 }) return json.dumps(options_list)
def login(self, email, password): projects = authenticate(email, password) if projects: self.projects = projects return True else: raise Unauthorized('Wrong credentials')
def change_username(): auth_status = auth() if not auth_status[0]: return redirect(url_for('index')) if request.method == 'GET': return redirect(url_for('settings.index')) if user_exists(request.form['username']): flash(f'Username: {request.form["username"]} is already in use') return redirect(url_for('settings.index')) if not authenticate(auth_status[1].username, request.form['password']): flash('Incorrect current password, your username has NOT changed') return redirect(url_for('settings.index')) collection.update_one( {'_id': auth_status[1].id}, { '$set': { 'username': request.form['username'] }} ) session['USERNAME'] = request.form['username'] flash(f'Username changed from {auth_status[1].username} to {request.form["username"]}') return redirect(url_for('settings.index'))
def change_password(): auth_status = auth() if not auth_status[0]: return redirect(url_for('index')) if request.method == 'GET': return redirect(url_for('settings.index')) if not authenticate(auth_status[1].username, request.form['currentPassword']): flash('Incorrect current password, your password has NOT changed') return redirect(url_for('settings.index')) if request.form['newPassword'] != request.form['newPassword2']: flash('Your passwords did not match') return redirect(url_for('settings.index')) collection.update_one( {'_id': auth_status[1].id}, { '$set': { 'password': enc.encrypt(request.form['newPassword']) }} ) session['PASSWORD'] = request.form['newPassword'] flash('Password successfully changed, make sure to save it!') return redirect(url_for('settings.index'))
def login(): if db.authenticate(request.form['username'], request.form['password']): session['USERNAME'] = request.form['username'] session['PASSWORD'] = request.form['password'] else: flash('Incorrect username or password') return redirect(url_for('login'))
def post(self): data = request.get_json() user = db.authenticate(data['username'], data['password']).__dict__ del user['password'] access_token = create_access_token(identity=user, expires_delta=timedelta(seconds=10)) return {'access_token': access_token}, 200
def auth(): if session.get('USERNAME') and session.get('PASSWORD'): user = authenticate(session.get('USERNAME'), session.get('PASSWORD')) signed_in = bool(user) if signed_in: return [signed_in, create_user_object(user)] return [False, False]
def authenticate(): username = request.form['username'] password = request.form['password'] result = db.authenticate(username, password) print(username, password) print('logging in', result) if type(result) == str: return jsonify(result = result) else: login_user(result) return jsonify(result = 'success')
def login(): if request.method == 'POST': if not db.authenticate(request.form['username'], request.form['password']): return 'Incorrect Username or Password' session['username'] = request.form['username'] session['password'] = request.form['password'] return redirect('/balance') elif request.method == 'GET': with open('login.html', 'r') as f: return f.read()
def inner(*args, **kwargs): if request.method == "POST": username = request.form["username"] password = request.form["password"] #if authenticate(username,password): if db.authenticate(username,password): session['name'] = username page = session.pop('nextpage','/') return redirect(page) else: if db.userexists(username): flash("You've inputted the wrong password for the given user.") return redirect(url_for('login')) else: flash("The username you inputted hasn't been registered yet.") return redirect(url_for('register')) return f(*args, **kwargs)
def is_order_valid(session, form): order = OrderParameters(session, form) if not db.authenticate(order.username, order.password): return 'BAD USERNAME OR PASSWORD' order.usd_balance, order.eth_balance = db.get_balance(order.username) #user wants to purchase eth if order.option == 'buy' and order.usd_amount > order.usd_balance: return 'NOT ENOUGH USD' #user wants to sell eth elif order.option == 'sell' and order.eth_amount > order.eth_balance: return 'NOT ENOUGH ETH' return order
def addDate(): some = str(request.args["dat"]) id = str(request.args["ID"]) email = str(request.args["email"]) list = db.genDates() list = db.remDates(list) if db.wrongEmail(email): return render_template("landing.html", error = "You must input a valid, senior, email address", happy = list) if db.wrongOSIS(id): return render_template("landing.html", error = "Your OSIS must be", happy = list, italics = " your", notitalics = " valid 9-digit number!") if (len(some) == 0) or (len(str(request.args["ID"])) == 0) or (len(str(request.args["email"])) == 0): return render_template("landing.html", error = "All fields must be filled!", happy = list) if db.authenticate(some): command = "INSERT INTO dates (id, date) VALUES (" + request.args["ID"] + ", '" + request.args["dat"] + "');" db.exec(command) return render_template("out.html", selectedDate = str(request.args["dat"]), osis = id) else: return render_template("landing.html", error = "Unfortunately, your date is already chosen :(", error2 = "Please choose a different date.", happy = list)
def login(): if request.method == "POST": username = request.form["username"] password = request.form["password"] #if authenticate(username,password): if db.authenticate(username,password): session['name'] = username global prevpage page = prevpage prevpage = "index" return redirect(url_for(page)) else: if db.userexists(username): flash("You've inputted the wrong password for the given user.") return redirect(url_for('login')) else: flash("The username you inputted hasn't been registered yet.") return redirect(url_for('register')) return render_template("login.html")
def check(): if request.method == 'POST': form = request.form username = form['username'] password = form['password'] # Authenticating the user try: result = db.authenticate(username, password) if result: user = str(result[0]) if username == user: # Setting Username db.setLogin(username) # Getting User ID userid = db.getUserId(username) # Checking if user has any videos videos = db.getMyVideos(userid) if videos: return redirect('/videos') else: return redirect('/welcome') else: message = { "message_type": "error", "message_info": "Invalid Login Details!" } return render_template('login.html', message=message) except: return redirect('/') return render_template('login.html')
def inner(*args, **kwargs): if request.method == "POST": username = request.form["username"] password = request.form["password"] #if authenticate(username,password): if db.authenticate(username, password): session['name'] = username page = session.pop('nextpage', '/') return redirect(page) else: if db.userexists(username): flash( "You've inputted the wrong password for the given user." ) return redirect(url_for('login')) else: flash( "The username you inputted hasn't been registered yet." ) return redirect(url_for('register')) return f(*args, **kwargs)
def authenticate(): user = db.authenticate(request.form['username']) try: check_pass = sha256_crypt.verify(request.form['pass'], user.password) except: check_pass = request.form['pass'], user.password if check_pass: session['id'] = user.id session['username'] = user.username session['name'] = user.name session['password'] = user.password session['access_level'] = user.access_level if user.password == 'pass': return redirect(url_for('change_pass')) else: flash(f'Welcome {user.name}') return redirect(url_for('home')) else: flash('Login failed, please try again') return redirect(url_for('home'))
def login(self, nick, channel, details): if len(details) < 2: return self.error_message(nick, channel, 'Usage: !login USERNAME PASSWORD') if channel != None: return self.error_message(nick, channel, 'USE PRIVATE MESSAGES FOR REGISTERING AND LOGGING IN (idiot)') u = db.User(nick=nick) if not u.new: return self.error_message(nick, channel, 'You are already logged in as ' + u.nick) m = Message() m.command = 'PRIVMSG' u = db.authenticate(details[0], details[1]) if u == None: m.params = [nick, 'Login failed'] else: if len(u.nick) > 0: m.params = [nick, 'Already logged in'] else: u.nick = nick u.last_login = datetime.now() u.save() m.params = [nick, 'Login succeeded'] self.connection.send(m)
def login_(): try: # Validate / sanitize input: s = Schema({ Required('username'): k_username_validity, Required('password'): k_password_validity, }) data = s(dict(b.request.forms.decode())) # Attempt login: dbs = session_maker() sess = b.request.environ.get('beaker.session') username = data['username'] user = db.authenticate(dbs, data['username'], data['password']) if user: sess['username'] = user.username sess.save() b.redirect(gurl(sess.get('after_login', 'home'))) else: return b.template('login', login_detail='Login failed... try again?') except MultipleInvalid as e: return b.template('login', flash=[error.msg for error in e.errors])
def MICvalue(): choice_user = request.get_json() # 获取前端用户选择的数据 flag = True # data = request.get_json() #bytes # print(data) choice0 = {} choice1 = {} # choice[0]['db'] = data[0][db] # choice[0]['col'] = data[0][col] # choice[0]['field'] = data[0][field] # choice[1]['db'] = data[1][db] # choice[1]['col'] = data[1][col] # choice[1]['field'] = data[1][field] choice0['db'] = choice_user[0][0] choice0['col'] = choice_user[0][1] choice0['field'] = choice_user[0][2] choice1['db'] = choice_user[1][0] choice1['col'] = choice_user[1][1] choice1['field'] = choice_user[1][2] print("choice0", choice0) print("choice1", choice1) # choice0['db'] = 'EpidemicData' # choice0['col'] = '上海' # choice0['field'] = '新增确诊' # choice1['db'] = 'EpidemicData' # choice1['col'] = '河北' # choice1['field'] = '新增确诊' # print(choice0) # print(choice1) # 获取数据 # client = MongoClient("10.72.100.5",8027,username='******',password='******') client = MongoClient("10.72.100.5", 8027) db = client.admin db.authenticate("double", "double") conn = MongoClient(host='mongodb://10.72.100.5:8027/' + 'admin', username='******', password='******') database = conn[choice0['db']] collection0 = database[choice0['col']] results0 = collection0.find({}, { choice0['field']: 1, "_id": 0 }).sort("_id", pymongo.ASCENDING) # 按照_id排序 collection1 = database[choice1['col']] results1 = collection1.find({}, { choice1['field']: 1, "_id": 0 }).sort("_id", pymongo.ASCENDING) # 按照_id排序 # 1表示显示此字段,0表示不显示此字段,默认会显示_id rawdata0 = [] rawdata1 = [] for result in results0: rawdata0.append(result[choice0['field']]) for result in results1: rawdata1.append(result[choice1['field']]) # 清理数据 for i in range(len(rawdata0) - 1, -1, -1): # 假定rawdata0与rawdata1的长度相同 if rawdata0[i] and rawdata1[i]: try: # 将数字形式的数据转换为浮点数 rawdata0[i] = float(rawdata0[i]) rawdata1[i] = float(rawdata1[i]) except ValueError: flag = False # 存在非数值字段 else: del rawdata0[i] del rawdata1[i] print("rawdata0", rawdata0) print("rawdata1", rawdata1) # 计算MIC m = MINE() if rawdata0: # 当rawdata0与rawdata1不为空时 if flag: # 将数据映射到[0,1]区间 min_max_scaler = MinMaxScaler() data1_std = min_max_scaler.fit_transform( np.array(rawdata0).reshape(-1, 1)) data2_std = min_max_scaler.fit_transform( np.array(rawdata1).reshape(-1, 1)) data1 = data1_std.reshape(1, -1)[0] data2 = data2_std.reshape(1, -1)[0] m.compute_score(data1, data2) # str(m.mic()) return json.dumps(m.mic()) else: return "请选取数值字段" else: return "您所选取的两个字段无对应数据"
def test_login_fail_username(self): user = db.authenticate('foo', 'password') self.assertIsNone(user)
def test_one(self): self.assertTrue(authenticate(123456, "dino", "instructor"))
def auth(): login, pwd, device_id = check_json_for_keys(["login", "pwd", "device_id"]) token = db.authenticate(login, pwd, device_id) if not token: raise PermissionDeniedException() return jsonify({"token": token})
def test_two(self): self.assertTrue(authenticate(123458, "dino", "instructor"))
def testD(self): result = db.authenticate(tests.username, tests.password) self.assertEqual(result[0], tests.username)
def test_login_fail_password(self): user = db.authenticate('admin', 'foo') self.assertIsNone(user)
def authenticate(user): pw = getpass.getpass("Enter your password:") if not db.authenticate(user, pw): raise db.Bad_User_Auth()
def test_login(self): user = db.authenticate('admin', 'password') self.assertIsNotNone(user) self.assertEqual(user.username, 'admin')
return "Welcome " + self.name if __name__ == "__main__": userType = "" quit = False authenticated = False inputValid = False print("Course Marks Interface\n") while (not authenticated): ID = input("ID: ") password = getpass.getpass('Password: ') # Check the type of user based on the ID if (len(str(ID)) >= 6): authenticated = db.authenticate(ID, password, "instructor") userType = "instructor" else: authenticated = db.authenticate(ID, password, "student") userType = "student" if (userType == "instructor"): while (not quit): print("Instructor menu\n") print("Create User (1) | Update Mark (2) | Auto Mark (3) ") print("Exit (4)") decision = input() # Creating new accounts if (decision == "1"): print("Create a New Account\n") type = input("student or instructor: ")