Ejemplo n.º 1
0
def register_team(request):
    """Register a new team.

    Checks that an email address, team name, adviser name, affiliation, and password were sent from the browser.
    If any of these are missing a status:0 is returned with a message saying that all fields must be provided.
    Verifies that no teams exist with the specified name, if one exists a status:0 with a message is returned.
    If the 'joingroup' flag is empty or false and the passed 'group' is not empty we check to see if a group with that
    name exists in the database, if it does we return a status:2 and a message saying the the group exists, and give
    the user the option to join it.
    If no failure at this point the function hashes the password and inserts the data into a new db document
    in the teams collection.
    If the passed 'group' was empty we now return a status:1 with a successful registration message. If the 'joingroup'
    flag was set/true (and 'group' exists) we search for the group, if it does NOT exist we create it and add the new
    team as an owner and member.  If it does exist we add the team as a member of the group.
    If 'joingroup' is not set/false but 'group' exists then we create the new group and add the user as an owner/member,
    we already know that the group does not exist (would have been caught at the beginning).
    """
    email = request.form.get('email', '')
    teamname = request.form.get('teamname', '')
    adviser = request.form.get('name', '')
    affiliation = request.form.get('aff', '')
    pwd = request.form.get('password', '')
    gname = request.form.get('group', '').lower().strip('')
    joingroup = 'true' #request.form.get('joingroup', '')
    print {email, teamname, pwd}
    if '' in {email, teamname, pwd}:
        return {'success': 0, 'message': "Please fill in all of the required fields."}
    if db.teams.find({'teamname': teamname}).count() != 0:
        return {'success': 0, 'message': "That team name is already registered."}
    # if joingroup != 'true' and gname != '':
        # if db.groups.find({'name': gname}).count() != 0:
            # return {'success': 2, 'message': "The group name you have entered exists, would you like to join it?"}

    tid = common.token()
    db.teams.insert({'email': str(email),
                     'advisor': str(adviser),
                     'teamname': str(teamname),
                     'affiliation': str(affiliation),
                     'pwhash': bcrypt.hashpw(str(pwd), bcrypt.gensalt(8)),
                     'tid': tid})
    if gname == '':
        return {'success': 1, 'message': "Success! You have successfully registered."}

    if joingroup == 'true':
        if db.groups.find({'name': gname}).count() == 0:
            group.create_group(tid, gname)
        else:
            db.groups.update({'name': gname}, {'$push': {'members': tid}})
            return {'success': 1, 'message': 'Success! You have been added to the group!'}
    else:
        group.create_group(tid, gname)
        return {'success': 1, 'message': "Success! You are registered and have created your group."}
Ejemplo n.º 2
0
def register_team(request):
    """Register a new team.

    Checks that an email address, team name, adviser name, affiliation, and password were sent from the browser.
    If any of these are missing a status:0 is returned with a message saying that all fields must be provided.
    Verifies that no teams exist with the specified name, if one exists a status:0 with a message is returned.
    If the 'joingroup' flag is empty or false and the passed 'group' is not empty we check to see if a group with that
    name exists in the database, if it does we return a status:2 and a message saying the the group exists, and give
    the user the option to join it.
    If no failure at this point the function hashes the password and inserts the data into a new db document
    in the teams collection.
    If the passed 'group' was empty we now return a status:1 with a successful registration message. If the 'joingroup'
    flag was set/true (and 'group' exists) we search for the group, if it does NOT exist we create it and add the new
    team as an owner and member.  If it does exist we add the team as a member of the group.
    If 'joingroup' is not set/false but 'group' exists then we create the new group and add the user as an owner/member,
    we already know that the group does not exist (would have been caught at the beginning).
    """
    email = request.form.get('email', '')
    teamname = request.form.get('team', '')
    adviser = request.form.get('name', '')
    affiliation = request.form.get('aff', '')
    pwd = request.form.get('pass', '')
    gname = request.form.get('group', '').lower().strip('')
    joingroup = request.form.get('joingroup', '')

    if '' in {email, teamname, adviser, affiliation, pwd}:
        return {'status': 0, 'message': "Please fill in all of the required fields."}
    if db.teams.find({'teamname': teamname}).count() != 0:
        return {'status': 0, 'message': "That team name is already registered."}
    if joingroup != 'true' and gname != '':
        if db.groups.find({'name': gname}).count() != 0:
            return {'status': 2, 'message': "The group name you have entered exists, would you like to join it?"}

    tid = common.token()
    db.teams.insert({'email': str(email),
                     'advisor': str(adviser),
                     'teamname': str(teamname),
                     'affiliation': str(affiliation),
                     'pwhash': bcrypt.hashpw(str(pwd), bcrypt.gensalt(8)),
                     'tid': tid})
    if gname == '':
        return {'status': 1, 'message': "Success! You have successfully registered."}

    if joingroup == 'true':
        if db.groups.find({'name': gname}).count() == 0:
            group.create_group(tid, gname)
        else:
            db.groups.update({'name': gname}, {'$push': {'members': tid}})
            return {'status': 1, 'message': 'Success! You have been added to the group!'}
    else:
        group.create_group(tid, gname)
        return {'status': 1, 'message': "Success! You are registered and have created your group."}
Ejemplo n.º 3
0
def new_group_handler(request):
    group_name = request & get_arg('group_name')
    invite_key = request & get_arg('group_invite_key')
    new_group = (create_group(group_name, invite_key) &
                 (lambda x: GroupManager().add_new_group(x)))
    result = new_group.attempt() & aduit_flow
    return result
Ejemplo n.º 4
0
def create_group_hook():
    return group.create_group(session['tid'], request.form.get('name', ''))
Ejemplo n.º 5
0
def process_group_password(message):
    group.set_temp(message.from_user.id, 'password', message.text)
    group.create_group(message.from_user.id)
    bot.send_message(message.from_user.id, 'Выберите пункт меню:', reply_markup=keyboard.get_main_keyboard())
Ejemplo n.º 6
0
def create_group_hook():
    return group.create_group(session['tid'], request.form.get('name', ''))