*Hi*
*I am using django 1.5 and created my own user model by AUTH_USER_MODEL= 
'account.User' in settings.*

*my user model is like this:*

from django.db import models
from django.contrib.auth.models import AbstractBaseUser, UserManager, 
PermissionsMixin
# Create your models here.
GENDER = (
    ('M', 'Male'),
    ('F', 'Female')
)

class User(AbstractBaseUser, PermissionsMixin):
    username = models.CharField(max_length=100, unique=True)
    first_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)
    email = models.EmailField(unique=True)
    gender = models.CharField(max_length=10, choices=GENDER)
    is_admin = models.BooleanField(default=False)
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=False)
    date_joined = models.DateTimeField(auto_now_add=True)
    
    objects = UserManager()
    
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username']
    
    def __unicode__(self):
        return self.get_full_name()
    
    
    def get_full_name(self):
        return ' '.join([self.first_name, self.last_name]) or self.username
    
    def get_short_name(self):
        return self.first_name or self.username.

The form which i present to user for signup is:

class SignupForm(forms.ModelForm):
    class Meta:
        model = User
        fields = ['username', 'first_name', 'last_name', 'email', 'gender', 
'password']
        exclude = ['last_login', 
'is_superuser','groups','user_permissions', 'is_admin', 'is_staff', 
'is_active']
        widgets = {
            'password': forms.PasswordInput(),
        }
        
        def save(self):
            user = super(SignupForm, self).save(commit=False)
            user.set_password(self.cleaned_data['password'])
            user.save(commit=True)
            return user


*my login view function is like this:*

class LoginView(View):
    def get(self, request, *args, **kwargs):
        form = LoginForm()
        return render_to_response('login.html', 
{'form':form},context_instance = RequestContext(request) )
    
    def post(self,request,*args, **kwargs ):
        username = self.request.POST['username']
        password = self.request.POST['password']
        user = authenticate(username=username, password=password)
        
        if user is not None:
            if user.is_active:
                print "You provided a correct username and password!"
                login(request, user)
                return redirect(reverse('bands-list'))
            else:
                login(request, user)
                print "Your account has been disabled!"
                return redirect(reverse('bands-list'))
        else:
            form = LoginForm()
            return render_to_response('login.html', 
{'form':form},context_instance = RequestContext(request) )

*and somewhere in my template:*

{% if request.user.is_authenticated %}
        <p>hello {{ user.first_name }}</p> <button class="btn btn-mini" 
>Logout</button>
        {% else %}
        <a class="btn btn-small" href="{% url 'login-view' %}">Login</a>
        <a class="btn btn-small" href="{% url 'register-view' %}">Signup</a>
        {% endif %}

*the problem i am facing are:*
*
*
*1. when the user signs up, password stored are not encrypted, ( though i 
am overriding save() to do so above)*
*2. though i provide correct password, request.user.is_authenticated does 
not works for me.*
*
*
kind suggestions are welcome.
Regards
Vijay Shanker



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to