예제 #1
0
    def signup_user():

        # get body of request; if nothing included, abort with 400
        body = request.get_json()
        if not body:
            abort(400)

        # set attributes for new User based on body input
        username = body.get('username', None)
        usertype = body.get('usertype', None)
        email = body.get('email', None)
        password = body.get('password', None)

        # proceed only if both required fields are provided
        if username and usertype:

            # First, check to see if username is already being used in local bd, and abort with 409 (conflict) if so
            if Mentor.exists(username) or Coder.exists(username):
                abort(409)

        # Then, try to add new user to auth0 database:
            url = f'https://{AUTH0_DOMAIN}/dbconnections/signup'

            post_object = {
                "client_id": AUTH0_CLIENT_ID,
                "email": email,
                "password": password,
                "connection": AUTH0_CONNECTION,
                "username": username,
                "user_metadata": {
                    "role": usertype.title()
                }
            }

            auth0_response = requests.post(url, json=post_object)

            # If there was a problem with auth0 process, abort:
            if hasattr(auth0_response, 'error'):
                abort(401)

            # Finally, if auth0 signup orcess successful,
            # insert user into local database:

            # instantiate a new object for the new user
            if usertype == 'mentor':
                user = Mentor(username=username)
            if usertype == 'coder':
                user = Coder(username=username)

            # try to add the new user to the applicable table in the database
            try:
                user.insert()
            except:
                abort(500)

        # if required fields weren't provided in the request, abort with 400
        else:
            abort(400)

        return jsonify({"success": "True", "user_id": user.id})
def load_mentors(raw_mentors_json):
    loaded_mentors: [Mentor] = []
    loaded_team_mentors: [TeamMentors] = []
    for mentor in raw_mentors_json:
        mntr = Mentor(name=mentor["name"])
        loaded_mentors.append(mntr)
        for mentored_team in mentor['teams']:
            tm_name = mentored_team['name']
            loaded_team_mentors.append(
                TeamMentors(team_name=tm_name, mentor_name=mntr.name))

    return loaded_mentors, loaded_team_mentors
예제 #3
0
def updateUsers(env):
    db = configure(env)

    from models import base
    from models import User, Mentor, Appointment, Project

    Session = sessionmaker(db)
    session = Session()

    #   Updating data relevant for Sensei application proper functionality like:
    #   1.  User projects completed / resubmmitted
    #   2.  User inactivity
    try:
        users = session.query(User)
        print("starting...")
        for user in users:
            if (datetime.datetime.utcnow() -
                    user.last_seen) > automaticDeactivationTime:
                user.active = False
            if user.active == True:
                id42user = getattr(user, 'id_user42')
                userProjects = Api42.userProjects(id42user)
                if not userProjects:
                    continue
                for p in userProjects:
                    project = session.query(Project).filter(
                        Project.id_project42 == p['id_project42']).first()
                    if project:
                        mentor = session.query(Mentor).filter(
                            Mentor.id_user42 == id42user,
                            Mentor.id_project42 == p['id_project42']).first()
                        if not mentor:
                            mentor = Mentor(id_project42=p['id_project42'],
                                            id_user42=id42user,
                                            finalmark=p['finalmark'])
                            session.add(mentor)
                        print(type(projectMinScore))
                        if mentor.finalmark >= int(projectMinScore):
                            mentor.abletomentor = True
        session.commit()
    except Exception as inst:
        print(inst.args)
        session.rollback()
    finally:
        session.close()
예제 #4
0
def apply_for_mentorship():
    if request.method == "POST":
        user_info = github.get("/user", access_token=g.user.github_access_token)
        print("Userinfo", user_info["login"])
        m = Mentor.get_or_none(username=user_info["login"])
        if m:
            flash(f"You have already applied for mentorship."
                  f" Your Status is {m.status}"
                  f"{f' and Reason is {m.status_reason}.' if m.status == 'rejected' else '.'}")
        else:
            print("M is ", m)
            m = Mentor(username=user_info["login"], status="pending",
                       profile_link=user_info["html_url"], status_reason="")
            m.save()
            flash("Submitted Successfully. It takes approximately 1 week to process"
                  " application. If you want to check your application status later"
                  " then click the same apply_mentor button")
    return render_template("apply_mentor.html", nav=nav)