def remove_users(request):
    privilege = view_utils.get_user_privilege(request)
    if privilege != 'admin':
        return redirect('/')

    query = QueryDict(request.body)
    usernames = query.getlist('user-list')
    usernames = write_models.validate_usernames(usernames)
    repository.remove_users(usernames)
    return redirect('/account/detail/#remove-users')
Esempio n. 2
0
def main_page(request):
    d = {}

    privilege = view_utils.get_user_privilege(request)
    view_utils.insert_privileges(d, privilege)
    d['loptruong_active'] = 'active'

    if privilege == "loptruong":
        return render(request, 'hoctap/manage_loptruong.html', d)
    return redirect('/')
Esempio n. 3
0
def homepage(request):
    d = {'homepage': 'active'}
    privilege = view_utils.get_user_privilege(request)
    view_utils.insert_privileges(d, privilege)

    if privilege == "admin":
        return render(request, 'home/homepage_admin.html', d)
    elif privilege == "saodo":
        return render(request, 'home/homepage_saodo.html', d)
    elif privilege == "loptruong":
        return render(request, 'home/homepage_loptruong.html', d)
    else:
        return render(request, 'home/homepage_guess.html', d)
def add_user(request):
    privilege = view_utils.get_user_privilege(request)
    if privilege != 'admin':
        return redirect('/')

    query = QueryDict(request.body)

    ret = repository.add_user(username=query['username'],
                              password=query['password'],
                              re_enter_password=query['re-enter-password'],
                              privilege_name=query['privilege-name'])

    if ret is False:
        return render(request, 'account/add-account-error.html')

    return redirect('/account/detail/#add-user')
def change_password(request):
    privilege = view_utils.get_user_privilege(request)
    if privilege == None:
        return redirect('/')

    query = QueryDict(request.body)

    ret = repository.update_password(
        username=view_utils.get_username(request),
        old_password=query['old-password'],
        new_password=query['new-password'],
        re_enter_new_password=query['re-enter-new-password'])
    if ret is False:
        return render(request, 'account/change-password-error.html')

    return redirect('/account/detail/#change-password')
def detail(request):
    d = {
        'username': view_utils.get_username(request),
        'privilege': view_utils.get_user_privilege_string(request),
    }
    privilege = view_utils.get_user_privilege(request)
    view_utils.insert_privileges(d, privilege)

    if privilege is None:
        return redirect('/')
    elif privilege == "admin":
        users = repository.get_users_except_admin()
        d['users'] = users
        return render(request, 'account/detail_admin.html', d)
    else:
        return render(request, 'account/detail_normal.html', d)
def login(request):
    if view_utils.get_user_privilege(request) is None:
        return render(request, 'account/login.html')
    else:
        return redirect('/')
Esempio n. 8
0
def add_row(request):
    privilege = view_utils.get_user_privilege(request)

    if privilege != "loptruong":
        return redirect('/')
    return HttpResponse("")