示例#1
0
    def clean_username(self):
        """
        Validate that the username is alphanumeric and is not already
        in use.

        """
        existing = UserModel().objects.filter(username__iexact=self.cleaned_data['username'])
        if existing.exists():
            raise forms.ValidationError(_("A user with that username already exists."))
        else:
            return self.cleaned_data['username']
示例#2
0
    def clean_username(self):
        """
        Validate that the username is alphanumeric and is not already
        in use.

        """
        existing = UserModel().objects.filter(
            username__iexact=self.cleaned_data['username'])
        if existing.exists():
            raise forms.ValidationError(
                _("A user with that username already exists."))
        else:
            return self.cleaned_data['username']
示例#3
0
 def clean_email(self):
     email = self.cleaned_data.get('email')
     if email and UserModel().objects.filter(email__iexact=email).exists():
         raise forms.ValidationError(
             _('A user with that email address already exists.'))
     else:
         return email
示例#4
0
 def clean_email(self):
     email = self.cleaned_data.get('email')
     # You cannot change your email to another user's email
     if email and UserModel().objects.filter(email__iexact=email).exclude(
             pk=self.instance.pk).exists():
         raise forms.ValidationError(
             _('A user with that email address already exists.'))
     else:
         return email
示例#5
0
def UserSignUp(request):
    if (request.method == "POST"):
        form1 = UserForm(request.POST)
        if (form1.is_valid()):
            username = form1.cleaned_data['username']
            email = form1.cleaned_data['email']
            password = form1.cleaned_data['password']
            retype_password = form1.cleaned_data['confirm_password']
            User.objects.create_user(username=username,
                                     email=email,
                                     password=password,
                                     first_name="job_seeker")
            messages.success(request, 'user registration successful')
            usr = authenticate(username=username, password=password)
            login(request, usr)
            user_instance = UserModel(user=usr, accountType="job_seeker")
            user_instance.save()
            # return HttpResponseRedirect(reverse(UserDashBoard))
            return HttpResponseRedirect(reverse(HomePage))
    else:
        form1 = UserForm()
    return render(request, 'user_signup.html', {'reg_form': form1})
示例#6
0
    def register(self, request, **cleaned_data):
        username, email, password = cleaned_data['username'], cleaned_data['email'], cleaned_data['password1']
        first_name, last_name = cleaned_data['first_name'], cleaned_data['last_name']

        UserModel().objects.create_user(username, email, password,
                                        first_name=first_name, last_name=last_name)

        new_user = authenticate(username=username, password=password)
        login(request, new_user)
        signals.user_registered.send(sender=self.__class__,
                                     user=new_user,
                                     request=request)
        return new_user
示例#7
0
class UserProfileUpdateView(generic.UpdateView):
    model = UserModel()
    template_name = 'accounts/profile_update.html'
    form_class = UserProfileUpdateForm
    success_url = reverse_lazy('accounts:profile')

    def get_object(self, queryset=None):
        return self.request.user

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(UserProfileUpdateView, self).dispatch(*args, **kwargs)

    def form_valid(self, form):
        result = super(UserProfileUpdateView, self).form_valid(form)
        messages.success(self.request, "Your profile has been updated.")
        return result
示例#8
0
 class Meta:
     model = UserModel()
     fields = ['email', 'first_name', 'last_name']