def manageAccountPage(): if "user" not in session: session["nextpage"] = "/manage_account" return redirect("/login") if "user" in session: if request.method == "GET": return render_template("account_settings.html") name = session["user"] password = request.form["password"] phone = request.form["phone"] authenticated = True hour = request.form["hour"] minute = request.form["minute"] time = "" if hour and minute: time = datetime(2014, 10, 11, int(hour), int(minute)) lines = request.form.getlist("lines") D = {} D['name'] = name D['password'] = password D['phone'] = phone D['authenticated'] = authenticated D['time'] = time D['lines'] = lines user = db.User(name, D) db.updateUser(user) return render_template("account_settings.html", error="Update successful.")
def createdNotUpdated(): nonlocal added_user sleep(1) # Same here db.updateUser(added_user) update_user = db.getUser(test_name) assert_that(update_user.get('created_at'), equal_to(added_user.get('created_at')))
def modifiedUpdated(): nonlocal added_user sleep(1) # Delay to ensure modified time is different db.updateUser(added_user) update_user = db.getUser(test_name) assert_that(update_user.get('updated_at'), not_(equal_to(added_user.get('updated_at'))))
def test_update_user(self): time = datetime.datetime(year=2014, month=1, day=1, hour=0, minute=0) alarm = db.Alarm(time, ["1"]) conn = Connection() mongodb = conn[self.dbname] people = mongodb[self.dbCollectionName] # insert a lot of users into the database for i in range(10): user = db.User("testuser%d" % i) user.setPassword("testpassword%d" % i) user.setAlarm(alarm) user.setAuthenticated(False) user.setPhone("111111111%d" % i) people.insert(user.jsonify()) # change all the users to the same values newtime = datetime.datetime(year=2014, month=1, day=1, hour=5, minute=5) newlines = ["1", "2", "3"] newalarm = db.Alarm(newtime, newlines) newpassword = "******" newAuth = True newPhone = "1231231234" for user in people.find(): newuser = db.User(user['name']) newuser.setPassword(newpassword) newuser.setAlarm(newalarm) newuser.setAuthenticated(newAuth) newuser.setPhone(newPhone) db.updateUser(newuser, self.dbname, self.dbCollectionName) # count the number of each attribute L = [] L.append(people.find({'password': newpassword}).count()) L.append(people.find({'authenticated': newAuth}).count()) L.append(people.find({'phone': newPhone}).count()) L.append(people.find({'alarm': {'time': newtime, 'lines': newlines}}).count()) # each element should be 10 for n in L: self.assertEquals(n == 10, True)
def confirmEmail(code): global CODE_VALIDATOR if CODE_VALIDATOR.match(code) is None: return forbidden() code_info = db.getCode(code) if code_info is None: return forbidden() user = db.getUserById(code_info.get('user_id')) if user is None: return forbidden() user['email'] = code_info.get('email') db.updateUser(user) db.useCode(code_info.get('code')) return ok()
def oauth_callback(): data = {} data["client_id"] = secrets.client_id data["client_secret"] = secrets.client_secret data["code"] = request.args.get("code") oauth_token = pyrequests.post('https://github.com/login/oauth/access_token', data).text # check if user exists already, and update or add them to the db accordingly response = pyrequests.get('https://api.github.com/user?' + oauth_token).text resp_dict = json.loads(response) if 'login' in resp_dict: session['oauth_token'] = oauth_token username = resp_dict['login'] session['username'] = username if db.userExists(username): db.updateUser(username, oauth_token) else: db.createUser(username, oauth_token) return redirect(url_for('home'))
def updatedUser(): nonlocal added_user update_email = '*****@*****.**' added_user['email'] = update_email res = db.updateUser(added_user) updated_user = db.getUser(test_name) assert_that(updated_user.get('name'), equal_to(test_name)) assert_that(updated_user.get('pass_hash'), equal_to(test_hash)) assert_that(updated_user.get('pass_salt'), equal_to(test_salt)) assert_that(updated_user.get('email'), equal_to(update_email))
async def on_message(self, message): if not message.author.bot: currentId = message.author.id currentGuildId = message.author.guild.id currentName = message.author.name user = db.getUser(currentId, currentGuildId) if not user: user = db.insertNewUser(currentId, currentGuildId, currentName) newLevel = calculateLevel(user["messages"]) user["messages"] += 1 user["name"] = currentName if user["level"] != newLevel: user["level"] = newLevel await message.channel.send("Congratulations {}! You have reached **level {}**!".format(user["name"], user["level"])) await hasPerk(user["level"], message, user) db.updateUser(user)
def oauth_callback(): data = {} data["client_id"] = secrets.client_id data["client_secret"] = secrets.client_secret data["code"] = request.args.get("code") oauth_token = pyrequests.post( 'https://github.com/login/oauth/access_token', data).text # check if user exists already, and update or add them to the db accordingly response = pyrequests.get('https://api.github.com/user?' + oauth_token).text resp_dict = json.loads(response) if 'login' in resp_dict: session['oauth_token'] = oauth_token username = resp_dict['login'] session['username'] = username if db.userExists(username): db.updateUser(username, oauth_token) else: db.createUser(username, oauth_token) return redirect(url_for('home'))
def cancelUserAction(id): db.updateUser(id, 'current_action', 'none')
def setUserCurrentAction(id, action): db.updateUser(id, 'current_action', action)
def setUserActiveCon(userId, conId): db.updateUser(userId, 'active_connector', conId)
def setBitlyToken(userId, token): try: db.updateUser(userId, 'bitly_token', token) return True except: return False
def setSiteId(userId, siteId): try: db.updateUser(userId, 'site_id', siteId) return True except: return False
print("Before:", db.retrieve(tables[3], "Issue_Number", 2)) db.updateHealthAndSafetyIssue("Resolution_Date", "2016/07/13", 2) print("After:", db.retrieve(tables[3], "Issue_Number", 2)) #Updating fine payments ID = 3 print("\nFine Payments") print("Updating Payment_status") print("Before:", db.retrieve(tables[4], "Citation_Number", 3)) db.updateFinePayment("Payment_status", "Paid", 3) print("After:", db.retrieve(tables[4], "Citation_Number", 3)) #Updating Users ID = 1 print("\nUsers") print("Updating Password") print("Before:", db.retrieve(tables[5], "User_ID", 1)) db.updateUser("Password", "ThisIsAPassword", 1) print("After:", db.retrieve(tables[5], "User_ID", 1)) #============================================================# #Delete #============================================================# print("\nDelete from Tables") entry = dict(User_ID = 3, Violation_Type = "Smoking", Description = "Smoking in smoke free zone", Department = "Visitor", Supervisor = "Angelica Cole", Date = "2016/08/31", Time = "11:00", Place_in_campus = "In front of P Block") db.insertOtherViolation(entry) print("Before") printTable(db, tables[2]) db.delete(tables[2], "User_ID", 3) print("After") printTable(db, tables[2]) #============================================================#
def help(update, ctx): gettime = str(update.message.date).split() timetoconvert = gettime[0] + "T" + gettime[1] timestamp = strict_rfc3339.rfc3339_to_timestamp(timetoconvert) print(update.message.chat_id) if timestart < int(timestamp): user = update.message.from_user language = str() if update.message.chat.type == "private": language = db.getLang(user["id"]) else: language = getLang(update.message.chat_id) if user["username"]: if not db.checkUser(str(user["id"])): wif = genAddress() db.addUser(str(user["username"]), str(user["id"]), str(wif)) ctx.bot.send_message( chat_id=update.message.chat_id, text= f"[{escape_markdown(user['first_name'], 2)}](tg://user?id={user['id']}), {lang[language]['help']['success-regsiter']}", parse_mode="MarkdownV2") if update.message.chat.type == "private": ctx.bot.send_message(chat_id=update.message.chat_id, text=f""" {lang[language]['help']['part-1']} [{escape_markdown(user['first_name'], 2)}](tg://user?id={user['id']})\\. {lang[language]['help']['part-2']} 1\\. /help 2\\. /price 3\\. /info 4\\. /tip @user amount 5\\. /deposit 6\\. /balance 7\\. /withdraw address amount 8\\. /export 9\\. /setlang lang \\(en, zh, id\\) 10\\. /about """, parse_mode="MarkdownV2") ctx.bot.send_message( chat_id=update.message.chat_id, text=lang[language]['help']['warning-msg'], parse_mode="MarkdownV2") else: ctx.bot.send_message(chat_id=update.message.chat_id, text=f""" {lang[language]['help']['part-1']} [{escape_markdown(user['first_name'], 2)}](tg://user?id={user['id']})\\. {lang[language]['help']['part-2']} 1\\. /help 2\\. /price 3\\. /tip @user amount """, parse_mode="MarkdownV2") ctx.bot.send_message( chat_id=update.message.chat_id, text=lang[language]['help']['warning-msg'], parse_mode="MarkdownV2") else: if user["username"] != db.getUserName(str(user["id"])): db.updateUser(str(user["id"]), user["username"]) if update.message.chat.type == "private": ctx.bot.send_message(chat_id=update.message.chat_id, text=f""" {lang[language]['help']['part-1']} [{escape_markdown(user['first_name'], 2)}](tg://user?id={user['id']})\\. {lang[language]['help']['part-2']} 1\\. /help 2\\. /price 3\\. /info 4\\. /tip @user amount 5\\. /deposit 6\\. /balance 7\\. /withdraw address amount 8\\. /export 9\\. /setlang lang \\(en, zh, id\\) 10\\. /about """, parse_mode="MarkdownV2") ctx.bot.send_message( chat_id=update.message.chat_id, text=lang[language]['help']['warning-msg'], parse_mode="MarkdownV2") else: ctx.bot.send_message(chat_id=update.message.chat_id, text=f""" {lang[language]['help']['part-1']} [{escape_markdown(user['first_name'], 2)}](tg://user?id={user['id']})\\. {lang[language]['help']['part-2']} 1\\. /help 2\\. /price 3\\. /tip @user amount """, parse_mode="MarkdownV2") ctx.bot.send_message( chat_id=update.message.chat_id, text=lang[language]['help']['warning-msg'], parse_mode="MarkdownV2") else: ctx.bot.send_message( chat_id=update.message.chat_id, text= f"[{escape_markdown(user['first_name'], 2)}](tg://user?id={user['id']}), please set a username before using this bot", parse_mode="MarkdownV2")
def help(update, ctx): gettime = str(update.message.date).split() timetoconvert = gettime[0] + "T" + gettime[1] timestamp = strict_rfc3339.rfc3339_to_timestamp(timetoconvert) if timestart < int(timestamp): user = update.message.from_user if user["username"]: if not db.checkUser(str(user["id"])): wif = genAddress() db.addUser(str(user["username"]), str(user["id"]), str(wif)) ctx.bot.send_message(chat_id=update.message.chat_id, text=f"[{escape_markdown(user['first_name'], 2)}](tg://user?id={user['id']}), You have been successfully registered", parse_mode="MarkdownV2") if update.message.chat.type == "private": ctx.bot.send_message(chat_id=update.message.chat_id, text=f""" Hey there [{escape_markdown(user['first_name'], 2)}](tg://user?id={user['id']})\\. Here are my commands: 1\\. /help 2\\. /price 3\\. /info 4\\. /tip @user amount 5\\. /deposit 6\\. /balance 7\\. /withdraw address amount 8\\. /export 9\\. /about """, parse_mode="MarkdownV2") ctx.bot.send_message(chat_id=update.message.chat_id, text="*Please Note: * It is highly recommended that you do not directly mine to the " "address given by this bot\\. Download a full node here: " "[Full Node](https://github\\.com/sugarchain\\-project/sugarchain/releases/latest)", parse_mode="MarkdownV2") else: ctx.bot.send_message(chat_id=update.message.chat_id, text=f""" Hey there [{escape_markdown(user['first_name'], 2)}](tg://user?id={user['id']})\\. Here are my commands: 1\\. /help 2\\. /price 3\\. /tip @user amount """, parse_mode="MarkdownV2") ctx.bot.send_message(chat_id=update.message.chat_id, text="*Please Note: * It is highly recommended that you do not directly mine to the " "address given by this bot\\. Download a full node here: " "[Full Node](https://github\\.com/sugarchain\\-project/sugarchain/releases/latest)", parse_mode="MarkdownV2") else: if user["username"] != db.getUserName(str(user["id"])): db.updateUser(str(user["id"]), user["username"]) if update.message.chat.type == "private": ctx.bot.send_message(chat_id=update.message.chat_id, text=f""" Hey there [{escape_markdown(user['first_name'], 2)}](tg://user?id={user['id']})\\. Here are my commands: 1\\. /help 2\\. /price 3\\. /info 4\\. /tip @user amount 5\\. /deposit 6\\. /balance 7\\. /withdraw address amount 8\\. /export 9\\. /about """, parse_mode="MarkdownV2") ctx.bot.send_message(chat_id=update.message.chat_id, text="*Please Note: * It is highly recommended that you do not directly mine to the " "address given by this bot\\. Download a full node here: " "[Full Node](https://github\\.com/sugarchain\\-project/sugarchain/releases/latest)", parse_mode="MarkdownV2") else: ctx.bot.send_message(chat_id=update.message.chat_id, text=f""" Hey there [{escape_markdown(user['first_name'], 2)}](tg://user?id={user['id']})\\. Here are my commands: 1\\. /help 2\\. /price 3\\. /tip @user amount """, parse_mode="MarkdownV2") ctx.bot.send_message(chat_id=update.message.chat_id, text="*Please Note: * It is highly recommended that you do not directly mine to the " "address given by this bot\\. Download a full node here: " "[Full Node](https://github\\.com/sugarchain\\-project/sugarchain/releases/latest)", parse_mode="MarkdownV2") else: ctx.bot.send_message(chat_id=update.message.chat_id, text=f"[{escape_markdown(user['first_name'], 2)}](tg://user?id={user['id']}), please set a username before using this bot", parse_mode="MarkdownV2")