Example #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)
Example #2
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)