Ejemplo n.º 1
0
    def on_get(self, req, resp, ugid, usid):
        found_session = GuildHasSession(ugid, usid, self.guilds)

        if found_session:
            session = self.session.GetSession(usid)
            if session is not None:
                resp.data = str.encode(
                    json.dumps({
                        'usid': session.get('_id'),
                        'game': session.get('game'),
                        'start': session.get('start'),
                        'notes': session.get('notes')
                    }))
                resp.status = falcon.HTTP_200
            else:
                #TODO Log this shit
                resp.data = str.encode(
                    json.dumps({
                        'error':
                        'Session belongs to guild, but could not be found in database of sessions.'
                    }))
                resp.status = falcon.HTTP_744
        else:
            resp.json = str.encode(
                json.dumps({
                    'error':
                    'Session identifier does not belong to guild referenced.'
                }))
            resp.status = falcon.HTTP_409
Ejemplo n.º 2
0
def settings():
    if request.method == 'GET':
        # GET USER INFO FOR SETTINGS
        user = controls.get_user_info(session.get('username'))
        if not user:
            return redirect(url_for('logout'))
        authorized_users = controls.get_authorized_users()
        lead = controls.get_lead(session.get('username'))
        if len(lead) == 0:
            lead={'first_name':'', 'last_name':'', 'username':''}
        else:
            lead=lead[0]
        return render_template('settings.html', authorized_users = authorized_users, lead=lead['username'], user=user)   
    elif request.method== 'POST':
        # UPDATE USER INFO WITH: ALL VALUES FROM THE FORM
        lead_id = request.form['lead'] if request.form['lead'] != 'None' else None
        payload ={'first_name':request.form['first_name'],
                  'last_name':request.form['last_name'],
                  'lead_id':lead_id}
        if request.form['password'] != '':
            payload['password']=request.form['password']
        if 'auth' in request.form:
            payload['authorized']=0
            payload['auth_token']=None
            session.pop('shard_id')
            session.pop('auth_token')
            session['authorized'] = 0
        payload['use_email'] = request.form['use_email']
        #payload['use_email'] = 1 if 'use_email' in request.form else 0
        controls.update_user(session.get('username'), **payload)
        flash('Settings Updated Successfully')
        session['first_name'] = request.form['first_name']
        session['last_name'] = request.form['last_name']
        return redirect(url_for('settings', lead=lead_id))
Ejemplo n.º 3
0
def login():
    error = None
    if request.method == 'POST':
        user = controls.get_user_info(request.form['username'])
        if len(user) <= 0:
            error = 'Invalid username'
        elif request.form['password'] != user['password']:
            error = 'Invalid password'
        else:
            session['logged_in'] = True
            session['username'] = request.form['username']
            session['first_name'] = user['first_name']
            session['last_name'] = user['last_name']
            # CHECK IF THIS HAS BEEN SET YET
            if user['shard_id'] is not None and len(user['shard_id']) > 0:
                session['shard_id'] = user['shard_id']
            if user['auth_token'] is not None and len(user['auth_token']) > 0:
                session['auth_token'] = user['auth_token']
            if user['is_admin'] is not None and user['is_admin'] > 0:
                session['admin'] = True
            flash('Successfully Logged In')
            return redirect(url_for('index'))
    else:
        if session.get('logged_in'):
            return redirect(url_for('index'))
    return render_template('login.html', error=error)
Ejemplo n.º 4
0
def login():
    error = None
    if request.method == 'POST':
        user = controls.get_user_info(request.form['username'])
        if len(user) <= 0:
            error = 'Invalid username'
        elif request.form['password'] != user['password']:
            error = 'Invalid password' 
        else:
            session['logged_in'] = True
            session['username'] = request.form['username']
            session['first_name'] = user['first_name']
            session['last_name'] = user['last_name']
            # CHECK IF THIS HAS BEEN SET YET
            if user['shard_id'] is not None and len(user['shard_id']) > 0: 
                session['shard_id'] = user['shard_id']
            if user['auth_token'] is not None and len(user['auth_token']) > 0:
                session['auth_token'] = user['auth_token']
            if user['is_admin'] is not None and user['is_admin'] > 0:
                session['admin'] = True
            flash('Successfully Logged In')
            return redirect(url_for('index'))
    else:
        if session.get('logged_in'):
            return redirect(url_for('index'))
    return render_template('login.html', error=error)
Ejemplo n.º 5
0
def GuildHasSession(ugid,
                    usid,
                    guild_col_ref,
                    just_future=False,
                    just_perivious=False):
    result = guild_col_ref.find_one(
        {'_id': ObjectId(ugid)},
        projection=['future_sessions', 'previous_sessions'])

    if result:
        if not just_perivious:
            for session in result.get('future_sessions'):
                if usid == session.get('usid'):
                    return True
        if not just_future:
            for session in result.get('previous_sessions'):
                if usid == session.get('usid'):
                    return True
    return False
