Ejemplo n.º 1
0
def delete_student_page():
    #db = current_app.config["db"]
    student_key = request.args.get('student_key')
    delete_user(student_key)
    global student_user
    student_user = True
    return render_template("home.html",
                           user_email=user_email,
                           club_user=club_user,
                           student_user=student_user)
Ejemplo n.º 2
0
    def on_delete(self, req, resp, username=None):
        """Handle DELETE requests to remove user"""
        session_user = session.get_user_name(req)
        if not session_user:
            raise falcon.HTTPUnauthorized(title='Login required')
        if session_user != username:
            raise falcon.HTTPUnauthorized(title='Permission denied')

        # delete user
        user.delete_user(user_storage, username)
        # and revoke user's session token
        session.invalidate_session(req)
Ejemplo n.º 3
0
def delete_user(user_id):
    if not auth.is_logged_in(session):
        return redirect_to_login(STRINGS['SIGNED_OUT'])
    if not auth.is_admin(session):
        return redirect_to_home(STRINGS['NOT_AUTHORIZED'])
    if int(user_id) == session['user_id']:
        flash("You can't delete your own account")
    else:
        user.delete_user(user_id)
        flash("User deleted successfully", category="success")

    return redirect(url_for('admin'))
Ejemplo n.º 4
0
def delete():
    id = request.form.get('id')
    result = delete_user(id)
    if isinstance(result, int):
        return '1'
    else:
        return render_template('error.html', result=result)
Ejemplo n.º 5
0
def delete_user(id):
    username = session["user_name"]
    if user.delete_user(id):
        flash(
            'Profile ' + username +
            ' deleted, all reviews, comments and likes removed.',
            'flashSuccess')
        return redirect("/")
    return redirect("/")
Ejemplo n.º 6
0
def delete_user(message):
    # delete user from database if you know id or number, or email
    if message.text == '/q':
        _quit_func(message)
    result = user.delete_user(message.text)
    if not result:
        bot.send_message(message.from_user.id, 'Такого юзера не существует, поробуй еще раз или напиши /q')
        bot.register_next_step_handler(message, delete_user)
    else:
        bot.send_message(message.from_user.id, result)
Ejemplo n.º 7
0
def delete_user(username):
    """
    Delete a user
    :param username:
    :return:
    """
    assert username == request.view_args['username']
    if not auth(  # authenticate user
            app.config['SECRET_KEY'],
            request,
            username
    ):
        return response_unauthorised()

    try:
        user.delete_user(username)
        response_json = json_dict({"User deleted: ": username}, indent=4)
        return Response(response_json, status=success_code, mimetype='application/json')
    except Exception as e:
        print(e)
        return response_unknown()
Ejemplo n.º 8
0
    def leave_post(self, current_uid = -1):
        user_id = current_uid
        usr = user.get_user(user_id)[1]

        password = web.input().password
        if not user.verify_password(user_id, password):
            return util.render().error(error_message= _('INVALID_PASSWORD'), help_context='error')

        result = user.delete_user(user_id)
        if not result[0]:
            return util.render().error(error_message = result[1], help_context='error')
        web.ctx.session.uid = 0
        web.ctx.session.kill()
        raise web.seeother(util.link('/'))
Ejemplo n.º 9
0
def index():
    name = request.args.get('name')
    passwd = request.args.get('passwd')
    add = request.args.get('add')
    oper = request.args.get('oper')

    # print "+++++++++++++++++++++++++++"
    print "name: %s, passwd: %s" % (name, passwd)
    # print "+++++++++++++++++++++++++++"


    operation_result_str = ""
    # status_code = 0

    if add == "submit" and oper == None:
        oper = 'add'
        status_code = add_user(name=name, passwd=passwd)
        operation_result_str = oper_result(oper=oper, status_code=status_code)

    elif add == None and oper == 'del':
        oper = 'del'
        status_code = delete_user(name=name)
        operation_result_str = oper_result(oper=oper, status_code=status_code)

    # print operation_result_str
    # print status_code
    
    result = '''
        <form action="/" method="get">
            name:
            <input type="text" name="name">
            password:
            <input type="password" name="passwd">
            <input type="submit" name="add" value="submit">
        </form>
    '''
    if operation_result_str != 1:
        operation_result_str = '<h2>%s</h2>' % operation_result_str
        result += operation_result_str

    user_html_table = html_table()
    result += user_html_table

    return result
