예제 #1
0
파일: routes.py 프로젝트: yinnyC/Lunch-Chat
def login():
    """ Return login template."""
    if request.method == "GET":
        if session['user'] and getUserID():
            role = session['role']
            if role == 'Students':
                return redirect(url_for("student.show_recruiters"))
            elif role == 'Recruiters':
                return redirect(url_for("recruiter.show_students"))
            else:
                return render_template('Auth/login.html')
        else:
            return render_template('Auth/login.html')
    elif request.method == "POST":
        try:
            email = request.form.get("email")
            password = request.form.get("password")
            loginUser(email, password)
            role = getUserRole()  # Redirect user to create user profile
            flash("sign In Successfully")
            if role == 'Students':
                return redirect(url_for("student.show_recruiters"))
            else:
                return redirect(url_for("recruiter.show_students"))
        except:
            error = "Some thing happend!! could not sign in"
            return render_template('Auth/login.html', error=error)
예제 #2
0
def student_main():
    """
    Return template for student profile.
    """
    if session['user']:
        user = getUserID()  # To access to the currenr user's uid
        data = getStudentProfile(user)
        return render_template('Students/profile_info.html', **data)
    else:
        print("please login first")
        return redirect(url_for("main.homepage"))
예제 #3
0
def update_student_profile():
    """ The function can update data for the student profile """
    if session['user']:
        if request.method == "GET":
            user = getUserID()  # To access to the currenr user's uid
            data = getStudentProfile(user)
            return render_template('Students/update_profile.html', **data)
        elif request.method == "POST":
            data = {
                "name": request.form.get("name"),
                "school": request.form.get("school"),
                "degree": request.form.get("degree"),
                "graduationDate": request.form.get("graduationDate"),
                "bio": request.form.get("bio")
            }
            user = getUserID()
            firebase.database().child("student_profile").child(user).update(
                data)
            print('data updated!')
            return redirect(url_for("student.student_main"))
    else:
        print("You have to be logged in first!")
        return redirect(url_for("main.homepage"))
예제 #4
0
def update_recruiter_profile():
    """ The function can update data for the recruiter profile """
    if session['user']:
        if request.method == "GET":
            user = getUserID()  # To access to the currenr user's uid
            data = getRecruiterProfile(user)
            return render_template('Recruiters/update_profile.html', **data)
        elif request.method == "POST":
            data = {
                "name": request.form.get("name"),
                "bio": request.form.get("bio"),
                "company": request.form.get("company"),
                "title": request.form.get("title"),
                "talent": request.form.get("talent"),
            }
            user = getUserID()
            firebase.database().child("recruiter_profile").child(user).update(
                data)
            print('data updated!')
            return redirect(url_for("recruiter.recruiter_main"))
    else:
        print("You have to be logged in first!")
        return redirect(url_for("main.homepage"))
예제 #5
0
def create_recruiter_profile():
    if session['user']:  # Check if user has logged in yet
        if request.method == "GET":
            return render_template('Recruiters/create_profile.html')
        elif request.method == "POST":
            data = {
                "name": request.form.get("name"),
                "bio": request.form.get("bio"),
                "company": request.form.get("company"),
                "title": request.form.get("title"),
                "talent": ",".join(request.form.getlist('talent')),
            }
            user = getUserID()
            firebase.database().child("recruiter_profile").child(user).update(
                data)
            print('data inserted')
            return redirect(url_for("recruiter.recruiter_main"))

    else:
        print("You need to log in first")
        return redirect(url_for("main.homepage"))
예제 #6
0
def create_student_profile():
    """
    Return template for create_student_profile and Store data to firebase
    """
    if session['user']:  # Check if user has logged in yet
        if request.method == "GET":
            return render_template('Students/create_profile.html')
        elif request.method == "POST":
            data = {
                "name": request.form.get("name"),
                "bio": request.form.get("bio"),
                "school": request.form.get("school"),
                "degree": request.form.get("degree"),
                "graduationDate": request.form.get("graduationDate")
            }
            user = getUserID()
            firebase.database().child("student_profile").child(user).update(
                data)
            print('data inserted')
            return redirect(url_for("student.student_main"))

    else:
        print("You need to log in first")
        return redirect(url_for("main.homepage"))
예제 #7
0
파일: routes.py 프로젝트: yinnyC/Lunch-Chat
def signup():
    """ 
    Get method: Return signup template 
    and pass the role user choosed to template
    POST method:Create an account, store user role to db 
    and redirect to create profile page
    """
    if request.method == "GET":
        role = session['role']
        if role == None:
            return render_template("Auth/re_direct_role.html")
        else:
            return render_template("Auth/signup.html", role=role)
    elif request.method == "POST":
        try:
            email = request.form.get("email")
            password = request.form.get("password")
            # Create User Account
            signup_user = auth.create_user_with_email_and_password(
                email, password)
            loginUser(email, password)  # Login user to create session
            userID = getUserID()  # Save User's role with UserID to db
            firebase.database().child('Role').child(userID).update(
                {"role": request.form.get("role")})
            print("account created!")
            role = getUserRole()  # Redirect user to create profile
            if role == 'Students':
                return redirect(url_for("student.create_student_profile"))
            elif role == 'Recruiters':
                return redirect(url_for("recruiter.create_recruiter_profile"))
            else:
                return render_template('Auth/login.html')
        except:
            role = session['role']
            error = "Could not sign up"
            return render_template("Auth/signup.html", role=role, error=error)