Ejemplo n.º 1
0
from django.contrib.auth.hashers import check_password
from django.db import models
from django.utils.translation import ugettext_lazy as _
import config
import time

#更新登录信息
def update_last_login(sender, request, user, **kwargs):
    user.last_login_time = time.time()
    user.login_times += 1
    user.last_login_ip = get_client_ip(request)
    user.is_active = True
    user.save()
    
#登录消息处理
user_logged_in.connect(update_last_login)
    
class User(PageModel):
#    GENDER_CHOICES = (
#        ('M', 'Male'),
#        ('F', 'Female'),
#    )
    username = models.CharField(max_length=50, unique=True, help_text=_('字母、数字或下划线组成,长度小于20个字符'), blank=True)
    tel = models.CharField(max_length=20,blank=True)
    qq = models.CharField(max_length=13,blank=True)
    password = models.CharField(max_length=128)
    
    regist_ip = models.IPAddressField(blank=True, null=True)
    regist_time = models.PositiveIntegerField(default=time_util.get_now_second())
    invite_uid = models.IntegerField(default=0)
    login_times = models.IntegerField(default=1)
Ejemplo n.º 2
0
    timestamp = models.DateTimeField(auto_now_add=True)
    active = models.BooleanField(default=True)
    ended = models.BooleanField(default=False)

    def end_session(self):
        session_key = self.session_key
        try:
            Session.objects.get(pk=session_key).delete()
            self.active = False
            self.ended = True
            self.save()
        except:
            pass
        return self.ended


def user_logged_receiver(sender, instance, request, *args, **kwargs):
    user = instance
    ip_address = get_client_ip(request)
    session_key = request.session.session_key
    UserSession.objects.create(
        user=user,
        ip_address=ip_address,
        session_key=session_key
    )


user_logged_in.connect(user_logged_receiver)


Ejemplo n.º 3
0
                "pk": self.pk
            }
        else:
            if settings.IDIOS_USE_USERNAME:
                kwargs = {"username": self.user.username}
            else:
                kwargs = {"pk": self.pk}
        return reverse("profile_detail", kwargs=kwargs)

    @classmethod
    def get_form(cls):
        return get_profile_form(cls)

    def _default_profile_slug(cls):
        return cls._meta.module_name

    profile_slug = ClassProperty(classmethod(_default_profile_slug))


def create_profile(sender, instance=None, **kwargs):
    if instance is None:
        return
    profile, created = get_profile_model().objects.get_or_create(user=instance)
post_save.connect(create_profile, sender=User)


def additional_info_kickstart(sender, **kwargs):
    request = kwargs.get("request")
    request.session["idios_additional_info_kickstart"] = True
user_logged_in.connect(additional_info_kickstart)
Ejemplo n.º 4
0
#def post_save_session_reciever(sender,instance,created,*args,**kwargs):
 #   if created:
  #      qs=UserSession.objects.filter(user=instance.user,ended=False,active=False).exclude(id=instance.id)
   #     for i in qs:
    #        i.end_session()  
    #if not instance.active and not instance.ended:
     #   instance.end_session() 
#it ends all the session that is currently bieng active at that moment
#post_save.connect(post_save_session_reciever,sender=UserSession)


#def post_save_user_changed_reciever(sender,instance,created,*args,**kwargs):
 #   if not created:
  #      if instance.is_active == False:
   #         qs=UserSession.objects.filter(user=instance.user,ended=False,active=False)
    #        for i in qs:
     #           i.end_session()
#post_save.connect(post_save_user_changed_reciever,sender=User)

def user_logged_in_reciever(sender,instance,request,*args,**kwargs):
    user=instance
    ip_address=get_client_ip(request)
    session_key=request.session.session_key
    UserSession.objects.create(
        user=user,
        ip_address=ip_address,
        session_key=session_key

    )
user_logged_in.connect(user_logged_in_reciever)