示例#1
0
def login():
    form = LoginForm2(next=request.args.get('next'))

    if form.validate_on_submit():
        u = User2.find_by_identity(request.form.get('identity'))

        if u and u.authenticated(password=request.form.get('password')):
            # As you can see remember me is always enabled, this was a design
            # decision I made because more often than not users want this
            # enabled. This allows for a less complicated login form.
            #
            # If however you want them to be able to select whether or not they
            # should remain logged in then perform the following 3 steps:
            # 1) Replace 'True' below with: request.form.get('remember', False)
            # 2) Uncomment the 'remember' field in user/forms.py#LoginForm
            # 3) Add a checkbox to the login form with the id/name 'remember'
            if login_user(u, remember=True) and u.is_active():
                u.update_activity_tracking(request.remote_addr)

                # Handle optionally redirecting to the next URL safely.
                next_url = request.form.get('next')
                if next_url:
                    return redirect(safe_next_url(next_url))

                return redirect(url_for('user2.settings'))
            else:
                flash('This account has been disabled.', 'error')
        else:
            flash('Identity or password is incorrect.', 'error')

    return render_template('user2/login.html', form=form)
示例#2
0
def recommendprj(email, disinterested):
    recommender = []

    user = User2.find_by_identity(email)

    user_skill = user.skills.split(',')

    projects = Projects.query \
        .order_by(Projects.created_on.desc())

    for project in projects:
        if project.resource_email == '':
            project_skills = project.skills.split(',')
            matching_skills = set(project_skills) & set(user_skill)
            if len(matching_skills) >= 0.6 * len(project_skills):
                project_employees = project.interesting_participants.split(',')
                if user.email in project_employees:
                    recommender.append([
                        project.projectid, user.email, 'X', disinterested,
                        project.description, project.email
                    ])
                else:
                    recommender.append([
                        project.projectid, user.email, '', disinterested,
                        project.description, project.email
                    ])
        if user.current_project != '':
            if user.current_project == project.projectid:
                recommender.append([
                    project.projectid, user.email, 'C', disinterested,
                    project.description, project.email
                ])

    return render_template('user2/projectrecommend.html', bets=recommender)
示例#3
0
def signup():

    #  form = SignupForm2(email = current_user.email)

    u = User2.find_by_identity(current_user.email)

    if u is None:
        u = User2()
        form = SignupForm2(email=current_user.email)
    else:
        form = SignupForm2(email=current_user.email,
                           skills=u.skills,
                           train=u.train,
                           department=u.department,
                           protype=u.protype)

#    form = SignupForm2(obj=current_user)

    if form.validate_on_submit():
        #        u = User2()

        form.populate_obj(u)
        u.save()

        redurl = '/recommendprj/' + u.email
        return redirect(redurl)

#       if login_user(u):
#           flash('Awesome, thanks for signing up!', 'success')
#           return redirect(url_for('user2.welcome'))

    return render_template('user2/signup.html', form=form)
示例#4
0
def recommendme(projectid, disinterested):
    recommender = []
    match = ''
    matching_skills = defaultdict(list)
    #    matching_skills = []
    stemmer = SS('english')

    project = Projects.find_by_identity(projectid)

    employees = User2.query \
        .order_by(User2.created_on.desc())

    if project.resource_email == '':
        project_skills = project.skills.split(',')
        for employee in employees:
            matching_skills = []
            employee_skills = employee.skills.split(',')
            for project_skill in project_skills:
                s1 = stemmer.stem(project_skill)
                for employee_skill in employee_skills:
                    s2 = stemmer.stem(employee_skill)
                    if s1 == s2:
                        matching_skills.append(employee_skill)


#            matching_skills = set(project_skills) & set(employee_skills)
            if len(matching_skills) >= 0.6 * len(project_skills):
                employee_projects = employee.interesting_projects.split(',')
                for matching_skill in matching_skills:
                    match = matching_skill + ',' + match
                if project.projectid in employee_projects:
                    recommender.append([
                        project.projectid, employee.email, 'X', disinterested,
                        employee.fullname, match, employee.department,
                        employee.protype
                    ])
                else:
                    recommender.append([
                        project.projectid, employee.email, '', disinterested,
                        employee.fullname, match, employee.department,
                        employee.protype
                    ])
    if project.project_status == 'Started':
        employee = User2.find_by_identity(project.resource_email)
        project_skills = project.skills.split(',')
        employee_skills = employee.skills.split(',')
        matching_skills = set(project_skills) & set(employee_skills)
        for matching_skill in matching_skills:
            match = matching_skill + ',' + match
        recommender.append([
            project.projectid, employee.email, '', 'E', employee.fullname,
            match, employee.department, employee.protype
        ])

    return render_template('contact2/userrecommend.html', bets=recommender)
示例#5
0
def ensure_identity_exists(form, field):
    """
    Ensure an identity exists.

    :param form: wtforms Instance
    :param field: Field being passed in
    :return: None
    """
    user = User2.find_by_identity(field.data)

    if not user:
        raise ValidationError('Unable to locate account.')
示例#6
0
def seed2():
    """
    Seed the database with an initial user.

    :return: User instance
    """
    if User2.find_by_identity(app.config['SEED_ADMIN_EMAIL']) is not None:
        return None

    params = {
        'role': 'admin',
        'email': app.config['SEED_ADMIN_EMAIL'],
        'password': app.config['SEED_ADMIN_PASSWORD']
    }

    return User2(**params).save()
示例#7
0
def recommendme(email):
    recommender = []

    user = User2.find_by_identity(email)

    user_skill = user.skills.split(',')

    projects = Projects.query \
        .order_by(Projects.created_on.desc())

    for project in projects:
        if project.resource_email == '':
            project_skills = project.skills.split(',')
            matching_skills = set(project_skills) & set(user_skill)
            if len(matching_skills) >= 0.6 * len(project_skills):
                recommender.append([project.projectid, user.email])

    return render_template('contact2/userrecommend.html', bets=recommender)
示例#8
0
def assign_project(projectid, email, action):

    u1 = Projects.find_by_identity(projectid)

    u2 = User2.find_by_identity(email)

    if action == 'I':

        u2.interesting_projects = projectid + ',' + u2.interesting_projects

        redurl = '/recommendprj/' + email + '/X'

        u2.save()

        return redirect(redurl)

    elif action == 'A':

        #        u1.whizcoin = 0

        u1.resource_email = email

#        u2.whizcoin = u2.whizcoin + 100

    elif action == 'R':

        u2_projects = u2.interesting_projects.split(',')

        u2_projects.remove(projectid)

        u2.interesting_projects = ''.join(u2_projects)

        u1_participants = u1.interesting_participants.split(',')

        u1_participants.remove(email)

        u1.interesting_participants = ''.join(u1_participants)

    elif action == 'S':

        u1.project_status = 'Started'

        u2.current_project = ''

    u1.save()

    u2.save()

    #    flash('Awesome, thanks for signing up!', 'success')

    #    u1 = Projects.find_by_identity(projectid)

    #    u1.interesting_participants = email + ',' + u1.interesting_participants

    #    u1.whizcoin = 0

    #    u2 = User2.find_by_identity(email)
    #    u2.interesting_projects = projectid + ',' + u2.interesting_projects
    #    u2.whizcoin = u2.whizcoin - 100

    #    u2.save()

    #    u1.save()

    #    recommender = []
    #    recommender.append([projectid, email])

    return render_template('contact2/thankyou.html')