Ejemplo n.º 10
0
def index():
    name = request.args.get('name')
    passwd = request.args.get('passwd')
    add = request.args.get('add')
    oper = request.args.get('oper')

    # print "+++++++++++++++++++++++++++"
    print "name: %s, passwd: %s" % (name, passwd)
    # print "+++++++++++++++++++++++++++"

    operation_result_str = ""
    # status_code = 0

    if add == "submit" and oper == None:
        oper = 'add'
        status_code = add_user(name=name, passwd=passwd)
        operation_result_str = oper_result(oper=oper, status_code=status_code)

    elif add == None and oper == 'del':
        oper = 'del'
        status_code = delete_user(name=name)
        operation_result_str = oper_result(oper=oper, status_code=status_code)

    # print operation_result_str
    # print status_code

    result = '''
        <form action="/" method="get">
            name:
            <input type="text" name="name">
            password:
            <input type="password" name="passwd">
            <input type="submit" name="add" value="submit">
        </form>
    '''
    if operation_result_str != 1:
        operation_result_str = '<h2>%s</h2>' % operation_result_str
        result += operation_result_str

    user_html_table = html_table()
    result += user_html_table

    return result
Ejemplo n.º 11
0
def usuario_deletar():
    reposta = json.loads(request.form['data'])
    user.delete_user(reposta)
    return 'Usuario deletado'
Ejemplo n.º 12
0
import user

params = cgi.FieldStorage()

data = session.get_session_data()
if data is None:  # tko nema sessiju nije logiran. - idi na login
    print("Location: login.py")
else:
    user_id = data.get("user_id", None)
    user_role = user.get_user_role(user_id)
    if user_role != "ADMIN":
        print("Location: index.py")
    else:
        delete_id = params.getvalue("delete_id")
        if delete_id:
            user.delete_user(delete_id)
print()
base.start_html()
print("<h1>USERS:</h1>")
users = user.get_all_users()
print("<table border=1>")
for user in users:
    print("<tr>")
    print("<td>" + user[1] + "</td>")
    print('<td><a href="edit_user_view.py?edit_id=' + str(user[0]) +
          '">edit</a></td>')
    print('<td><a href="users.py?delete_id=' + str(user[0]) +
          '">delete</a></td>')
    print("</tr>")
print('<tr><td><a href="register.py">add user</a></td></tr>')
print("</table>")
Ejemplo n.º 13
0
 def delete_user(self, userid):
     return dumps(user.delete_user(userid))
Ejemplo n.º 14
0
        break

    if menu == "1":
        clear_screen()
        add_user_from_csv = input("Do you want to add a user from a csv? (\'yes\' or \'no\') ").lower()

        if add_user_from_csv == 'yes':
            print("Which user you want to add? (Enter the ID): \nID - Name")
            print(user.print_users())

            input_user_id = input('> ')

            name = user.find_user(input_user_id)
            user.add_user(name)
        elif add_user_from_csv == 'no':
            input_name = input("What's the user's full name? ")
            user.add_user(input_name)
        else:
            print("Please answer \'yes\' or \'no\'")
    elif menu == "2":
        clear_screen()
        user.delete_user()
    elif menu == '3':
        clear_screen()
        user.modify_user()
    elif menu == '4':
        clear_screen()
        user.reset_password()
    else:
        print('Please enter the right number')
Ejemplo n.º 15
0
def delete_user():
    username = request.args.get('username', '')
    user.delete_user(username)
    return redirect('/users/')
Ejemplo n.º 16
0
def delete_user():
    username = request.args.get('username', '')
    user.delete_user(username)
    return redirect('/users/')
Ejemplo n.º 17
0
def delete(id: int):
    return delete_user(id)
Ejemplo n.º 18
0
def delete(user_id):
    res = delete_user(user_id)
    return { "success": True }, 200