Ejemplo n.º 6
0
def settings():
    if request.method == 'GET':
        # GET USER INFO FOR SETTINGS
        user = controls.get_user_info(session.get('username'))
        if not user:
            return redirect(url_for('logout'))
        authorized_users = controls.get_authorized_users()
        lead = controls.get_lead(session.get('username'))
        if len(lead) == 0:
            lead = {'first_name': '', 'last_name': '', 'username': ''}
        else:
            lead = lead[0]
        return render_template('settings.html',
                               authorized_users=authorized_users,
                               lead=lead['username'],
                               user=user)
    elif request.method == 'POST':
        # UPDATE USER INFO WITH: ALL VALUES FROM THE FORM
        lead_id = request.form[
            'lead'] if request.form['lead'] != 'None' else None
        payload = {
            'first_name': request.form['first_name'],
            'last_name': request.form['last_name'],
            'lead_id': lead_id
        }
        if request.form['password'] != '':
            payload['password'] = request.form['password']
        if 'auth' in request.form:
            payload['authorized'] = 0
            payload['auth_token'] = None
            session.pop('shard_id')
            session.pop('auth_token')
            session['authorized'] = 0
        payload['use_email'] = request.form['use_email']
        #payload['use_email'] = 1 if 'use_email' in request.form else 0
        controls.update_user(session.get('username'), **payload)
        flash('Settings Updated Successfully')
        session['first_name'] = request.form['first_name']
        session['last_name'] = request.form['last_name']
        return redirect(url_for('settings', lead=lead_id))
Ejemplo n.º 7
0
def configure(guid_list=None):
    if request.method=='POST':
        guid_list = request.form.getlist('notebook')
        controls.update_user(session.get('username'), notebook_ids=','.join(guid_list))
        return redirect(url_for('configure'))
    else:    
        # CHECK IF THIS NEEDS SHARD/AUTH
        notebook_list=get_notebook_list(session.get('auth_token'), session.get('shard_id'))
        if guid_list is None:
            # CHECK AND SEE IF USER HAS SELECTED NOTEBOOKS
            guid_list = controls.get_notebook_ids(session.get('username'))
            if len(guid_list) == 1:
                guid_list = guid_list[0]['ids'].split(',')
            else:
                guid_list = None
        if guid_list is not None:
            for notebook in notebook_list:
                for guid in guid_list:
                    if guid == notebook['guid']:
                        notebook['selected'] = True
                        break    
    return render_template('configure.html', notebooks=notebook_list)
Ejemplo n.º 8
0
def auth_finish():
    """After the user has authorized this application on Evernote's website,
    they will be redirected back to this URL to finish the process."""

    oauth_verifier = request.args.get('oauth_verifier', '')

    token = oauth.Token(session['oauth_token'], 
                        session['oauth_token_secret'])
    token.set_verifier(oauth_verifier)

#    client = get_oauth_client()
    client = get_oauth_client(token)

    # Retrieve the token credentials (Access Token) from Evernote
    resp, content = client.request(app.config['EN_ACCESS_TOKEN_URL'], 'POST')

    if resp['status'] != '200':
        raise Exception('Invalid response %s.' % resp['status'])

    access_token = dict(urlparse.parse_qsl(content))
    authToken = access_token['oauth_token']
    
    # MAY NEED SHARD/AUTH
    userStore = get_userstore()
    user = userStore.getUser(authToken)

    # Save the users information to so we can make requests later
    session['shard_id'] = user.shardId
    session['auth_token'] = authToken
    
    # INSERT THE SESSION AND LINK TO THE USERID
    controls.update_user(session.get('username'),
                         auth_token=session.get('auth_token'), 
                         shard_id=session.get('shard_id'),
                         authorized=1)
    flash("Evernote Test Session Authorized!!")
    return redirect(url_for('index'))
Ejemplo n.º 9
0
def auth_finish():
    """After the user has authorized this application on Evernote's website,
    they will be redirected back to this URL to finish the process."""

    oauth_verifier = request.args.get('oauth_verifier', '')

    token = oauth.Token(session['oauth_token'], session['oauth_token_secret'])
    token.set_verifier(oauth_verifier)

    #    client = get_oauth_client()
    client = get_oauth_client(token)

    # Retrieve the token credentials (Access Token) from Evernote
    resp, content = client.request(app.config['EN_ACCESS_TOKEN_URL'], 'POST')

    if resp['status'] != '200':
        raise Exception('Invalid response %s.' % resp['status'])

    access_token = dict(urlparse.parse_qsl(content))
    authToken = access_token['oauth_token']

    # MAY NEED SHARD/AUTH
    userStore = get_userstore()
    user = userStore.getUser(authToken)

    # Save the users information to so we can make requests later
    session['shard_id'] = user.shardId
    session['auth_token'] = authToken

    # INSERT THE SESSION AND LINK TO THE USERID
    controls.update_user(session.get('username'),
                         auth_token=session.get('auth_token'),
                         shard_id=session.get('shard_id'),
                         authorized=1)
    flash("Evernote Test Session Authorized!!")
    return redirect(url_for('index'))
