diff --git a/README.md b/README.md index 48d42a8..1775085 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,8 @@ Initial dependencies 1. Install python and pip: `sudo apt-get install python3 python3-pip` 2. Install other dependencies: `sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev python-ldap django-auth-ldap` -1. Install python library: `pip3 install -r requirements.txt` +3. Install python library: `pip3 install -r requirements.txt` +4. To create admin: `python3 manage.py createsuperuser` To configure NGINX as proxy, use the following method diff --git a/omi_security/security_node/form.py b/omi_security/security_node/form.py index a21bf3a..71c353c 100644 --- a/omi_security/security_node/form.py +++ b/omi_security/security_node/form.py @@ -12,8 +12,8 @@ class UserForm(forms.ModelForm): email = forms.EmailField(label='Email', max_length=64, widget=forms.TextInput(attrs={'placeholder': 'Email'})) password = forms.CharField(min_length=6, max_length=32, label='Password', widget=forms.PasswordInput) password1 = forms.CharField(min_length=6, max_length=32, label='Password confirmation', widget=forms.PasswordInput) - is_superuser = forms.BooleanField(label='Superuser', required=False) - superuser_secret = forms.CharField(label='superuser secret', max_length=64, required=False, widget=forms.TextInput(attrs={'placeholder': 'superuser secret'})) + #is_superuser = forms.BooleanField(label='Superuser', required=False) + #superuser_secret = forms.CharField(label='superuser secret', max_length=64, required=False, widget=forms.TextInput(attrs={'placeholder': 'superuser secret'})) class Meta: fields = ['first_name', 'last_name', 'username', 'email', 'password', 'password1', 'is_superuser'] model=User @@ -25,6 +25,7 @@ def clean(self): raise forms.ValidationError( "Password and Confirm Password does not match" ) + """ if cleaned_data.get("is_superuser"): cleaned_data = super(UserForm, self).clean() superuser_secret = cleaned_data.get("superuser_secret") @@ -33,6 +34,7 @@ def clean(self): raise forms.ValidationError( "Please enter valid superuser secret or uncheck the superuser checkbox" ) + """ def clean_email(self): email = self.cleaned_data.get('email') username = self.cleaned_data.get('username') @@ -55,3 +57,39 @@ class Meta: model = Group +class SuperuserForm(forms.ModelForm): + first_name = forms.CharField(label='First Name', max_length=64,widget=forms.TextInput(attrs={'placeholder': 'First name'})) + last_name = forms.CharField(label='Last Name', max_length=64,widget=forms.TextInput(attrs={'placeholder': 'Last Name'})) + username = forms.CharField(min_length=6, label='Username', max_length=32, widget=forms.TextInput(attrs={'placeholder': 'Username'})) + email = forms.EmailField(label='Email', max_length=64, widget=forms.TextInput(attrs={'placeholder': 'Email'})) + password = forms.CharField(min_length=6, max_length=32, label='Password', widget=forms.PasswordInput) + password1 = forms.CharField(min_length=6, max_length=32, label='Password confirmation', widget=forms.PasswordInput) + is_superuser = forms.BooleanField(label='Superuser', required=False) + + class Meta: + fields = ['first_name', 'last_name', 'username', 'email', 'password', 'password1', 'is_superuser'] + model = User + + def clean(self): + cleaned_data = super(SuperuserForm, self).clean() + password = cleaned_data.get("password") + password1 = cleaned_data.get("password1") + if password != password1: + raise forms.ValidationError( + "Password and Confirm Password does not match" + ) + + def clean_email(self): + email = self.cleaned_data.get('email') + username = self.cleaned_data.get('username') + if email and User.objects.filter(email=email).exclude(username=username).exists(): + raise forms.ValidationError(u'Email addresses must be unique.') + return email + + def save(self, commit=True): + # Save the provided password in hashed format + user = super(SuperuserForm, self).save(commit=False) + user.set_password(self.cleaned_data["password"]) + if commit: + user.save() + return user \ No newline at end of file diff --git a/omi_security/security_node/templates/base.html b/omi_security/security_node/templates/base.html index 4ce8040..d31e38b 100644 --- a/omi_security/security_node/templates/base.html +++ b/omi_security/security_node/templates/base.html @@ -22,7 +22,10 @@
First Name | +Last Name | +Username | +Is_superuser | +Change Status | +||
---|---|---|---|---|---|---|
{{ user.first_name }} | +{{ user.last_name }} | +{{ user.email }} | +{{ user.username }} | +{{ user.is_superuser }} | + {% if user.is_superuser %} ++ + {% else %} + | + + {% endif %} + |