def checkUser(cls): if request.method == "POST": email = request.form['emailaddress'].upper() password = request.form['password'] conn = DataBaseManager.database_connection() cur = conn.cursor() try: query = "SELECT * FROM users WHERE email=%s" cur.execute(query, (email, )) row = cur.fetchone() if row: if (sha256_crypt.verify(password, row[3])): user = User(*row) if user.roleid == "002": session['userdatalist'] = user.getData() return redirect(url_for('loadAssociateHome')) if user.roleid == "003": session['userdatalist'] = user.getData() return redirect(url_for('loadAdminHome')) if user.roleid == "001": session['userdatalist'] = user.getData() return redirect(url_for('loadManagerHome')) else: return render_template( 'login.html', message="Wrong email or password") else: return render_template('login.html', message="Wrong email or password") finally: conn.close() else: return render_template('login.html')
def post(self): json_data = request.get_json() username = json_data.get('username') email = json_data.get('email') non_hash_password = json_data.get('password') if User.get_by_username(username): return {'message': 'username already'}, HTTPStatus.BAD_REQUEST if User.get_by_email(email): return {'message': 'email already exists'}, HTTPStatus.BAD_REQUEST password = hash_password(non_hash_password) user = User(username=username, email=email, password=password) user.save() data = { 'id': user.id, 'username': user.username, 'email': user.email } return data, HTTPStatus.CREATED
def post(self): data = Register.parser.parse_args() if User.find_by_username(data.username): return ResponseHandler.error('user exists', 400) user = User(**data) user.save() if user.id: return ResponseHandler.success('User Added', 200, data=user.json()) return ResponseHandler.error('user not added', 400)
def checkUserRegister ( cls, email ): conn = DataBaseManager.database_connection() cur = conn.cursor() try: email = email.upper() query = "SELECT * FROM users WHERE email=%s" cur.execute ( query, (email,) ) row = cur.fetchone() if row: return User ( *row ) else: return None finally: conn.close()
def signin(): if request.method == "GET": return render_template('signin.html') elif request.method == "POST": form = request.form name = form['name'] email = form['email'] username = form['username'] password = form['password'] new_user = User(name=name, email=email, username=username, password=password) new_user.save() return redirect(url_for('index'))
def post(self): username = request.form.get('username') email = request.form.get('email') password = request.form.get('password') existing_user = User.query.filter_by(email=email).first() if not username or not email or not password: flash("Tüm alanları doldurun!", "signup") elif existing_user: flash("Geçersiz email adresi!", "signup") else: user = User(username=username, email=email, password=password) user.save() login_user(user) return redirect('/home') return redirect('/')
def registerAdmin(username: str, password: str): """Registers a new admin, if the username isn't yet taken Parameters ---------- name : username The user login name : password The password set for that user Raises ---------- ExistingUserException If an already existing username is passed as the first argument. """ if (userExists(username)): raise exceptions.ExistingUserException( "{0} already exists in the database".format(username)) else: newUser = User(username, password, True) jsonUser = newUser.toJSON() usersCollection.insert_one(jsonUser) ##link = Link (["Grumbarg"], "<0> es <1> del ejército de <2>", ["general", "Rahash"], "Grumbarg el grande", 1) ##addLink(link) ##newLink = getLink(link.getName()) ##print(newLink.getFullText()) ##print (existsLink("holaa")) ##print (getLinkByLinks("pájaro").getName()) ##print (getLinksByField("alias", "hola")) ##for i in getLinksContainingWord("alias", "guerra"): ## print (i) ##print (getLink("Ruiseñor escarlata").getFormattedText()) ##print (getLink("Ruiseñor escarlata").getFullText()) ##print (getLinkByField("alias", "Muertos")) ##for link in getLinksByField("_id", "5fd2bcf54e318fc347906f78"): # print (link) # link = getLink("Mijail") # print (link.id) # link.alias.append("Mikhail") # updateLinkById(link.id, link) #print (userExists("joaquinollo")) #registerUser("joaco", "esdla03")
def login(): conn = db_connection() cursor = conn.cursor() user = None if request.method == 'POST': data = request.get_json() pseudo = data['pseudo'] password = data['password'] sql = """SELECT id, pseudo, mail, password FROM user WHERE pseudo =? and password =?""" cursor.execute(sql, (pseudo, password)) row = cursor.fetchone() if row is not None: user = User(row[0], row[1], row[2], row[3]) token = JwtService().create(user) return token, 200 cursor.close() conn.close() return "Can't authenticate", 401
def authenticateUser(username: str, password: str) -> bool: """Returns a bool value indicating whether the provided username and password match to a user registered, or not. Parameters ---------- name : username The user login name : password The password set for that user """ authenticated = False query = {"username": username} entity = usersCollection.find_one(query) if (entity): newUser = User(entity["username"], entity["password"], entity["admin"], True) authenticated = newUser.verify_password(password) return authenticated
def getUserInfo(self): try: tables = self.getPdfTables(True, False) except PdfReadError as error: print(str(error) + ", Please check your password!") return None # if password is incorrect function will return None userInfo = list() # list of tables object userInfoStr = list() # list of strings in tables objects userInfo = tables[0].df[0] for info in userInfo: if info == "": continue else: userInfoStr.append(str(info).replace(";", "")) Len = userInfoStr.__len__() # length of userInfoStr # Email email = re.search("\w+@+\w+\.+\w+", userInfoStr[0]) # print(email.group(0)) # Name name = re.search("[a-zA-Z\s]+", userInfoStr[1]) # print(name.group(0)) # address address = "" for i in range(2, Len - 1): address = "".join([address, userInfoStr[i], " "]) # print(address) # phone if re.search("\+", userInfoStr[Len - 1]): phone = re.search("\+\d{12}", userInfoStr[Len - 1]) else: phone = re.search("\d{10}", userInfoStr[Len - 1]) # print(phone.group(0)) user = User(name.group(0), "", email.group(0), phone.group(0), address) self.user = user
def registerUser(username: str, password: str): """Registers a new user, if the username isn't yet taken Parameters ---------- name : username The user login name : password The password set for that user Raises ---------- ExistingUserException If an already existing username is passed as the first argument. """ if (userExists(username)): raise exceptions.ExistingUserException( "{0} already exists in the database".format(username)) else: newUser = User(username, password) jsonUser = newUser.toJSON() usersCollection.insert_one(jsonUser)
def userlogin(): return User().login()
def usersignup(): return User().signup()
def usersignout(): return User().signout()
if not 200 < response.status_code < 300: response.raise_for_status() data = json.loads(response.text) return data def example_get_chat_messages(user): response = get_user_chat_id(user.email) data = json.loads(response.text) chat_id = data['Id'] response = get_chat_messages(user.id, chat_id, size=10) if not 200 < response.status_code < 300: response.raise_for_status() data = json.loads(response.text) return data user_email = '*****@*****.**' print(example_get_user_by_email(user_email)) user = User(example_get_user_by_email(user_email)) group_id = example_get_groups_of_user(user) group = Group(example_get_group(user.id, group_id)) print(group) result = example_send_push_notification(user) print result #result = example_post_new_card_with_impersonation(user, user.id) #print(result)
def callback(): try: # Get authorization code Google sent back to you code = request.args.get("code") # Find out what URL to hit to get tokens that allow you to ask for # things on behalf of a user google_provider_cfg = get_google_provider_cfg() token_endpoint = google_provider_cfg["token_endpoint"] logging.error("1") token_url, headers, body = client.prepare_token_request( token_endpoint, authorization_response=request.url, redirect_url=request.base_url, code=code ) logging.error("2") token_response = requests.post( token_url, headers=headers, data=body, auth=(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET), ) logging.error("3") # Parse the tokens! client.parse_request_body_response(json.dumps(token_response.json())) logging.error("4") # Now that you have tokens (yay) let's find and hit the URL # from Google that gives you the user's profile information, # including their Google profile image and email userinfo_endpoint = google_provider_cfg["userinfo_endpoint"] uri, headers, body = client.add_token(userinfo_endpoint) userinfo_response = requests.get(uri, headers=headers, data=body) logging.error("5") # You want to make sure their email is verified. # The user authenticated with Google, authorized your # app, and now you've verified their email through Google! if userinfo_response.json().get("email_verified"): unique_id = userinfo_response.json()["sub"] users_email = userinfo_response.json()["email"] picture = userinfo_response.json()["picture"] users_name = userinfo_response.json()["given_name"] else: return "User email not available or not verified by Google.", 400 logging.error("6") # Create a user in your db with the information provided # by Google user = User( id_=unique_id, name=users_name, email=users_email, profile_pic=picture ) logging.error("7") # Begin user session by logging the user in login_user(user) logging.error("8") # Send user back to homepage return "ok" except Exception as ex: logging.error(ex) return ex