def sign_in(): email = request.form['email'] password = request.form['password'] check_user = db_select_queries.check_user_by_email(email) if not check_user: return jsonify(error=True, message='invalid credentials') pw_check = check_password(password, check_user['password']) if not pw_check: return jsonify(error=True, message='invalid credentials') user = db_select_queries.get_user_by_username(check_user['username']) user_session['session_id'] = uniqueValue() user_session['you_id'] = user["id"] user_session['you_username'] = user['username'] user_session['you'] = user return jsonify( message='Signed In Successfully!', success=True, user_id=user_session['you_id'], username=user_session['you_username'], )
def get_user_by_value(user_value): is_int = isinstance(user_value, int) is_str = isinstance(user_value, str) if is_int: return db_select_queries.get_user_by_id(user_value) if is_str: return db_select_queries.get_user_by_username(user_value) return None
def get_user_by_username_or_id(value): val = str(value).encode('utf-8') try: user = db_select_queries.get_user_by_id(int(val)) except Exception as err1: print('error: ', err1) try: user = db_select_queries.get_user_by_username(val) except Exception as err2: print('error: ', err2) pass return jsonify(user=user)
def sign_up(): form_dict = { "displayname": str(request.form['displayname']).encode('utf-8'), "username": str(request.form['username']).encode('utf-8'), "email": str(request.form['email']).encode('utf-8'), "password": str(request.form['password']).encode('utf-8'), } password = str(form_dict['password']).encode('utf-8') password_confirm = str(request.form['password_confirm']).encode('utf-8') passwords_do_not_match = password != password_confirm if passwords_do_not_match: return jsonify(error=True, message='passwords do not match') check_username = db_select_queries.check_user_by_username( form_dict['username']) if check_username: return jsonify(error=True, message='username already in use') check_email = db_select_queries.check_user_by_email(form_dict['email']) if check_email: return jsonify(error=True, message='email already in use') new_user_id = db_insert_queries.create_new_user(form_dict) new_user = db_select_queries.get_user_by_username(form_dict['username']) user_session['session_id'] = uniqueValue() user_session['you_id'] = new_user_id user_session['you_username'] = form_dict['username'] user_session['you'] = new_user return jsonify( message='Signed Up Successfully!', success=True, new_user_id=user_session['you_id'], new_username=user_session['you_username'], )
def get_user_by_username(username): user = db_select_queries.get_user_by_username(username) return jsonify(user=user)