Exemple #1
0
    def save( self, request ):
        my_email = self.cleaned_data["email"]

        if len(my_email) == 0:
            raise forms.ValidationError(_(u"Favor preencher o email."))

        if my_email != EmailAddress.objects.get_primary(request.user).email:
            EmailAddress.objects.add_email( request.user, my_email )
            new_email = EmailAddress.objects.get(
                           user=request.user,
                            email=my_email,
                        )
            new_email.set_as_primary()
        try:
            tintzSettings = TintzSettings.objects.get(user=request.user)
        except:
            tintzSettings = TintzSettings()

        tintzSettings.email_follow = self.cleaned_data["email_follow"]
        tintzSettings.email_publication = self.cleaned_data["email_publication"]
        tintzSettings.email_post = self.cleaned_data["email_post"]
        tintzSettings.user = request.user

        #try:
        oldpassword = self.cleaned_data["oldpassword"]
        password2 =  self.cleaned_data["password2"]
        if len(oldpassword) > 0 and len(password2) > 0:
            self.user.set_password(password2)
            self.user.save()
            request.user.message_set.create(message=ugettext(u"Senha alterada com sucesso."))
        #except forms.ValidationError:
        #raise forms.ValidationError(_(u"Senhas não conferem."))
        #except:
        #    raise forms.ValidationError(_(u"Erro ao atualizar senha."))

        tintzSettings.save()

        self.change_avatar(request)
Exemple #2
0
    def save(self, request):
        first_name = self.cleaned_data["first_name"]
        last_name = self.cleaned_data["last_name"]
        birth_date = self.cleaned_data["birth_date"]
        about = self.cleaned_data["about"]
        interests = self.cleaned_data["interests"]
        location = self.cleaned_data["location"]
        state = self.cleaned_data["state"]
        country = self.cleaned_data["country"]
        website = self.cleaned_data["website"]

        new_user = User.objects.get(username=request.user.username)
        #new_user.is_active = 1
        #new_user.save()

        create_profile(new_user, name=new_user.username)
        profile, created = Profile.objects.get_or_create(user=new_user)
        profile.first_name = first_name
        profile.last_name = last_name
        profile.birth_date = birth_date
        profile.about = about
        profile.interests = interests
        profile.location = location
        profile.state = state
        profile.country = country
        profile.website = website
        profile.save()

        #Creating default settings
        tintzSettings = TintzSettings()

        tintzSettings.email_follow = True
        tintzSettings.email_publication = True
        tintzSettings.email_post = True
        tintzSettings.user = new_user
        tintzSettings.save()

        return new_user.username, new_user.password, new_user.email # required for authenticate()