示例#1
0
def admin():
    """used to administrate the users of the system"""
    if request.method == 'GET':
        # SELECT ALL USERS, ADMIN_USERS, AND LEAD ID
        users = controls.get_users_info()
        # GET LEAD FIRST / LAST BASED ON lead_id
        for user in users:
            # RETURNS A JSON ObJECT OF USERNAME, FIRST AND LAST
            lead = controls.get_lead(user['username'])
            if len(lead) > 0:
                user['lead_first'] = lead['first_name']
                user['lead_last'] = lead['last_name']
        return render_template('admin.html', users=users)
    elif request.method == 'POST':
        users = request.form.getlist('user')
        action = request.form['action']
        for user in users:
            if action == 'delete':
                controls.delete_user(user)
            elif action == 'admin':
                controls.update_user(user, is_admin=1)
            elif action == 'noadmin':
                controls.update_user(user, is_admin=0)
            elif action == 'auth':
                controls.update_user(user,
                                     auth_token=None,
                                     shard_id=None,
                                     authorized=0)
                session['authorized'] = 0
                session.pop('auth_token')
                session.pop('shard_id')
            elif action == 'pwd':
                controls.update_user(user, password='******')
        return redirect(url_for('admin'))
示例#2
0
文件: views.py 项目: 3-form/ENTSM
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))
示例#3
0
文件: views.py 项目: 3-form/ENTSM
def admin():
    """used to administrate the users of the system"""
    if request.method == 'GET':
        # SELECT ALL USERS, ADMIN_USERS, AND LEAD ID
        users = controls.get_users_info()
        # GET LEAD FIRST / LAST BASED ON lead_id
        for user in users:
            # RETURNS A JSON ObJECT OF USERNAME, FIRST AND LAST 
            lead = controls.get_lead(user['username'])
            if len(lead) > 0:
                user['lead_first'] = lead['first_name']
                user['lead_last'] = lead['last_name']
        return render_template('admin.html', users=users)
    elif request.method == 'POST':
        users = request.form.getlist('user')
        action = request.form['action']
        for user in users:
            if action == 'delete':
                controls.delete_user(user)
            elif action == 'admin':
                controls.update_user(user, is_admin=1)
            elif action == 'noadmin':
                controls.update_user(user, is_admin=0)
            elif action == 'auth':
                controls.update_user(user, auth_token=None, shard_id=None, authorized=0)
                session['authorized'] = 0
                session.pop('auth_token')
                session.pop('shard_id')
            elif action == 'pwd':
                controls.update_user(user, password='******')
        return redirect(url_for('admin'))
示例#4
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))
示例#5
0
def logout():
    for key in session.keys():
        session.pop(key, None)
    flash('You were logged out')
    return redirect(url_for('index'))
示例#6
0
文件: views.py 项目: 3-form/ENTSM
def logout():
    for key in session.keys():
        session.pop(key, None)
    flash('You were logged out')
    return redirect(url_for('index'))