def process_add_user(): client = data.get_client() categories = dao.get_all_categories(client) password = request.form.get('password') encrypted_password = pbkdf2_sha256.hash(password) email = request.form.get('email') name = request.form.get('name') age = request.form.get('age') gender = request.form.get('gender') occupation = request.form.get('occupation') user_exist = dao.get_user_by_email(client, email) if flask_login.current_user.is_authenticated: current_user = flask_login.current_user if current_user: user = dao.get_user_by_email(client, current_user.id) else: user = None if user_exist: flash('You have already registered! Please login.') return render_template('register.template.html', cat=categories, user=user) else: dao.add_user_to_db(client, email, name, encrypted_password, age, gender, occupation) redirect_url = request.args.get('redirect') if redirect_url is None: redirect_url = "/" return redirect(redirect_url)
def get(self, email, pageno=None): if pageno is None: print('pageno is none') return jsonify({'result': dao.get_user_by_email(email)}) else: offset = (pageno - 1) * 5 pageno = 5 return jsonify( {'result': dao.get_user_by_email(email, pageno, offset)})
def search(): client = data.get_client() search_by = request.args.get('search_by') search_str = request.args.get('search') filter_by_cat = request.args.get('filter_by_cat') filter_by_rating = request.args.get('filter_by_rating') results = dao.search_by_query(client, search_str, search_by, filter_by_cat, filter_by_rating) no_of_result = results.count() categories = dao.get_all_categories(client) all_users = dao.get_all_users(client) if flask_login.current_user.is_authenticated: current_user = flask_login.current_user if current_user: user = dao.get_user_by_email(client, current_user.id) else: user = None return render_template('search_result.template.html',results=results, search_str=search_str, user=user, cat=categories, all_users=all_users, no_of_result=no_of_result)
def check_user_log_in(client): current_user = flask_login.current_user if current_user: user = dao.get_user_by_email(client, current_user.id) else: user = None return user
def read_reviews(): client = data.get_client() latest_review = client[DB_NAME].user_reviews.find().sort('posted', pymongo.DESCENDING).limit(4) users = dao.get_all_users(client) categories = dao.get_all_categories(client) skincare_reviews = client[DB_NAME].user_reviews.find( { 'categories.name': 'Skin Care' } ).sort('posted', pymongo.DESCENDING).limit(4) cosmetic_reviews = client[DB_NAME].user_reviews.find( { 'categories.name': 'Make Up' } ).sort('posted', pymongo.DESCENDING).limit(4) bodycare_reviews = client[DB_NAME].user_reviews.find( { 'categories.name': 'Body Care' } ).sort('posted', pymongo.DESCENDING).limit(1) haircare_reviews = client[DB_NAME].user_reviews.find( { 'categories.name': 'Hair Care' } ).sort('posted', pymongo.DESCENDING).limit(1) formen_reviews = client[DB_NAME].user_reviews.find( { 'categories.name': 'For Men' } ).sort('posted', pymongo.DESCENDING).limit(1) user_list = [] for user in users: user_list.append(user) if flask_login.current_user.is_authenticated: current_user = flask_login.current_user if current_user: user = dao.get_user_by_email(client, current_user.id) else: user = None return render_template('read_reviews.template.html', review=latest_review, cat=categories, users=user_list, skincare=skincare_reviews, cosmetics=cosmetic_reviews, bodycare=bodycare_reviews, haircare=haircare_reviews, formen=formen_reviews, user=user)
def user_loader(email): client = data.get_client() # attempt to get the user user_in_db = dao.get_user_by_email(client, email) user = User() user.id = user_in_db['email'] if user: return user else: return None
def delete_review(review_id): client = data.get_client() if flask_login.current_user.is_authenticated: current_user = flask_login.current_user if current_user: user = dao.get_user_by_email(client, current_user.id) else: user = None dao.delete_review_by_id(client, review_id) return redirect(url_for('view_my_reviews', user_id=user['_id']))
def add_user(): client = data.get_client() categories = dao.get_all_categories(client) if flask_login.current_user.is_authenticated: current_user = flask_login.current_user if current_user: user = dao.get_user_by_email(client, current_user.id) else: user = None return render_template('register.template.html', cat=categories, user=user)
def view_review_details(review_id): client = data.get_client() review = dao.get_review_by_review_id(client, review_id) all_users = dao.get_all_users(client) all_cat = dao.get_all_categories(client) if flask_login.current_user.is_authenticated: current_user = flask_login.current_user if current_user: user = dao.get_user_by_email(client, current_user.id) else: user = None return render_template('review_details.template.html', cat=all_cat, review=review, user=user, all_users=all_users)
def read_reviews_by_category(cat_id): client = data.get_client() reviews = dao.get_reviews_by_cat_id(client, cat_id) current_cat = dao.get_category_by_id(client, cat_id) all_cat = dao.get_all_categories(client) all_users = dao.get_all_users(client) if flask_login.current_user.is_authenticated: current_user = flask_login.current_user if current_user: user = dao.get_user_by_email(client, current_user.id) else: user = None return render_template('read_reviews_by_cat.template.html', current_cat=current_cat, cat=all_cat, reviews=reviews, user=user, all_users=all_users)
def view_my_reviews(user_id): client = data.get_client() my_reviews = dao.get_review_by_userid(client, user_id) categories = dao.get_all_categories(client) user = dao.get_one_user(client, user_id) if flask_login.current_user.is_authenticated: current_user = flask_login.current_user if current_user: user = dao.get_user_by_email(client, current_user.id) else: user = None else: return redirect('/user_login?redirect=/read_reviews') return render_template('my_reviews.template.html', reviews=my_reviews, user=user, cat=categories)
def add_review(): client = data.get_client() public_key = os.environ.get('UPLOADCARE_PUBLIC_KEY') categories = dao.get_all_categories(client) cat_list = [] for cat in categories: cat_list.append(cat) if flask_login.current_user.is_authenticated: current_user = flask_login.current_user if current_user: user = dao.get_user_by_email(client, current_user.id) else: user = None else: return redirect('/user_login?redirect=/add_review') return render_template('add_review.template.html',cat=cat_list, ratings=ratings, public_key=public_key, user=user)
def proccess_user_login(): client = data.get_client() user_in_db = dao.get_user_by_email(client, request.form.get('email')) print(user_in_db) if user_in_db: user = User() user.id = user_in_db['email'] redirect_url = request.args.get('redirect') if redirect_url is None: redirect_url = "/" if verify_password(request.form.get('password'), user_in_db['password']): flask_login.login_user(user) return redirect(redirect_url) else: flash('Login Failed. Invalid Email or Password') return render_template('user_login.template.html')