Ejemplo n.º 19
0
    if not admin:
        result = filter(lambda x: x['name'] != CONF.keystone.username and x['name'] != CONF.identify.super_user_name,
                        ret)
    else:
        result = filter(lambda x: x['name'] != CONF.keystone.username,
                        ret)

    if CONF.ldap.enable:
        try:
            ldap_ret = eldap.users()
            l_u = {}
            for lu in ldap_ret:
                if lu['name']:
                    l_u[lu['name']] = lu
            ldap_result = []
            for k in result:
                if k['name'] not in l_u.keys():
                    if admin and k['name'] == CONF.identify.super_user_name:
                        ldap_result.append(k)
                    elif k['name'] != 'ecloud':
                        yield user.delete_user(k["id"])
                else:
                    k.update(l_u[k['name']])
                    ldap_result.append(k)
            result = ldap_result
        except BaseException, e:
            LOG.error("list ldap user error %s",e)
            LOG.error(trace())
    raise gen.Return(result)
Ejemplo n.º 20
0
def profile(user_id):
    """
    a profile page for normal registered users
    if it is users own profile; user can change account info
    else; user can see the common clubs and basic information of the other user
    """
    if not current_user.is_authenticated:
        return redirect(url_for('login'))
    if current_user.is_admin:
        abort(401)
    try:
        form = UserUpdateForm()
        user = get_user_by_id(id=current_user.id)
        if request.method == 'GET':
            if user_id == current_user.id:
                user = get_user_by_id(id=current_user.id)
                form.name.data = user.name
                form.surname.data = user.surname
                form.student_id.data = user.student_id
                form.email.data = user.email
                #form.department.data = user.department
                if user.gender:
                    form.gender.data = user.gender
                return render_template('profile.html',
                                       form=form,
                                       name=None,
                                       surname=None,
                                       student_id=None,
                                       department=None)
            elif user_id != current_user.id:
                user = get_user_by_id(id=user_id)
                name = user.name
                surname = user.surname
                student_id = user.student_id
                department = user.department
                get_common_clubs_statement = """select clubs.id, clubs.name from clubs 
                                                join members 
                                                on clubs.id = members.club_id 
                                                join users 
                                                on users.id = members.user_id 
                                                where users.id = %s
                                                INTERSECT 
                                                select clubs.id, clubs.name from clubs 
                                                join members 
                                                on clubs.id = members.club_id 
                                                join users 
                                                on users.id = members.user_id 
                                                where users.id = %s """
                with connection.cursor() as cursor:
                    cursor.execute(get_common_clubs_statement,
                                   (current_user.id, user_id))
                    common_clubs = cursor.fetchall()

                return render_template('profile.html',
                                       name=name,
                                       surname=surname,
                                       student_id=student_id,
                                       department=department,
                                       common_clubs=common_clubs)
        elif request.method == 'POST':
            if 'delete' in request.form:
                return "asd"
                logout_user()
                delete_user(user_id=user_id)
                flash('User Deleted')
                return redirect(url_for('register'))
            if form.validate_on_submit():
                name = form.data["name"]
                surname = form.data["surname"]
                student_id = form.data["student_id"]
                email = form.data["email"]
                if form.data["gender"]:
                    gender = form.data["gender"]
                else:
                    gender = None
                x = False
                if (user.student_id != student_id):
                    x = True
                update_user(current_user.id, name, surname, student_id, email,
                            gender)
                if x:
                    flash(
                        'Your student id is changed, login again with your new id'
                    )
                return redirect(url_for('profile', user_id=current_user.id))
            else:
                print(form.errors)
                return render_template('profile.html', form=form)
    except Exception as e:
        print("Error in profile page", e)
Ejemplo n.º 21
0
def delete_user():
    id = request.args.get('id')
    user.delete_user(id)
    flash('删除用户成功!')
    return redirect('/users/')
Ejemplo n.º 22
0
def delete_user():
    username = request.args.get('username')
    user.delete_user(username)
    flash('删除用户信息成功')
    return redirect('/users/')