def process_login(): model.connect_to_db() username = request.form.get("username") password = request.form.get("password") user_id = model.authenticate(username, password) if model.authenticate(username, password): flash("User authenticated") session['user_id'] = user_id else: flash("Password incorrect, there may be a ferret stampede in progress!") return redirect(url_for("index"))
def process_login(): email = request.form.get("email") password = request.form.get("password") if model.authenticate(email, password): user_email, user_id = model.authenticate(email, password) if email != None: flash ("Welcome, %s!" % str(user_email)) session['user_id'] = user_id # put user_id into the session rather than email else: flash("Authentication failed.") return redirect(url_for("index"))
def test_can_get_tweet_quoted_message(self): """ End to End Test: Logs in, and then attempts to extract relevant info from a QUOTED tweet. """ api = authenticate() my_name = api.me().screen_name ## Todo, send a tweet, quote it (with @mention in text), then test. most_recent_mentions = api.mentions_timeline() tweet = most_recent_mentions[3] # How to handle quoted text. if tweet.is_quote_status: explanatory_text = tweet.text quoted_message_id = tweet.quoted_status_id target_tweet = api.get_status(quoted_message_id) json_string = json.dumps(target_tweet._json) filtered_data = parse_tweet_data(json_string) filtered_data.update({"explanation_text": explanatory_text}) #Todo: Tests go here. else: self.fail("Tweet was not a quote tweet")
def test_can_send_dm(self): """ End to End Test: Logs in, and then sends a direct message to ourselves """ api = authenticate() my_name = api.me().screen_name my_id = api.me().id api.send_direct_message(my_id, f"Hello {my_name}, How are you today") #reply_options = [ # { # "label": "Red", # "description": "Color of heightened emotion, strength, and power.", # "metadata": "external_id_1" # }, # { # "label": "Blue", # "description": "Convey a sense of trust, loyalty, cleanliness, and understanding.", # "metadata": "external_id_2" # } #] # Note that there is a bug in tweepy Api fixed in https://github.com/tweepy/tweepy/pull/1364 # Quick_reply_type is currently broken. # api.send_direct_message(my_id, "text", quick_reply_type=reply_options) self.assertTrue(True)
def test_get_tweet_data(self): """ End to End Test: Logs in, and then attempts to extract relevant info from a tweet. """ api = authenticate() my_name = api.me().screen_name msg = generate_random_string(30) # Create a tweet api.update_status(msg) # Get Tweet (via user timeline) tweets = api.user_timeline(screen_name=my_name, count=1, include_rts=False, tweet_mode='extended') tweet = tweets[0] self.assertEqual(tweet.full_text, msg) # Note that this step is not entirely necessary, we could create our database by calling the tweepy methods directly # (e.g. [tweepy object].text) as opposed to using the following convoluted process of [tweepy object] -> json_string -> python dict -> dict["text"])) # However the advantage of converting to Json and then extracting from Json is that we 'decouple' functionality. # For instance, we could replace 'tweepy' with some other library that can export tweets in Json format and the "parse_tweet_data" function # should work more or less the same. json_string = json.dumps(tweet._json) filtered_data = parse_tweet_data(json_string) cleaned = cleanup_data(filtered_data) self.assertEqual(cleaned["text"], msg) self.assertEqual(cleaned["id"], tweet.id)
def authenticate(): login_email = request.form['email'] login_pw = request.form['password'] usr_auth = model.authenticate(g.db, login_email, login_pw) print usr_auth session['usr_id'] = usr_auth['id'] return redirect(url_for('list_tasks'))
def login(): email = request.form['email'] password = request.form['password'] db = model.connect_db() auth_user = model.authenticate(db, email, password) if auth_user != None: return redirect("/Tasks")
def on_btn_login_clicked(self): usr_name = unicode(self.edit_usr_name.text()) pwd = unicode(self.edit_pwd.text()) if not model.authenticate(usr_name, pwd): QMessageBox.critical(self, u"登录", u"用户名或密码错误!") else: self.done(QDialog.Accepted)
def authenticate(): email = request.form['email'] password = request.form['password'] # capture the userid information from model-database user_id = model.authenticate(g.db, email, password) session['user_id'] = user_id # after getting the session variable back, you have to point it to a page return redirect("/")
def authenticate(): email = request.form["email"] password = request.form["password"] user_id = model.authenticate(g.db, email, password) if user_id == None: error = "no user with that combination" return render_template("/login.html", error=error) session["user_id"] = user_id return redirect("/tasks")
def process_login(): username = request.form.get("username") password = request.form.get("password") if model.authenticate(username, password): flash("User authenticated!") else: flash('Password incorrect!') return redirect(url_for("index"))
def process_login(): # form.get("___") --> blank corresponds to name in HTML form email = request.form.get("email") password = request.form.get("password") if model.authenticate(email, password): return render_template("login.html", email=email, password=password) # redirect to logged in user page instead else: return render_template("login_fail.html")
def authenticate(): db = model.connect_db() email = request.form['email'] password = request.form['password'] user_info = model.authenticate(db, email, password) if user_info == None: return redirect('/') else: return redirect('/tasks')
def check_auth(username, password): """This function is called to check if a username / password combination is valid. """ account = model.authenticate(username, password) if account is None: return AuthResponse.no_account if not model.hasAssignedBlock(account): return AuthResponse.no_block return AuthResponse.success
def login(): email = request.form.get("email") password = request.form.get("password") user_id = model.authenticate(email, password) if user_id == None: flash("User does not exist") return redirect(url_for("index")) else: session['id'] = user_id return redirect(url_for("profile", user_id =user_id))
def auth(): email = request.args.get('email') password = request.args.get('password') result = model.authenticate(email, password) if isinstance(result, model.User): return jsonify(model.convert(result)) else: return abort(401)
def process_login(): email = request.form.get("email") password = request.form.get("password") if model.authenticate(email, password): user_object = model_session.query(model.User).filter_by(email=email).first() session['id'] = user_object.user_id return redirect(url_for("user_movies", user_id=user_object.user_id)) else: flash("Login incorrect!") return redirect("/")
def authenticate(): email = request.form['email'] password = request.form['password'] user_id = model.authenticate(self, email, password) if user_id != None: session['user_id'] = user_id return render_template("ratings.html") else: return redirect("/login")
def login(): #TODO: add validation form = request.form email = form["email"] password = form["password"] name = model.authenticate(email, password) if name: return render_template("dashboard.html", name=name) flash("Password and Email invalid. Sucks to be you.") return render_template("login.html")
def login(): if request.method == 'POST': user = model.authenticate(request.form['username'], request.form['password']) if user: login_user(user) url = request.form['next'] if 'next' in request.form else '/' return redirect(url) else: flash('Invalid login', 'error') return redirect('/login') return render_template('login.html', next=request.args.get('next'))
def process_login(): emailform = request.form.get("email") passwordform = request.form.get("password") email = model.authenticate(emailform, hash(passwordform)) if email != None: flash("User authenticated!") session['email'] = email else: flash("Password incorrect, please try again.") return redirect(url_for("main_menu"))
def process_login(): user_id = request.form.get("user_id") password = request.form.get("password") user_id = model.authenticate(user_id, password) if user_id: flash("User authenticated") session["user_id"] = user_id else: flash("WRONG.") return redirect(url_for("index"))
def process_login(): username = request.form.get("username") password = request.form.get("password") if model.authenticate(username, password): flash("User authenticated") else: flash("Password incorrect, there may be a ferret stampede") return redirect(url_for("index"))
def POST(self): login = web.input() if model.authenticate(login.username,login.password)=='True': session.logged_in = True session.username = login.username print session raise web.seeother('/home') else: raise web.seeother('/login') return render.form()
def process_login(): username = request.form.get("username") password = request.form.get("password") auth_user = model.authenticate(username, password) if auth_user != None: session['username'] = auth_user session['actual_username'] = username else: flash("Password incorrect, please try again!") return redirect(url_for("index"))
def process_login(): username = request.form.get("username") password = request.form.get("password") user_id = model.authenticate(username, password) if user_id != None: flash("User authenticated!") session['id'] = user_id return redirect(url_for ("view_user", username = username)) else: flash("Password incorrect, there may be a ferret stampede in progress!") return redirect(url_for("index"))
def process_login(): username = request.form.get("username") password = request.form.get("password") user_id = model.authenticate(username, password) if user_id != None: flash("User authenticated!") session['user_id'] = user_id return redirect(url_for("view_user", username=username)) else: flash('Username or password incorrect!') return redirect(url_for("index"))
def authenticate(): email = request.form["email"] password = request.form["password"] user_id = model.authenticate(email, password) #(g.db, email, password)? # DOESN'T WORK IF AREN'T IN DB??! if user_id: fsession["user_id"] = user_id fsession["email"] = email return redirect("/view_user") else: flash("I'm sorry, either that password or email is not in our database.") return redirect("/")
def login(): email = request.form.get("email") password = request.form.get("password") user_info = model.authenticate(email, password) if user_info != None: session['user_id'] = user_info[0] session['email'] = user_info[1] return redirect("/users/%s" %user_info[0]) else: flash("Your login credentials are not recognized. Sorry!") return render_template("index.html")
def process_login(): email = request.form.get("email") password = hash(request.form.get("password")) user = model.authenticate(email, password) if user: session['user_id'] = user.id # sessionUserId = model.Session.query(model.User).get(id) return redirect(url_for("getMyRatings")) else: flash("Email or Password incorrect, grab your shit umbrella!") return redirect(url_for("index"))
def process_login(): email = request.form.get("email") password = request.form.get("password") if model.authenticate(email, password): flash("You're in!") session['email'] = email user_email = session.get("email") user = model.s.query(model.User).filter_by(email = user_email).first() user = user.id return redirect(url_for("user_page", user_id=user)) else: flash("No movie ratings for you!") return redirect(url_for("index"))
def process_login(): username = request.form.get("username") password = request.form.get("password") auth_user = model.authenticate(username, password) if auth_user != None: flash("User authenticated!") session['username'] = auth_user session['actual_username'] = username else: flash("Password incorrect, there may be a ferret stampede in progress!") return redirect(url_for("index"))
def process_login(): username = request.form.get("username") password = request.form.get("password") user_id = model.authenticate(username, password) if user_id != None: flash("User authenticated") session['user_id'] = user_id else: flash("Password incorrect, there may be dragons.") return redirect(url_for("index"))
def sign_in(): email = request.form.get("email") password = request.form.get("password") user_id = authenticate(email, password) if user_id is not None: flash("loggedin!") session['user_id'] = user_id print session.get('user_id') # return redirect(url_for("view_user_ratings", user_id = user_id)) else: flash("Password or email incorrect. Try again.") return redirect(url_for("index"))
def authenticate(): email = request.form["email"] password = request.form["password"] user_id = model.authenticate(email, password) #(g.db, email, password)? # DOESN'T WORK IF AREN'T IN DB??! if user_id: fsession["user_id"] = user_id fsession["email"] = email return redirect("/view_user") else: flash( "I'm sorry, either that password or email is not in our database.") return redirect("/")
def process_login(): username = request.form.get("username") password = request.form.get("password") legit_username = model.authenticate(username, password) print legit_username if legit_username != None: flash("User authenticated!") session["username"] = legit_username else: flash("Password incorrect. There may be a ferret stampede in progress!") return redirect(url_for("view_user", username = legit_username))
def sign_in(): email = request.form.get("email") password = request.form.get("password") user_id = model.authenticate(email, password) if user_id != None: flash("loggedin!") session['user_id'] = user_id print session.get('user_id') # return redirect(url_for("view_user_ratings", user_id = user_id)) else: flash("Password or email incorrect. Try again.") return redirect(url_for("index"))
def process_login(): username = request.form.get("username") password = request.form.get("password") user_id = model.authenticate(username, password) if username != None: flash("User authenticated!") session['user_id'] = user_id session['username'] = username else: flash("Password incorrect, there may be a ferret stampede in progress!") return redirect(url_for("index"))#render_template("login.html")
def process_login(): username = request.form.get("username") password = request.form.get("password") model.connect_to_db() user_id = model.authenticate(username, password) if user_id > 0: flash("User authenticated") session['user_id'] = user_id return redirect(url_for("view_user", username= username)) else: flash("Invalid credentials") print ("model said no go on password") model.CONN.close() return redirect(url_for("index"))
def process_login(): emailform = request.form.get("email") passwordform = request.form.get("password") email = model.authenticate(emailform, hash(passwordform)) print "functionreturn", email if email == "Auth failed" or email == None: flash("Password incorrect, please try again.") user = None return render_template("login.html", user=user) else: flash("User authenticated!") session['email'] = email return redirect(url_for("main_menu"))
def process_login(): username = request.form.get("username") password = request.form.get("password") legit_username = model.authenticate(username, password) print legit_username if legit_username != None: flash("User authenticated!") session["username"] = legit_username else: flash( "Password incorrect. There may be a ferret stampede in progress!") return redirect(url_for("view_user", username=legit_username))
def process_login(): username = request.form.get("username") password = request.form.get("password") user_id = model.authenticate(username, hash(password)) # return user_id if user_id != None: flash("User authenticated!") #session['username'] = username session['user_id'] = user_id else: flash("Password incorrect, there may be a ferret stampede in progress.") return redirect(url_for("index"))
def process_login(): username = request.form.get("username") # variable with methods password = request.form.get("password") # variable with methods user_id = model.authenticate(username, hash(password)) # variable with method? # return user_id # logical oparation IF/ELSE if user_id != None: flash("User authenticated!") # flash is from FLASK session['user_id'] = user_id # else: flash("Password incorrect, there may be a ferret stampede in progress.") #return redirect(url_for("index", username=username)) return redirect(url_for("show_user_profile", username=username))
def dashboard(): # Authenticate the user if request.method == 'GET': try: if session['username']: return render_template("dashboard.html", name=session["username"]) else: abort(401) except: abort(401) else: if model.authenticate(request): return render_template("dashboard.html", name=session["username"]) else: return render_template("sign_in.html", failed=True)
def process_login(): username = request.form.get("username") password = request.form.get("password") #and use the authenticate function to check if username and password match user_id = model.authenticate(username, password) if user_id != None: # flash("User authenticated!") #setting the session user id to the user's user_id session['user_id'] = user_id else: #if password entered incorrectly also if username doesn't exist flash("Password or username incorrect, there may be an issue.") #send them back to login if there is an issue here #we are redirecting them either way here but it checks again if they are logged in return redirect(url_for("index"))
def process_login(): username = request.form.get("username") password = request.form.get("password") # flash is a function that takes in a string. Each string is queued in the flash, # waiting to be displayed only once. user_id = model.authenticate(username, password) thewall.connect_to_db() if username != None: flash("User authenticated!") session['username'] = user_id # put user_id into the session rather than username else: flash('Password incorrect, there may be a ferret stampeded in progress!') return redirect(url_for("index"))
def process_login(): username = request.form.get("username") password = request.form.get("password") status = model.authenticate(username, password) if status == "SUCCESS": flash("User authenticated") session['username'] = username return redirect(url_for("index")) elif status == "no_user": flash("User does not exist") return redirect(url_for("index")) elif status == "incorrect": flash( "Username or Password incorrect, there may be a ferret stampede in progress!" ) return redirect(url_for("index"))
def process_login(): username = request.form.get("username") password = request.form.get("password") # authenticate user. if authenticated, returns id. else, returns None user_id = model.authenticate(username, password) if user_id != None: # if user authenticated, set the user_id on the session session['user_id'] = user_id else: # if not authenticated, flash an error message flash("Password or username incorrect. Please try again.") # everyone redirects to index. if auth, this will redirect again to wall. # this seems unnecessary - should we just put it in the if/else? return redirect(url_for("index"))
def login(): if 'user_id' in session: return redirect('/') if request.method == 'POST': data = request.form.to_dict(flat=True) result = model.authenticate(data['username'], data['password']) if isinstance(result, model.User): session.permanent = True session['user_id'] = result.id session['user_admin'] = result.admin return redirect('/') else: return router['login'](['invalid']) return router['login']()
def process_login(): username = request.form.get("username") password = request.form.get("password") username = model.authenticate(username, password) print username if username == False: flash("User does not exist. Please register below.") return redirect(url_for("register")) elif username != None: flash("User authenticated!") session['username'] = username return redirect( url_for("view_user", username=request.form.get("username"))) elif username == None: flash( "Password incorrect, there may be a ferret stampede in progress!") return redirect(url_for("index"))
def on_btn_ok_clicked(self): if not model.authenticate( self.usr_name, unicode(self.edit_old_pwd.text())): QMessageBox.critical(self, u"修改密码", u"旧密码错误!") return if self.edit_new_pwd.text() != self.edit_new_pwd_2.text(): QMessageBox.critical(self, u"修改密码", u"两次输入的密码不一致!!") return if model.set_pwd( self.usr_name, unicode(self.edit_new_pwd.text())): QMessageBox.information(self, u"修改密码", u"密码修改成功!") self.done(QDialog.Accepted) else: QMessageBox.critical(self, u"修改密码", u"密码修改失败!")
def test_can_get_tweet_reply_message(self): """ End to End Test: Logs in, and then attempts to extract relevant info from a Reply tweet. """ api = authenticate() my_name = api.me().screen_name my_id = api.me().id # send message initial_message = generate_random_string(25) api.update_status(initial_message) time.sleep(1) timeline = api.user_timeline(my_id) initial_tweet = timeline[0] self.assertEquals(initial_tweet.text, initial_message) reply_msg = f"@{my_name} (reply) {generate_random_string(20)}" api.update_status(reply_msg, in_reply_to_status_id=initial_tweet.id) time.sleep(1) most_recent_mentions = api.mentions_timeline() tweet = most_recent_mentions[0] # How to handle reply text. reply_id = tweet.in_reply_to_status_id if isinstance(reply_id, int): explanatory_text = tweet.text target_tweet = api.get_status(reply_id) json_string = json.dumps(target_tweet._json) filtered_data = parse_tweet_data(json_string) filtered_data.update({"explanation_text": explanatory_text}) self.assertEquals(filtered_data["explanation_text"], reply_msg) self.assertEquals(filtered_data["text"], initial_tweet.text) self.assertEquals(filtered_data["id"], initial_tweet.id) else: self.fail("Tweet was not a reply tweet")
def process_login(): model.connect_to_db() username = request.form.get("username") password = request.form.get("password") # Checks user authenticated to then create a session user_id = model.authenticate(username, password) if user_id != None: flash("User authenticated!") session['user_id'] = user_id session['username'] = username elif model.get_user_by_name(username) is None: flash("Username does not exist, please register a new account") return redirect(url_for("register")) else: flash( "Password incorrect, there may be a ferret stampede in progress!") return redirect(url_for("index"))
def test_can_see_mentions(self): """ End to End Test: Logs in, and then sends a random tweet (using our name as the @mention) We then request the mentions timeline and check if the most recent mention is the message we have just sent. """ api = authenticate() my_name = api.me().screen_name # Create tweet where we @mention self. message = f"@{my_name} {generate_random_string(20)}" # send message api.update_status(message) most_recent_mention = api.mentions_timeline()[0] actual = most_recent_mention.text self.assertEquals(actual, message)
def login(): if 'user_id' in session: return redirect(url_for('status')) if request.method == 'POST': data = request.form.to_dict(flat=True) email = data['email'] password = data['password'] result = model.authenticate(email, password) if isinstance(result, model.User): session.permanent = True session['user_id'] = result.id session['user_admin'] = result.admin return redirect(url_for('status')) else: return router['login'](['invalid']) return router['login']([])
def authenticate(): email = request.form["email"] password = request.form["password"] user_id = model.authenticate(g.db, email, password) session["user_id"] = user_id return redirect("/tasks")