예제 #1
0
	def login(self, data):
		try:
			mongo_config = MongoConfig()
			collection = mongo_config.db()
			if(collection):
				user_obj = User()
				search_user = {'email': data['email']}
				user = collection.find(search_user)
				crypto = Crypto()
				if(user):
					if(crypto.verify_decrypted_string(data['password'], user[0]['password'])):
						user_obj.first_name = user[0]['firstName']
						#user_obj.last_name = user[0]['lastName']
						user_obj.user_id = str(user[0]['_id'])
						user_obj.token = Jwt.encode_auth_token(user_id=user[0]['_id']).decode()
						return user_obj
					else:
						return "Invalid Credentials"
				else:
					return "User not available"
			else:
				return "Unable to connect to database"
		except IndexError as IE:
			return "User not available"
		except Exception as e:
			raise e
예제 #2
0
	def login(data):
		try:
			conn = PgConfig.db()
			if(conn):
				cur = conn.cursor()
				login_query = "SELECT users.otp, users.user_id, users.first_name, users.last_name, users.color_theme, users.image\
				FROM users WHERE users.email LIKE %s"
				cur.execute(login_query, (data['email'], ))
				user = cur.fetchone()
				response = User()
				if(user[0]==data['otp']):
					response.email= data['email']
					response.user_id = user[1]
					response.first_name = user[2]
					response.last_name = user[3]
					response.color_theme = user[4]
					response.image = user[5]
					get_role_query = "SELECT user_role.role_id FROM user_role WHERE user_role.user_id = %s"
					cur.execute(get_role_query, (user[1],))
					response.role_id = cur.fetchone()[0]
					response.token = (Jwt.encode_auth_token(user_id=user[1], role_id=response.role_id)).decode()
					cur.close()
					conn.close()
					return response
				else:
					return False
			else:
				return False
		except Exception as e:
			raise e
예제 #3
0
	def check_fb_user_existence(email):
		conn = None
		cur = None
		try:
			conn = PgConfig.db()
			if(conn):
				cur = conn.cursor()
				select_query = "SELECT user_id, first_name, color_theme, image FROM users WHERE email LIKE %s AND type = %s"
				cur.execute(select_query, (email, 'fb', ));
				obj = cur.fetchone()
				response = User()
				if(obj):
					get_role = "SELECT role_id FROM user_role WHERE user_id = %s"
					cur.execute(get_role, (obj[0],));
					role = cur.fetchone()
					response.email= email
					response.user_id = obj[0]
					response.role_id = role[0]
					response.first_name = obj[1]
					response.color_theme = obj[2]
					response.image = obj[3]
					response.token = (Jwt.encode_auth_token(user_id=obj[0], role_id=response.role_id)).decode()
					cur.close()
					conn.close()
					return response
				else:
					cur.close()
					conn.close()
					return False
			else:
				return False
		except Exception as e:
			return  e
def update_color_theme(theme, student):
    auth_header = request.headers.get('Authorization')
    try:
        status = Jwt.decode_auth_token(auth_header)
        if (status):
            response = Service.update_color_theme(theme, student)
            if (response == True):
                return jsonpickle.encode(response, unpicklable=False), 200
            else:
                return jsonify({"Error": "Something went wrong"}), 500
        else:
            return jsonify({"Error": "Invalid token"}), 500
    except Exception as e:
        return jsonify(e), 500
def get_students_by_course(id):
    auth_header = request.headers.get('Authorization')
    try:
        status = Jwt.decode_auth_token(auth_header)
        if (status):
            response = Service.get_students_by_course(id)
            if (response):
                return jsonpickle.encode(response, unpicklable=False), 200
            else:
                return jsonify({"Error": "Something went wrong"}), 500
        else:
            return jsonify({"Error": "Invalid token"}), 500
    except Exception as e:
        return jsonify(e), 500
def delete_from_cart(course, user, sem):
    auth_header = request.headers.get('Authorization')
    try:
        status = Jwt.decode_auth_token(auth_header)
        if (status):
            response = Service.delete_from_cart(course, user, sem)
            if (response):
                return jsonify({"response": "Success"}), 200
            else:
                return jsonify({"Error": "Something went wrong"}), 500
        else:
            return jsonify({"Error": "Invalid token"}), 500
    except Exception as e:
        return jsonify(e), 500
def get_all_professors(start, end):
    auth_header = request.headers.get('Authorization')
    try:
        status = Jwt.decode_auth_token(auth_header)
        if (status):
            response = Service.get_all("PROFESSORS", start, end)
            if (response):
                return jsonpickle.encode(response, unpicklable=False), 200
            else:
                return jsonify({"Error": "Something went wrong"}), 500
        else:
            return jsonify({"Error": "Invalid token"}), 500
    except Exception as e:
        return jsonify(e), 500
def enroll_courses():
    auth_header = request.headers.get('Authorization')
    data = request.json
    try:
        status = Jwt.decode_auth_token(auth_header)
        if (status):
            response = Service.enroll_courses(data)
            if (response):
                return jsonpickle.encode(response, unpicklable=False), 200
            else:
                return jsonify({'Error': "Course timings clash"}), 500
        else:
            return jsonify({"Error": "Invalid token"}), 500
    except Exception as e:
        return jsonify(e), 500
def drop_course(course_id, user_id, sem):
    auth_header = request.headers.get('Authorization')
    data = request.json
    try:
        status = Jwt.decode_auth_token(auth_header)
        if (status):
            response = Service.delete_enrolled_course(user_id, course_id, sem)
            if (response):
                return jsonify({'Success': "Dropped the course"}), 200
            else:
                return jsonify({'Error': "Something went wrong"}), 500
        else:
            return jsonify({"Error": "Invalid token"}), 500
    except Exception as e:
        return jsonify(e), 500
def update_financial_aid(value, student):
    auth_header = request.headers.get('Authorization')
    try:
        status = Jwt.decode_auth_token(auth_header)
        if (status):
            if (status['role'] == str(1)):
                response = Service.update_financial_aid(value, student)
                if (response == True):
                    return jsonpickle.encode(response, unpicklable=False), 200
                else:
                    return jsonify({"Error": "Something went wrong"}), 500
            else:
                return jsonify({"Error": "Unauthorised"}), 500
        else:
            return jsonify({"Error": "Invalid token"}), 500
    except Exception as e:
        return jsonify(e), 500
def get_all_students(start, end):
    auth_header = request.headers.get('Authorization')
    try:
        status = Jwt.decode_auth_token(auth_header)
        if (status):
            if (status['role'] == str(1)):
                response = Service.get_all("STUDENTS", start, end)
                if (response):
                    return jsonpickle.encode(response, unpicklable=False), 200
                else:
                    return jsonify({"Error": "Something went wrong"}), 500
            else:
                return jsonify({"Error": "Unauthorised"}), 500
        else:
            return jsonify({"Error": "Invalid token"}), 500
    except Exception as e:
        return jsonify(e), 500
예제 #12
0
	def auth_token(token):
		return Jwt.decode_auth_token(token)