Пример #1
0
 def save(self):
     user = models.bsdUsers.objects.get(id=self.userid)
     models.bsdGroupMembership.objects.filter(bsdgrpmember_user=user).delete()
     groupid_list = self.cleaned_data["bsduser_to_group"]
     for groupid in groupid_list:
         group = models.bsdGroups.objects.get(id=groupid)
         m = models.bsdGroupMembership(bsdgrpmember_group=group, bsdgrpmember_user=user)
         m.save()
     notifier().reload("user")
Пример #2
0
    def save(self, commit=True):
        if commit:
            _notifier = notifier()
            group = self.cleaned_data["bsdusr_group2"]
            if group is None:
                try:
                    gid = models.bsdGroups.objects.get(bsdgrp_group=self.cleaned_data["bsdusr_username"]).bsdgrp_gid
                except:
                    gid = -1
            else:
                gid = group.bsdgrp_gid
            uid, gid, unixhash, smbhash = _notifier.user_create(
                username=str(self.cleaned_data["bsdusr_username"]),
                fullname=self.cleaned_data["bsdusr_full_name"].encode("utf8", "ignore").replace(":", ""),
                password=self.cleaned_data["bsdusr_password2"].encode("utf8", "ignore"),
                uid=self.cleaned_data["bsdusr_uid"],
                gid=gid,
                shell=str(self.cleaned_data["bsdusr_shell"]),
                homedir=str(self.cleaned_data["bsdusr_home"]),
                homedir_mode=int(self.cleaned_data["bsdusr_mode"], 8),
                password_disabled=self.cleaned_data["bsdusr_password_disabled"],
                locked=self.cleaned_data["bsdusr_locked"],
            )
            bsduser = super(bsdUserCreationForm, self).save(commit=False)
            try:
                grp = models.bsdGroups.objects.get(bsdgrp_gid=gid)
            except models.bsdGroups.DoesNotExist:
                grp = models.bsdGroups(
                    bsdgrp_gid=gid, bsdgrp_group=self.cleaned_data["bsdusr_username"], bsdgrp_builtin=False
                )
                grp.save()
            bsduser.bsdusr_group = grp
            bsduser.bsdusr_uid = uid
            bsduser.bsdusr_shell = self.cleaned_data["bsdusr_shell"]
            bsduser.bsdusr_unixhash = unixhash
            bsduser.bsdusr_smbhash = smbhash
            bsduser.bsdusr_builtin = False
            bsduser.save()

            models.bsdGroupMembership.objects.filter(bsdgrpmember_user=bsduser).delete()
            groupid_list = self.cleaned_data["bsdusr_to_group"]
            for groupid in groupid_list:
                group = models.bsdGroups.objects.get(id=groupid)
                m = models.bsdGroupMembership(bsdgrpmember_group=group, bsdgrpmember_user=bsduser)
                m.save()

            _notifier.reload("user")
            bsdusr_sshpubkey = self.cleaned_data.get("bsdusr_sshpubkey")
            if bsdusr_sshpubkey:
                _notifier.save_pubkey(
                    bsduser.bsdusr_home, bsdusr_sshpubkey, bsduser.bsdusr_username, bsduser.bsdusr_group.bsdgrp_group
                )
        return bsduser