def authorized(): if "error" in request.args: # User cancelled the auth flow - discard auth (most likely there won't be any) session.pop("twitch_token", None) return redirect(url_for("mainpage")) twitch = OAuth2Session(config.CLIENT_ID, config.CLIENT_SECRET, state=session["login_state"]) resp = twitch.fetch_access_token("https://id.twitch.tv/oauth2/token", code=request.args["code"], # For some bizarre reason, we need to pass this information along. client_id=config.CLIENT_ID, client_secret=config.CLIENT_SECRET, redirect_uri=os.environ.get("OVERRIDE_REDIRECT_URI") or url_for("authorized", _external=True)) if "access_token" not in resp: # Something went wrong with the retrieval. No idea what or why, # so I'm doing a cop-out and just dumping to console. print("Unable to log in", file=sys.stderr) pprint(resp, stream=sys.stderr) print("Returning generic failure.", file=sys.stderr) raise Exception session["twitch_token"] = resp["access_token"] session["twitch_refresh_token"] = resp["refresh_token"] session["twitch_auth_scopes"] = " ".join(sorted(resp["scope"])) # kraken_user = query("kraken/user", token="oauth") # The Kraken response includes fields not in Helix, including created_at, # and email (though Helix gives us the latter if we add an OAuth scope). user = query("helix/users", token="bearer")["data"][0] user["_id"] = user["id"] # For now, everything looks for _id. Existing logins don't have user["id"]. database.login_user(user["_id"], session["twitch_token"]) session["twitch_user"] = user return redirect(url_for("mainpage"))
def login(): if request.method == 'POST': form_user_name = request.form.get('user_name') form_password = request.form.get('password') user = User.query.filter_by(user_name=form_user_name).first() if check_password_hash(user.password, form_password): login_user(user) return redirect('/admin') else: title = "Skipcafe|Login" return render_template('login.html', title=title)
def login(connection): first_name = input("Enter your firstname ") pass_word = getpass.getpass(prompt='Enter password') if database.login_user(connection, first_name): stats, password = database.login_user(connection, first_name) if password == pass_word and stats == 'admin': print("Test is gotten ") elif password == pass_word and stats != 'admin': print("second ack ") else: print("please check your password ") else: print("Your username does not exist") dev.sign_up(connection)
def login(): data = request.get_json(silent=True) print('Check ', data.get('username'), ' login.') login_result = db.login_user(data.get('username'), data.get('password')) if (login_result == 'FAIL'): return login_result else: token = jwt.encode( { 'sub': login_result['username'], 'iat': datetime.utcnow(), 'exp': datetime.utcnow() + timedelta(minutes=60) }, current_app.config['SECRET_KEY']) return jsonify({ 'token': token.decode('UTF-8'), 'username': login_result['username'], 'email': login_result['email'], 'firstname': login_result['firstname'], 'lastname': login_result['lastname'], 'address': login_result['address'], 'city': login_result['city'], 'country': login_result['country'], 'about': login_result['about'], 'type': login_result['level'], 'imgtype': login_result['imgtype'], 'postalcode': login_result['postalcode'], 'avatar': login_result['profileimg'] })
def login(): """Logs in the user.""" if 'username' in session: return jsonify(ok=0, msg='You are already log in') user = request.form['user'] passw = request.form['pass'] if database.login_user(user, passw): session['username'] = user session['userid'] = database.get_userid(user) session['password'] = passw return jsonify(ok=1, msg='User is log in now') return jsonify(ok=0, msg='User could not be log in')
def del_entrie(): """Deletes the entrie entrieID.""" if not 'username' in session or \ not 'password' in session or \ not database.login_user(session['username'], session['password']): return jsonify(ok=0, msg='User is not log in') entrieid = request.form['entrieID'] if database.del_entrie(entrieid, session['userid']): return jsonify(ok=1) return jsonify(ok=0, msg='Entrie could not be deleted')
def login_user(): if not request.json or 'Login' not in request.json: print("LOL") abort(400) return_data = db.login_user(request.json) print(bcrypt.hashpw(b"admin1", bcrypt.gensalt())) password = request.json['Password'].encode('utf-8') hash = return_data[0]['Password'].encode('utf-8') if(len(return_data) == 0): return make_response(jsonify({'error': 'invalid user name'}), 404) else: if(bcrypt.checkpw(password,hash)): return_data[0].pop('Password') # we don't need to return password to the user return make_response(jsonify(return_data), 200) else: return make_response(jsonify({'error': "wrong password"}),401)
def act_login(request): """Authenticates login with email and password :param request: json request from client :returns: json of jwt """ username = request.get('username', None) password = request.get('password', None) # check if user exists and the password is correct if login_user(username, password): res = {'jwt': create_jwt(identity=username)} return jsonify(res), 200 return jsonify({'error': 'username or password is incorrect'}), 400
def socket_login(message): """ Process login even from a player. """ LOGGER.info(f"Login requested: {message}") try: email = message["email"] password = message["password"] except KeyError as error: raise UnauthorizedError( "A username and password must be provided to log in") from error user = login_user(database_session, email, password) # Push user into the proxy object for later reference current_user.push(user) LOGGER.info(f"{user!r} successfully logged in") emit("login_accepted", user)
def add_entrie(): """Adds a new entrie.""" if not 'username' in session or \ not 'password' in session or \ not database.login_user(session['username'], session['password']): return jsonify(ok=0, msg='User is not log in') name = request.form['name'] cityname = request.form['cityName'] gmt = int(request.form['gmt']) entrieid = int(request.form['id']) if name == "" or cityname == "" or gmt < -20 or gmt > 20: return jsonify(ok=0, msg='Entrie is invalid') userid = session['userid'] if entrieid == -1: entrieid = database.add_entrie(name, cityname, gmt, userid) else: database.modify_entrie(entrieid, name, cityname, gmt, userid) if entrieid is not None: return jsonify(ok=1, entrieID=entrieid) return jsonify(ok=0, msg='Entrie could not be added')
def get_entries(): """Returns all the entries from a user, filtered by namefilter.""" if not 'username' in session or \ not 'password' in session or \ not database.login_user(session['username'], session['password']): return jsonify(ok=0, msg='User is not log in') namefilter = request.args.get('nameFilter', None) entries = database.get_entries(session['userid'], namefilter) data = "[" addcomma = False for entrie in entries: if addcomma: data += ", " else: addcomma = True data += '{"name": "' + entrie['name'] + '", "cityName": "' + \ entrie['cityName'] + '", "gmt": ' + str(entrie['gmt']) + \ ', "id": '+ str(entrie['id']) +'}' data += "]" return jsonify(ok=1, entries=data)
def login(): # login page try: session["logged_in"] except KeyError: session["logged_in"] = False print(session['logged_in']) if not session["logged_in"]: if request.method == "GET": return render_template("login.html", error=False) else: usr = request.form['username'] pas = request.form['password'] check = login_user(usr, pas) if check == False: return render_template("login.html", error=True) elif request.method == "POST": session["logged_in"] = True session['user_id'] = check[0] return redirect(url_for("main")) else: return redirect(url_for("main"))
def is_logged_in(): """Checks if user is logged in or not.""" if 'username' in session and 'password' in session: if database.login_user(session['username'], session['password']): return jsonify(ok=1, user=session['username']) return jsonify(ok=0)