Ejemplo n.º 10
0
def configure(guid_list=None):
    if request.method == 'POST':
        guid_list = request.form.getlist('notebook')
        controls.update_user(session.get('username'),
                             notebook_ids=','.join(guid_list))
        return redirect(url_for('configure'))
    else:
        # CHECK IF THIS NEEDS SHARD/AUTH
        notebook_list = get_notebook_list(session.get('auth_token'),
                                          session.get('shard_id'))
        if guid_list is None:
            # CHECK AND SEE IF USER HAS SELECTED NOTEBOOKS
            guid_list = controls.get_notebook_ids(session.get('username'))
            if len(guid_list) == 1:
                guid_list = guid_list[0]['ids'].split(',')
            else:
                guid_list = None
        if guid_list is not None:
            for notebook in notebook_list:
                for guid in guid_list:
                    if guid == notebook['guid']:
                        notebook['selected'] = True
                        break
    return render_template('configure.html', notebooks=notebook_list)
Ejemplo n.º 11
0
def index():
    error_list = None
    # CHECK IF THE USER IS LOGGED IN, OTHERWISE REDIRECT
    if not session.get('logged_in'):
        return redirect(url_for('login'))
    # GET THE USER INFO, REDIRECT IF NOTHING IS RETURNED
    user = controls.get_user_info(session.get('username'))
    if not user:
        redirect(url_for('logout'))
    authorized_users = controls.get_authorized_users()
    # RETURNS A JSON ObJECT OF USERNAME, FIRST AND LAST
    lead = controls.get_lead(session.get('username'))
    if len(lead) == 0:
        lead = {'username': '', 'first_name': '', 'last_name': ''}
    else:
        lead = lead[0]
    notebooks = []
    if session.get('auth_token'):
        # CHECK AND SEE IF USER HAS SELECTED NOTEBOOKS
        if user['notebook_ids'] is not None and len(user['notebook_ids']) > 0:
            guid_list = user['notebook_ids'].split(',')
            flash("Getting Notebooks and Notes")
            notebooks = get_notebooks(session.get('auth_token'),
                                      session.get('shard_id'), guid_list)
        else:
            return redirect(url_for('configure', guid_list=None))
    # POST REQUESTS
    if request.method == 'POST':
        error_list = []
        note_list = request.form.getlist('note')
        # GET THE NOTE CONTENT FOR EACH NOTES GUID
        for value in note_list:
            try:
                title, guid = value.split(':')
                note = get_note(session.get('auth_token'),
                                session.get('shard_id'), guid)
            except Exception as e:
                error = "Error retrieving note using guid %s" % e
                return render_template('main.html', error=error)
            # ATTEMPT TO PARSE THE NOTE INTO A ENXML OBJECT
            # GET DOCTYPE FROM NOTE CONTENT
            rg = re.compile('(<!DOCTYPE .*?>)')
            m = rg.search(note)
            try:
                # CREATE EN OBJECT INITILIZING WITH NOTE AND DOCTYPE
                en = EN(note, doctype=m.group(1))
                # BREAK OUT TABLES
                en.break_out_tables()
                try:
                    en.set_activity_type('O')
                    en.set_activity_type('I')
                except:
                    error_list.append(
                        "Using an old Template, update your template in the future"
                    )
                    error_list.append(
                        "Unable to set Issues and Activities within the note")
                flash(
                    update_note(session.get('auth_token'),
                                session.get('shard_id'),
                                en.tostring(),
                                guid=guid,
                                title=title))
                # IF EMAIL IS SET
                if user['use_email'] == 1:
                    lib.send_email(en, app.config['EMAIL_SERVER'],
                                   user['email_address'])
                    flash("Note sent as email to %s" % user['email_address'])
                # IF LEAD IS SET
                if request.form['lead'] != 'None':
                    # GET LEAD AUTH_TOKEN
                    lead = controls.get_user_info(request.form['lead'])
                    flash(
                        new_note(shard_id=lead['shard_id'],
                                 content=en.tostring(),
                                 title=title,
                                 auth_token=lead['auth_token']))
                    flash("Sent note to lead: %s" % request.form['lead'])
                    controls.set_lead(session.get('username'),
                                      request.form['lead'])
                # CHANGE THE USERS LEAD ID TO THAT USED
                else:
                    controls.delete_lead(session.get('username'))
                    lead = {'username': '', 'first_name': '', 'last_name': ''}
                flash("Bug Time: %s" % en.times['B'])
                flash("Setup Time: %s" % en.times['S'])
                flash("Test Time: %s" % en.times['T'])
                flash("Session Length: %s" % en.session_length)
                en.export_xml(app.config['UPLOADED_FILE_DEST'],
                              "%s.xml" % title)
            except Exception as e:
                error_list.append(
                    "ERROR parsing out data from note %s. Exception: [%s]" %
                    (title, e))
    return render_template('main.html',
                           notebooks=notebooks,
                           error=error_list,
                           authorized_users=authorized_users,
                           lead=lead)
