def get_posts(): session_user_email = session['username'] query = 'SELECT * from users WHERE email = %s' values = (session_user_email, ) user = model.get_users(query, values) query_posts = 'SELECT * from posts WHERE user_id = %s' values = (user[0][0], ) posts = model.get_users(query_posts, values) return posts
def login(): if request.method == 'POST': user_email = request.form['user-email'] user_pass = request.form['user-password'] # get user from db who match the input fields query = 'SELECT * FROM users WHERE email = %s' values = (user_email, ) users = model.get_users(query, values) if len(users): user_session_email = users[0][2] user_session_pass = users[0][3] if user_pass == user_session_pass: session['logged_in'] = True session['username'] = user_email flash('Welcome {}'.format(users[0][1])) return redirect(url_for('index')) else: flash('Incorrect password') return render_template('login.html') else: flash("User not exist") return render_template('login.html') return render_template('login.html')
def register(): if request.method == 'POST': user_username = request.form['username'] user_email = request.form['user-email'] user_pass = request.form['user-password'] repeat_pass = request.form['repeat-password'] users = model.get_users() error = None for user in users: if user_username == user[1] and user_email == user[2]: error = 'The username and email is already taken' if user_username == user[1]: error = 'The username is already taken' if user_email == user[2]: error = 'The email is already taken' if error: flash(error) return render_template('register.html') query = '''INSERT INTO users(username, email, password, joined_at, is_admin) VALUES(%s, %s, %s, %s, %s)''' values = (user_username, user_email, user_pass, datetime.now(), False) model.add_user(query, values) flash('Registered Successfuly!') return redirect(url_for('index')) return render_template('register.html')
def shuotest1(): results = '' results += '<p>[TEST] ADD a user, list the number of users, and all users name and email</p>' name = 'Lucy' pwd = 'llll' email = name +'@brandeis.edu' #test #model.add_user(name,pwd,email) #for count in model.add_user('Alex','1','*****@*****.**'): #results += '<p>add a new user</p><br/><p>current total number of users: ' + str(count['total_user']) + '</p><hr/>' #results +='<p>TOTAL USERS: '+str(model.add_user('Kiki','000','*****@*****.**'))+'</p>' #test for total in DB().query('SELECT COUNT(*) AS total_user FROM users'): results +='<p>total users:'+str(total['total_user'])+'</p>' #test, add a user results +='<p>[TEST] Add a user:'******'</p>' for row in model.get_users(): results += '<p>'+row['user']+' '+ row ['email']+'</p>' return results
def POST(self): form = addform() if not form.validates(): users = model.get_users() return render.index(users, form) model.new_user(form.d.login, form.d.password, form.d.prefix, form.d.firstname, form.d.lastname, form.d.email, form.d.phone, form.d.addr1, form.d.addr2, form.d.city, form.d.state, form.d.country, form.d.zip, form.d.approved) mailfrom = "rhn-newuser-request@localhost" mailto = "root@localhost" subject = "New User Added" message = "The following user has requested access: %s" % (form.d.login) web.sendmail(mailfrom, mailto, subject, message) return "Thank you, an email will be sent for Approval."
def display_all(): users = get_users() view = f'<h1>View Users</h1><br>' if users == []: return '<h1>Something Wrong</h1><br> <a href="/main/{id}">Voltar</a>' for user in users: view += f'ID: {user[0]}<br> User: {user[1]}<br> Email: {user[2]}<br> Password: {user[3]}<br><br>' view += f'<a href="/main/{id}">Voltar</a>' return view
def test_login(self): self.assertIn("OrangeHRM", self.driver.title) admin_user=model.get_users('admin') username=element.find_element(locator.LoginPageLocators.EMAIL_ID, self.driver) password= element.find_element(locator.LoginPageLocators.PASSWORD, self.driver) login_button=element.find_element(locator.LoginPageLocators.LOGIN,self.driver) username.send_keys(admin_user['username']) password.send_keys(admin_user['password']) login_button.click() assert "Welcome Admin" in self.driver.page_source
def find(): if request.method == 'POST': input_val = request.form['find_user'] query = '''SELECT username from users WHERE username LIKE %s''' values = ('{}%'.format(input_val), ) users = model.get_users(query, values) print(users) return render_template('find.html', users=users) return render_template('find.html')
def pay(): if not flask_security.current_user.is_authenticated: return redirect('/login') if not flask_security.current_user.id == int(app.config['ADMIN_ID']): flask.abort(404) users = model.get_users() users_choices = [] for u in users: users_choices.append((str(u.id), ("%s %s" % (str(u.first_name), str(u.last_name))))) print(users_choices) form = forms.PaymentForm() form.user.choices = users_choices if form.validate_on_submit(): user_id = int(form.user.data) users = (model.User.query .filter(model.User.approved == True) .filter(model.User.participates == True) .filter(model.User.id != user_id)).all() amount = form.amount.data birthday = model.Birthday() birthday.amount = int(amount) birthday.user_id = user_id birthday.gift = form.gift.data db.session.add(birthday) num_users = int(len(users)) individual_payment = int(birthday.amount / num_users) for user in users: payment = model.Payment() payment.amount = individual_payment payment.birthday = birthday payment.user = user payment.timestamp = datetime.datetime.utcnow() db.session.add(payment) db.session.commit() for user in users: tasks.pay.delay(user.id, int(individual_payment), user_id, birthday.gift) return flask.redirect(flask.url_for( 'pay')) return render_template('pay.html', form=form)
def POST(self): flag_loginfail=1 posts=model.get_posts() login_user=model.get_users() for user in login_user: if web.input().login_username==user.username and model.create_md5(web.input().login_password)==user.password: flag_loginfail=0 web.setcookie('username',web.input().login_username) if flag_loginfail: return render.index(posts) raise web.seeother('/')
def get_users(self, ID_M): Bookkeeping.deleteinfo(self) bk_rows = model.show_by_month(ID_M) pa_rows = model.get_users() for row in bk_rows: for col in row: self.data_items_bk.append(col) print(col) for row in pa_rows: for col in row: self.data_items_pa.append(col)
def POST(self): param = web.input() user_name = param.username user_password = param.password user_info = model.get_userbyname(user_name) if user_info is not None : if user_info['password'] == user_password: users = model.get_users() return render.showusers(users,user_name) else: return "false password or User"
def profile(): session_user_email = session['username'] query = 'SELECT * from users WHERE email = %s' values = (session_user_email, ) user = model.get_users(query, values) date = str(user[0][4]) date = date[:11].replace('-', '/') return render_template('profile.html', user=user[0], date=date)
def POST(self): param = web.input() user_name = param.username user_password = param.password user_info = model.get_userbyname(user_name) if user_info is not None: if user_info['password'] == user_password: users = model.get_users() return render.showusers(users, user_name) else: return "false password or User"
def api_usuarios(): if (request.method == 'GET'): nombres_usuarios = model.get_users() if (nombres_usuarios): return jsonify(nombres_usuarios) else: return jsonify(error_BD), 404 # Verbo erróneo else: return jsonify(error_verbo_peticion), 400
def GET(self): '''Show home page''' users = model.get_users() posts = [] for user in users: report = model.get_report_by_name(user.name) # bug??? Need ot konw the life scope of variable 'post' if report != None: post = Post(user.name2, user.id, report.id, report.postdate) else: post = Post(user.name2, user.id) posts.append(post) today = datetime.date.today().strftime('%Y%m%d') return render.index(posts, today)
def add_post(): session_user_email = session['username'] query = 'SELECT * from users WHERE email = %s' values = (session_user_email, ) user = model.get_users(query, values) if request.method == 'POST': value_post = request.form['new-post'] query = 'INSERT INTO posts(value, user_id) VALUES(%s, %s)' values = (value_post, user[0][0]) model.add_user(query, values) posts = get_posts() return render_template('index.html', posts=posts)
def leader_board(): users = model.get_users() #userid, balance, first, last users_list = [] for user in users: userid = user[0] if userid == 'admin123': continue acct_bal = user[1] name = user[2] + ' ' + user[3] data = stocks_earnings( userid) #(acct_bal,stocks_val,earnings,stocks_list) stocks_val = data[1] earnings = data[2] users_list.append((earnings, acct_bal, stocks_val, userid, name)) users_list.sort(reverse=True) return users_list
def POST(self): form = addform() if not form.validates(): users = model.get_users() return render.index(users, form) model.new_user(form.d.login, form.d.password, form.d.prefix, form.d.firstname, form.d.lastname, form.d.email, form.d.phone, form.d.addr1, form.d.addr2, form.d.city, form.d.state, form.d.country, form.d.zip, form.d.approved) mailfrom = "rhn-newuser-request@localhost" mailto = "root@localhost" subject = "New User Added" message = "The following user has requested access: %s" % ( form.d.login) web.sendmail(mailfrom, mailto, subject, message) return "Thank you, an email will be sent for Approval."
def connect(self): try: admin_user = model.get_users('admin') username = element.find_element(locator.LoginPageLocators.EMAIL_ID, self.driver) password = element.find_element(locator.LoginPageLocators.PASSWORD, self.driver) login_button = element.find_element( locator.LoginPageLocators.LOGIN, self.driver) username.send_keys(admin_user['username']) password.send_keys(admin_user['password']) login_button.click() assert "Welcome Admin" in self.driver.page_source except Exception as e: print(e, "Failed to login") return self.driver
def GET(self): ''' Get a list of _all_ users that exist in the DB. This method is only available to the super admin user ''' if session.privilege == 2: self.users = model.get_users() data = [] for user in self.users: data.append({ "email": user.email, "id": user.id, "username": user.username, "privilege": user.privilege }) web.header("Content-Type", "application/json") web.header("Cache-Control", "no-cache") return json.dumps(data)
def POST(self): form = self.form() if not form.validates(): return render.download(form) root = 'file' filename = '(WeekReport)SW 3G5P Security TG_' + \ datetime.date.today().strftime('%Y%m%d') + '.xls' attend_staff = form.d.attend_staff absent_staff = form.d.absent_staff meeting_direct = form.d.meeting_direct record_staff = form.d.record_staff today_reports = list(model.get_all_reports()) users = model.get_users() reports = [] for user in users: report = Report(user.name) for tr in today_reports: if tr.who == user.name: report.add(tr.job, tr.risk, tr.plan) break # make sure that every user exist in the excel document even # if it is emtpy reports.append(report) issues = '' mk_report.generate_report( root, filename, attend_staff, absent_staff, meeting_direct, record_staff, reports, issues) # deal with download fd = file(root + '/' + filename, 'rb') # web.header('http-equiv', 'refresh') # redirect web.header('Content-type', 'application/octet-stream') fileinfo = 'attachment;filename="' + filename + '"' web.header('Content-Disposition', fileinfo) web.header('Content-transfer-encoding', 'binary') return fd.read()
def GET(self): form = addform() users = model.get_users() return render.index(users, form)
def GET(self): """Get users list""" users = model.get_users() return demjson.encode(users)
def admin_loop(username): # Admin menu (balance, deposit, withdraw, set, portfolio, leaderboard, users, exit) admin_done = False while not admin_done: balance_inputs = ["a", "balance"] deposit_inputs = ["d", "deposit"] withdraw_inputs = ["w", "withdraw"] set_inputs = ["t", "set"] portfolio_inputs = ["p", "portfolio"] leaderboard_inputs = ["l", "leaderboard"] users_inputs = ["u", "users"] exit_inputs = ["e", "exit"] acceptable_inputs = balance_inputs\ +deposit_inputs\ +withdraw_inputs\ +set_inputs\ +portfolio_inputs\ +leaderboard_inputs\ +users_inputs\ +exit_inputs user_input = view.admin_menu() # If the user input is acceptable. if user_input.lower() in acceptable_inputs: # Balance if user_input.lower() in balance_inputs: username = view.admin_balance_menu() balance = model.get_balance(username) view.admin_display_balance(username, balance) # Deposit elif user_input.lower() in deposit_inputs: username, balance_to_add = view.admin_deposit_menu() balance = model.get_balance(username) new_balance = model.calculate_new_deposit( balance, balance_to_add) model.update_balance(new_balance, username) view.admin_display_new_balance(username, balance, new_balance) # Withdraw elif user_input.lower() in withdraw_inputs: username, balance_to_subtract = view.admin_withdraw_menu() balance = model.get_balance(username) new_balance = model.calculate_new_withdraw( balance, balance_to_subtract) model.update_balance(new_balance, username) view.admin_display_new_balance(username, balance, new_balance) # Set elif user_input.lower() in set_inputs: username, balance_to_set = view.admin_set_menu() balance = model.get_balance(username) new_balance = model.calculate_new_set(balance, balance_to_set) model.update_balance(new_balance, username) view.admin_display_new_balance(username, balance, new_balance) # Portfolio elif user_input.lower() in portfolio_inputs: username = view.admin_portfolio_menu() df = model.get_holdings_dataframe(username) balance = model.get_balance(username) earnings = model.get_earnings(username) view.display_dataframe(df, balance, earnings, username) # Leaderboard elif user_input.lower() in leaderboard_inputs: view.admin_leaderboard_wait() leaderboard = model.get_leaderboard() view.admin_display_leaderboard(leaderboard) # Users elif user_input.lower() in users_inputs: users = model.get_users() view.admin_display_users(users) # Exit elif user_input.lower() in exit_inputs: view.exit_message() admin_done = True # Otherwise else: return "Error"
def html_movielist(id): user = model.get_users() movies = model.get_movies() html = """ <div class="list content"> <header> <div id="humberger"> <div></div> <div></div> <div></div> </div> </a> <img src="images/netflix-logo.png" class="logo"/> </header> """ for u in user: if (u[0] == int(id)): html += """ <div class="balloon"> <p>Hi! """ + str(u[1]) + """ !</p> </div> <div id="user"> <img src="images/user_image.png"/> <h1>UserName: """ + str(u[1]) + """</h1> <a href="index.py"><button>Sign Out</button></a> </div> <main> <h1>Manga</h1> <div class="movies genre"> """ for m in movies: if (m[4] == 1): html += """ <a href="moviedetail.py?id=""" + str(m[0]) + """"><img src=" """ + str( m[5]) + """ "></a> """ html += """ </div> <h1>Avengers</h1> <div class="drama genre"> """ for m in movies: if (m[4] == 2): html += """ <a href="moviedetail.py?id=""" + str( m[0]) + """"><img src=" """ + str(m[5]) + """ "></a> """ html += """ </div> <h1>Favorite</h1> <div class="trend genre"> """ for m in movies: if (m[4] == 3): html += """ <a href="moviedetail.py?id=""" + str( m[0]) + """"><img src=" """ + str(m[5]) + """ "></a> """ html += """ </div> </main> <script src="main.js"></script> </div> """ return html
def news(text): for user in get_users(): send_news.delay(user.id, text)
def notify_all_about_birthday(birthday_user_id, days): for user in get_users(): if user.id != birthday_user_id: notify_about_birthday.delay(user.id, birthday_user_id, days)
def find_incomplete_accounts(): for user in get_users(): if user.birthday is None or user.phone is None: message_admin("User %s has incomplete accounts." % user.full_name())
def nudge(): for user in get_users(): if user.balance < 200: print("Nudging user:", user) nudge_user.delay(int(user.id), user.balance)
def index(): model.connect() users = model.get_users() return render_template("index.html", users=users)
def show_users(): user_list = model.get_users() return render_template("homepage.html", users=user_list)
def game_loop(): start = view.start_up_menu() if start == "s": (user_name, password) = view.sign_up_menu() model.sign_up(user_name, password) else: (user_name, password) = view.logg_in_menu() _id = model.user_check(password) print(_id) while 1: buy_inputs = ['b', 'buy'] sell_inputs = ['s', 'sell'] lookup_inputs = ['l', 'lookup', 'look up', 'look-up'] quote_inputs = ['q', 'quote'] exit_inputs = ['e', 'exit', 'quit'] view_inputs = ['v'] acceptable_inputs = buy_inputs \ +sell_inputs \ +lookup_inputs \ +quote_inputs \ +exit_inputs \ +view_inputs user_input = view.main_menu() if user_input in acceptable_inputs: if user_input in buy_inputs: balance = model.check_balance(user_name) fee = 6.25 ticker_symbol = view.quote_menu() price = model.quote(ticker_symbol) trade_volume = view.transaction_menu(balance, ticker_symbol, price) transaction_cost = (float(trade_volume) * price) + fee if transaction_cost <= balance: balance -= transaction_cost model.update_cash(user_name, balance) model.buy(user_name, ticker_symbol, float(trade_volume), float(price)) model.buy_holdings(user_name, ticker_symbol, float(trade_volume), price) else: print("Not enough monay") elif user_input in sell_inputs: ticker_symbol = view.quote_menu() price = model.quote(ticker_symbol) trade_volume = view.sell_menu() owned = model.check_holdings(user_name, ticker_symbol) if owned and int(trade_volume) <= owned: model.sell_holdings(user_name, ticker_symbol, trade_volume, price, owned) elif user_input in lookup_inputs: return model.lookup(view.lookup_menu()) elif user_input in quote_inputs: return model.quote(view.quote_menu()) elif user_input in view_inputs: users = model.get_users() users_list = [ ] # this is a list of all the users that currenttly have holdings for i in users: users_list.append(i[0]) users_holdings = [ ] # users holdings by tickers but not numbers for i in users_list: user_holdings = model.get_holdings(i) a = [] for i in user_holdings: a.append(i[0]) users_holdings.append(a) tickers = [ ] # is all the stocks the users, un "set'd" and joinined together for i in users_holdings: for j in i: tickers.append(j) prices = { } # this has all the prices for all the stocks owned in the holdings for i in set(tickers): # price = model.quote(i) prices[i] = price volumes = [ ] # a list of lists of amount of stock each of them own for i in users_list: volumes.append(model.holdings_volumes(i)) # print(users_holdings) # print(volumes) values_final = {} for i in range(len(users_holdings)): total = 0 for j in range(len(users_holdings[i])): total += (prices[users_holdings[i][j]]) * ( volumes[i][j][0]) values_final[users_list[i]] = total highest = 0 sorted_words = {} while values_final: for i in values_final: if values_final[i] >= highest: highest = values_final[i] word = i sorted_words[word] = highest values_final.pop(i) highest = 0 for i in sorted_words: print("{} : {}".format(i, sorted_words[i])) # highest = 0 # while values_final: # for i in range(len(values)) # if values[i] # need to add total balance #work vwamp elif user_input in exit_inputs: break
def GET(self): print web.ctx.method users = model.get_users() return render.index(users)
def GET(self): userlists = model.get_users() return render.usercontrol(userlists)
def users(): # Lists all users in 2 groups, active past 90 days, otherwise. log_access('users') return render_template('users.html', activeusers=model.get_users(1), passiveusers=model.get_users(2))