示例#1
0
文件: views.py 项目: pawelpbm/student
def account(request):
    """View for displaying and modyfing acount information"""
    if request.method == 'POST':
        form = AccountForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            ssh_public_key = form.cleaned_data['ssh_public_key']
            
            username = request.user.username
            user = LdapUser.objects.get(uid=username)
            
            user.mail = email

            keys = user.ssh_public_key
            keys_new = []
            for key in keys:
                if key.startswith(('ssh-dss','ssh-rsa',)):
                    keys_new.append(ssh_public_key)
                else:
                    keys_new.append(key)
                    
            user.ssh_public_key = keys_new
            user.save()

            return render_to_response('account.html', {'form': form, 'changed': 1}, context_instance=RequestContext(request))
          
    else:
        username = request.user.username
        user = LdapUser.objects.get(uid=username)
        form = AccountForm(initial={'email': user.mail, 'ssh_public_key': find_primary_key(user)})
        
    return render_to_response('account.html',  {'form': form,}, context_instance=RequestContext(request))
示例#2
0
文件: views.py 项目: pawelpbm/student
def git_repo_add(request):
    """View for adding repository permissions"""
    repos = list_user_repos(request.user.username)
    if request.method == 'POST':
        form = RepoForm(request.POST, repos=repos)
        if form.is_valid():    
            my_username = request.user.username
            username = form.cleaned_data['username']
            reponame = form.cleaned_data['reponame']
            permissions = form.cleaned_data['permissions']

            # User that want access to repo
            guest = LdapUser.objects.get(uid=username)

            # Owner of repo
            user = LdapUser.objects.get(uid=my_username)
            
            command = 'command="/var/student/gitserver.py %s" ' % (guest,)
            try:
                user.ssh_public_key.append(command + find_primary_key(guest))
                user.save()
            except ldap.TYPE_OR_VALUE_EXISTS:
                pass
            
            Git = git_entry(my_username)
            git = Git()
            git.ou = "git"
            try:
                git.save()
            except ldap.ALREADY_EXISTS:
                pass
            
            Repo = repo_entry(my_username)
            try:
                repo = Repo.objects.get(repo=reponame)
            except ObjectDoesNotExist:
                repo = Repo()

            repo.repo = reponame;
            if permissions == "rw":
                repo.userRW.append(username)
            elif permissions == "ro":
                repo.userRO.append(username)

            try:
                repo.save()            
            except ldap.TYPE_OR_VALUE_EXISTS:
                return git_repos(request, err={'err': 'permission_exist'})
                
            return git_repos(request, repository_modification={'username': username, 'reponame': reponame, 'permission': 'zapis' if permissions == 'rw' else 'odczyt', 'modification': 'add'})
    else:
        if not repos:
            return render_to_response('repos.html',  {'error_no_git_dir': True}, context_instance=RequestContext(request))
        form = RepoForm(repos=repos)

    return render_to_response('repo_add.html',  {'form': form,}, context_instance=RequestContext(request))