Ejemplo n.º 12
0
def index():
    error_list = None
    # CHECK IF THE USER IS LOGGED IN, OTHERWISE REDIRECT
    if not session.get('logged_in'):
        return redirect(url_for('login'))
    # GET THE USER INFO, REDIRECT IF NOTHING IS RETURNED
    user = controls.get_user_info(session.get('username'))
    if not user:
        redirect(url_for('logout'))
    authorized_users = controls.get_authorized_users()
    # RETURNS A JSON ObJECT OF USERNAME, FIRST AND LAST 
    lead = controls.get_lead(session.get('username'))
    if len(lead) == 0:
        lead = {'username':'', 'first_name':'', 'last_name':''}
    else:
        lead = lead[0]
    notebooks = []
    if session.get('auth_token'):
        # CHECK AND SEE IF USER HAS SELECTED NOTEBOOKS
        if user['notebook_ids'] is not None and len(user['notebook_ids']) > 0:
            guid_list = user['notebook_ids'].split(',')
            flash("Getting Notebooks and Notes")
            notebooks = get_notebooks(session.get('auth_token'), 
                                      session.get('shard_id'),
                                      guid_list) 
        else:
            return redirect(url_for('configure', guid_list=None))         
    # POST REQUESTS
    if request.method=='POST':
        error_list = []
        note_list = request.form.getlist('note')
        # GET THE NOTE CONTENT FOR EACH NOTES GUID
        for value in note_list:
            try:
                title, guid = value.split(':')
                note = get_note(session.get('auth_token'), 
                                session.get('shard_id'),
                                guid)
            except Exception as e:
                error = "Error retrieving note using guid %s" %e
                return render_template('main.html', 
                                       error=error)
            # ATTEMPT TO PARSE THE NOTE INTO A ENXML OBJECT
            # GET DOCTYPE FROM NOTE CONTENT
            rg = re.compile('(<!DOCTYPE .*?>)')
            m = rg.search(note)
            try:
                # CREATE EN OBJECT INITILIZING WITH NOTE AND DOCTYPE
                en = EN(note, doctype=m.group(1))
                # BREAK OUT TABLES
                en.break_out_tables()
                try:
                    en.set_activity_type('O')
                    en.set_activity_type('I')
                except:
                    error_list.append("Using an old Template, update your template in the future")
                    error_list.append("Unable to set Issues and Activities within the note")
                flash(update_note(session.get('auth_token'),
                                  session.get('shard_id'),
                                  en.tostring(), 
                                  guid=guid, 
                                  title=title))
                # IF EMAIL IS SET
                if user['use_email'] == 1:
                    lib.send_email(en, app.config['EMAIL_SERVER'], user['email_address'])
                    flash("Note sent as email to %s" %user['email_address'])
                # IF LEAD IS SET
                if request.form['lead'] != 'None':
                    # GET LEAD AUTH_TOKEN
                    lead = controls.get_user_info(request.form['lead'])
                    flash(new_note(shard_id=lead['shard_id'],
                                   content=en.tostring(), 
                                   title=title, 
                                   auth_token=lead['auth_token']))
                    flash("Sent note to lead: %s" %request.form['lead'])
                    controls.set_lead(session.get('username'), request.form['lead'])
                # CHANGE THE USERS LEAD ID TO THAT USED
                else: 
                    controls.delete_lead(session.get('username'))
                    lead = {'username':'', 'first_name':'', 'last_name':''}
                flash("Bug Time: %s" %en.times['B'])
                flash("Setup Time: %s" %en.times['S'])
                flash("Test Time: %s" %en.times['T'])
                flash("Session Length: %s" %en.session_length)
                en.export_xml(app.config['UPLOADED_FILE_DEST'], "%s.xml" %title)
            except Exception as e:
                error_list.append("ERROR parsing out data from note %s. Exception: [%s]" %(title, e))
    return render_template('main.html',
                            notebooks=notebooks, 
                            error=error_list,
                            authorized_users=authorized_users,
                            lead=lead)