def home(): if "user_id" in session: user = user_class.User(user_id=session["user_id"]) user.get_user_by_id() return render_template('index.html', user=user) else: return render_template('index.html')
def login(): try: login_data = request.get_json() cur.execute("select user_id, first_name, username, password, spotify_id, activated from users where username=\'" + login_data['username'] + "\'") row = cur.fetchone() db_user = { 'user_id': row[0], 'first_name': row[1], 'username': row[2], 'password': row[3], 'spotify_id': row[4], 'activated': row[5] } if not check_password_hash(db_user['password'], login_data['password']): return {'error': 'incorrect username or password'} else: session['username'] = db_user['username'] session['first_name'] = db_user['first_name'] user_obj = user_class.User(str(db_user['user_id']).encode("utf-8"), session['username'], session['first_name']) # need activated account? user_obj.set_activated(db_user['activated']) user_obj.set_authenticated(True) login_user(user_obj) return {'success': 'Successfully logged in for ' + escape(session['username'])} except psycopg2.ProgrammingError as e: print(e) return {'error': 'Incorrect username or password.'} except Exception as e: print(e) return {'error': 'Unknown error while logging in'}
def user_login(email1, password1): user = user_class.User(email=email1, password=password1) ans = user.login() if (ans == True): return user else: return False
def user(): user = user_class.User('SMnRa',12) inputid = request.args.get('id') print(type(inputid)) print(type(user.id)) if int(inputid) == 12: return render_template('user_index.html',username = user.name,userid = user.id) else: return render_template('template_1.html',content = "Not Found user id, and id is %s" % inputid)
def user_signup(email1, password1, firstname1, lastname1, age1, phone1): user = user_class.User(email=email1, password=password1, firstName=firstname1, lastName=lastname1, age=age1, phoneNo=phone1) ans = user.signUp() return ans
def make_userlist(): the_list = [] ROOT = path.dirname(path.realpath(__file__)) conn = sqlite3.connect(path.join(ROOT, "database.db")) conn.row_factory = sqlite3.Row with conn: cursor = conn.cursor() cursor.execute("SELECT * FROM users") query = cursor.fetchall() for row in query: r = dict(row) usr = user_class.User(r["user_id"], r["username"], r["password"], r["email"]) the_list.append(usr) return the_list
def send_register(): if request.method == "POST": userr = request.form['username'] pwd = request.form['password'] rpwd = request.form['confirm_password'] mail_address = request.form['email'] if (pwd == "") or (pwd != rpwd) or (mail_address == ""): return render_template('register.html') if userr in users: return render_template('register.html') else: new_user = user_class.User(userr, "", mail_address) users[new_user] = pwd #return redirect(url_for('/'), code=302) return render_template("login.html")
def login(): user = user_class.User() if request.method == 'POST': user.username = request.form["username"] user.email = request.form["username"] password_candidate = request.form["password"] user.check_username() if sha256_crypt.verify(password_candidate, user.password): user.get_user_by_id() session['user_id'] = user.user_id session['username'] = user.username session.permanent = True return url_for("home") else: return 'Invalid user information', 400 else: return render_template('login.html', isLogin=True)
def user_space(self, connection, address): connection.send(self.banner.encode()) data = json.loads(connection.recv(1024).decode("utf-8")) access = False for one_user in self.__users_list.values(): if one_user.get("name") == data.get("name"): if one_user["password"] == data["password"]: access = True if access: if data["name"] == "4321": user = root_class.Root(data["name"], self.default_group, self.default_directory, self.history_path, self.config["history_length"], address, self) else: user = user_class.User(data["name"], self.default_group, self.default_directory, self.history_path, self.config["history_length"], address) if data["name"] in self.directories: user.cwd = self.directories[data["name"]] user.path = user.cwd.path self.users.append(user) user.set_connection(connection) connection.send("True".encode()) sleep(0.01) connection.send(user.path.encode()) print("new user {} from {}".format(user.name, address)) user.run_connected() user.disconnect() self.directories[user.name] = user.cwd self.users.remove(user) self.remote_addresses.remove(address) sys.exit() else: connection.send("False".encode()) self.remote_addresses.remove(address)
def register(): user = user_class.User() if request.method == 'POST': user.username = request.form["username"] user.email = request.form["email"] password_candidate = request.form["password"] user.password = sha256_crypt.hash(password_candidate) if user.check_unique(): user.insert_into_db() user.check_username() session['user_id'] = user.user_id session['username'] = user.username session.permanent = True return url_for("home") else: return "Username or email taken", 403 else: return render_template('login.html', isLogin=False)
def makeBoolArray(numstr): bool_array = np.zeros(shape=(1,user_class.numTopics),dtype=bool) for num in numstr: bool_array[0,int(num)]=True return bool_array def returnMatches(numstr): bool_array = makeBoolArray(numstr) posts = Post.query.all() print(posts) k = 2 # number of matches desired for suggestions if __name__ == "__main__": users = [ user_class.User("Person A", "a", datetime(1998, 1, 6)), user_class.User("Person B", "b", datetime(1985, 7, 21)), user_class.User("Person C", "c", datetime(1925, 1, 11)), user_class.User("Person D", "d", datetime(2001, 2, 5)), user_class.User("Person E", "e", datetime(1995, 9, 30)), user_class.User("Person F", "f", datetime(2012, 7, 13)), ] print("Topics of interest are", user_class.topics, "\n") for user in users: user.GenerateInterests() # randomly generate interest in topics print( user.name, "has interest mat", np.ma.masked_array(user_class.topics, mask=user.interests), )
def user_profile(name): user = user_class.User(user_id=session["user_id"]) user.get_user_by_id() return render_template('userprofile.html', user=user)
## In the user_class.py file, you'll code out your user class. ## Here, you can write tests to see if your user class is functioning correctly. ## This line of code is important. It's how your users.py program loads in your definition of the user class. ## Uncomment the line below for your program to run at all. import user_class ## If the line below runs without error, you're able to make an instance of a user class. ## As you can see, this user has a name, an email, a password, and an age. ## Uncomment this initializer and see if it runs without error. jolson615 = user_class.User("Jeff", "*****@*****.**", "password1", 28) ## If your first user was created successfully, the one below probably won't be. ## What would you need to change for Sarah to have an account? sarah773 = user_class.User("Sarah", "*****@*****.**", "mangotrain") ## Next, lets set a user's mood. jolson615.mood = "Happy" ## Now let's write a method called status_update that prints an update about a user's mood. ## For example, if we called this method on jolson615, it should print "I'm feeling Happy today." jolson615.status_update("Happy") ## let's finally write a method to try to change a user's password. It will take two arguments - the old password, and the new one. ## If the old password matches, it should change the password and print a success message. jolson615.change_password("password1", "moosedogredpine") ## If the old password doesn't match, it should print an error message. sarah773.change_password("mango", "mygreatnewpassword")
import requests import hashlib as hasher import datetime as date import random import user_class import os node = Flask(__name__) """ All global variables """ nodes = [] #All known nodes get added here vlocchain = [] #the main chain, most updated exchanges = [] #all the exchanges miner_address = "yeet" #temporary users = {} #full user dictionary, usernames admin = user_class.User("admin", "", "") users[admin] = "pass" #weblink = "https://127.0.0.1:5000/" #The main webwage of the website """ When this place gets pinged, make a new user and send the information out so the pinger can recieve it """ """ The home page of the website. If the user isn't logged in yet, it will bring them to the login page. Otherwise, the hub page will be rendered. """ @node.route('/', methods=['GET', 'POST']) def index(): if not session.get('logged'): #If the user is not logged in return render_template('login.html')
def sel_user(): user = None inputid = int(request.args.get('id')) if inputid == 12: user = user_class.User('SMnRa',12) return render_template('user_index_1.html',user = user)
def users(): userss = [] for i in range(1,10): userss.append(user_class.User('smnra_'+str(i),i)) return render_template('for_index.html',userss=userss)