def login(self): user = authenticate(request.form.get("username"), request.form.get("password")) if user: login(user) return SUCCESS_RESP else: raise APIError(401, "AuthError")
def login(): try: username = request.json.get("username", None) password = request.json.get("password", None) user = authenticate(username=username, password=password) if user == None: return jsonify({"Login failed": "Bad username or password"}), 401 access_token = create_access_token(identity=username) return jsonify(access_token=access_token) except: return {"Your request is invalid, are you using the correct format?": {"Format": {"username": "******", "password": "******"}}}, 400
def login(): if current_user.is_authenticated() and current_user.is_active(): return redirect(url_for('index')) if request.method == "POST": username = request.form['username'] password = request.form['password'] if(username and password): # do login because username and password have been specified uid = user.authenticate(username, password) if uid != None: login_user(user.get(uid)) return redirect(url_for('index')) return render_template('login.html')
def authenticate(): session['username'] = request.form['username'] session['password'] = request.form['password'] print(session) # Both username and password are valid ================ if user.authenticate(session['username'], session['password']): return redirect("/menu") # All other invalid cases ============================= else: msg = "It looks like you've entered an invalid password or username. Please try again." return render_template("login.html", message=msg) print(url_for('disp_login')) print(url_for('authenticate')) return redirect(url_for("disp_login"))
def login(email, password): """ This function handles the login of an email/password pair. As of now, we aren't sure how auth is being implemented. So this is just a dummy stub that redirects to the login page. :param email: The email address of the user to login as :param password: The password for the specified user :return: A redirect to a page that indicates success/failure as needed """ user = authenticate(email, password) if user is None or not user: # TODO: Change this to an error page return redirect(url_for('login_page')) else: # TODO: Change this to contain a cookie with the auth key or whatever session['username'] = email return redirect(url_for('login_page'))
def parse_params(parameters, ip=False): try: client = MongoClient() mongodb = client.socrates result = "{}" #string result from each run-type to print at the end working_set = None working_set_id = -1 working_set_name = "Untitled" if 'username' in parameters and 'password' in parameters: if 'register' in parameters: #register new user taken = not user.register(parameters['username'], parameters['password']) result = json.dumps({"attempted": True, "taken" : taken}) else: #authenticate if not user.authenticate(parameters['username'], parameters['password']): return _err("Invalid username and password") else: #use default user user.setDefault() if 'working_set_id' in parameters: working_set_id = parameters['working_set_id'] working_set = user.getWorkingSet(working_set_id) working_set_name = working_set["working_set_name"] if 'working_set_name' in parameters: working_set_name = parameters['working_set_name'] #mutually exclusive if-elif if 'module' in parameters: typ = parameters['type'] mod = parameters['module'] fn = parameters['function'] print "Running %s, %s, %s\n" % (typ, mod, fn) param = {} if "input" in parameters: param = parameters["input"] return_all_data = False if "return_all_data" in parameters: return_all_data = parameters["return_all_data"] if typ == "analysis" and working_set is None: return _err("Working set id not included") (working_set, is_new) = run(typ, mod, fn, param, working_set) user.log_run(typ, mod, fn) if ip: user.log_activity("run_ip", ip) if working_set is None: return _err("Internal operation error") if 'error' in working_set and working_set['error']: return _err("error: " + working_set['message']) #store new/modified working set working_set["working_set_name"] = working_set_name if is_new: insert_id = user.addWorkingSet(working_set) working_set['working_set_id'] = str(insert_id) else: user.updateWorkingSet(working_set_id, working_set) #overwrite in database working_set['working_set_id'] = str(working_set_id) if not return_all_data: #remove all data except first entry working_set["data"] = working_set["data"][0:1] if "analysis" in working_set: for i in range(len(working_set["analysis"])): a = working_set["analysis"][i] if "entry_analysis" in a: for p in a['entry_analysis']: a['entry_analysis'][p] = a['entry_analysis'][p][0:1] return dumps(working_set) elif 'specs' in parameters: print "Fetching specs\n" if ip: user.log_activity("fetch_ip", ip) return json.dumps(getAllSpecs()) elif 'fetch' in parameters: working_set = user.getWorkingSet(working_set_id) working_set['working_set_id'] = str(working_set_id) #add if statement here to check for datasetonly parameter if 'datasetonly' in parameters and parameters['datasetonly']=='true': working_set.pop("analysis",None) working_set.pop("visualization", None) #check format parameter if 'format' in parameters and parameters['format']=='csv': return pd.io.json.json_normalize(working_set['data']).to_csv(encoding='utf-8') elif 'format' in parameters and parameters['format']=='json': return dumps(working_set) elif 'remove' in parameters: user.removeWorkingSet(working_set_id) return dumps({"status" : "success"}) elif 'rename' in parameters: user.renameWorkingSet(working_set_id, parameters['new_name']) return dumps({"status" : "success"}) elif 'fetch_all_ids' in parameters: working_sets = user.getWorkingSets() working_set_identifiers = [] for w in working_sets: wid = { "id" : w["working_set_id"], "name" : "Untitled" } if "working_set_name" in w: wid["name"] = w["working_set_name"] working_set_identifiers.append(wid) return dumps({"ids" : working_set_identifiers}) elif 'upload' in parameters: working_set = None default_working_set_name = "Imported Dataset" data = parameters['working_set_data'] format = parameters['format'] if format not in ["csv", "json"]: return _err("Invalid upload format selected") if format == "json": try: working_set = json.loads(data) #no additional parsing necessary except ValueError as ve: return _err("Working set JSON could not be parsed") elif format == "csv": #parse string as csv working_set = _parseCSV(data) if working_set is not None: if "working_set_name" not in working_set: working_set["working_set_name"] = default_working_set_name working_set_id = user.addWorkingSet(working_set) return dumps({ "id" : str(working_set_id), "name" : working_set["working_set_name"] }) else: return _err("Could not upload") return result; except Exception as e: sys.stderr.write("Exception caught: %s\n" % e) sys.stderr.write("Stack trace:\n%s\n" % traceback.format_exc())
def sign_out(user_name): if user.signout(user_name): print("Successfully signed out.") else: second_option = input("Not signed in.\n1. Sign in?\n2. Exit?\n") # Can't sign out if not signed in. if second_option == '1': sign_in(user_name) else: exit(0) option = input('Please select an option below: \n1.Login.\n2.Register.\n') if option == '1': username = input('Please enter your username: '******'Enter password: '******'Welcome ', user.get_name(username)) print('Please choose an option below:') log = input('1. Sign-in.\n2. Signout.\n') if log == '1': sign_in(username) elif log == '2': sign_out(username) else: print('Incorrect selection.') # Error handling else: print('Incorrect username and password combination.') elif option == '2': print('Welcome to the registration page.')
def parse_params(parameters, ip=False): try: client = MongoClient() mongodb = client.socrates result = "{}" #string result from each run-type to print at the end working_set = None working_set_id = -1 working_set_name = "Untitled" if 'username' in parameters and 'password' in parameters: if 'register' in parameters: #register new user taken = not user.register(parameters['username'], parameters['password']) result = json.dumps({"attempted": True, "taken" : taken}) else: #authenticate if not user.authenticate(parameters['username'], parameters['password']): return _err("Invalid username and password") else: #use default user user.setDefault() if 'working_set_id' in parameters: working_set_id = parameters['working_set_id'] working_set = user.getWorkingSet(working_set_id) working_set_name = working_set["working_set_name"] if 'working_set_name' in parameters: working_set_name = parameters['working_set_name'] #mutually exclusive if-elif if 'module' in parameters: typ = parameters['type'] mod = parameters['module'] fn = parameters['function'] print "Running %s, %s, %s\n" % (typ, mod, fn) param = {} if "input" in parameters: param = parameters["input"] return_all_data = False if "return_all_data" in parameters: return_all_data = parameters["return_all_data"] if typ == "analysis" and working_set is None: return _err("Working set id not included") (working_set, is_new) = run(typ, mod, fn, param, working_set) user.log_run(typ, mod, fn) if ip: user.log_activity("run_ip", ip) if working_set is None: return _err("Internal operation error") if 'error' in working_set and working_set['error']: return _err("error: " + working_set['message']) #store new/modified working set working_set["working_set_name"] = working_set_name if is_new: insert_id = user.addWorkingSet(working_set) #user.test(working_set) working_set['working_set_id'] = str(insert_id) else: user.updateWorkingSet(working_set_id, working_set) #overwrite in database working_set['working_set_id'] = str(working_set_id) if not return_all_data: #remove all data except first entry working_set["data"] = working_set["data"][0:1] if "analysis" in working_set: for i in range(len(working_set["analysis"])): a = working_set["analysis"][i] if "entry_analysis" in a: for p in a['entry_analysis']: a['entry_analysis'][p] = a['entry_analysis'][p][0:1] return dumps(working_set) elif 'specs' in parameters: print "Fetching specs\n" if ip: user.log_activity("fetch_ip", ip) return json.dumps(getAllSpecs()) elif 'fetch' in parameters: working_set = user.getWorkingSet(working_set_id) working_set['working_set_id'] = str(working_set_id) return dumps(working_set) elif 'remove' in parameters: user.removeWorkingSet(working_set_id) return dumps({"status" : "success"}) elif 'rename' in parameters: user.renameWorkingSet(working_set_id, parameters['new_name']) return dumps({"status" : "success"}) elif 'fetch_all_ids' in parameters: working_sets = user.getWorkingSets() working_set_identifiers = [] for w in working_sets: wid = { "id" : w["working_set_id"], "name" : "Untitled" } if "working_set_name" in w: wid["name"] = w["working_set_name"] working_set_identifiers.append(wid) return dumps({ "ids" : working_set_identifiers }) elif 'upload' in parameters: working_set = None default_working_set_name = "Imported Dataset" data = parameters['working_set_data'] format = parameters['format'] if format not in ["csv", "json"]: return _err("Invalid upload format selected") if format == "json": try: working_set = json.loads(data) #no additional parsing necessary except ValueError as ve: return _err("Working set JSON could not be parsed") elif format == "csv": #parse string as csv working_set = _parseCSV(data) if working_set is not None: if "working_set_name" not in working_set: working_set["working_set_name"] = default_working_set_name working_set_id = user.addWorkingSet(working_set) return dumps({ "id" : str(working_set_id), "name" : working_set["working_set_name"] }) else: return _err("Could not upload") return result except Exception as e: sys.stderr.write("Exception caught: %s\n" % e) sys.stderr.write("Stack trace:\n%s\n" % traceback.format_exc())
def authenticate(request): username = request.form["uid"] password = request.form["password"] record = user.authenticate(username, password) return record