当前位置: 首页>>代码示例>>Python>>正文


Python User.set_password方法代码示例

本文整理汇总了Python中user.models.User.set_password方法的典型用法代码示例。如果您正苦于以下问题:Python User.set_password方法的具体用法?Python User.set_password怎么用?Python User.set_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在user.models.User的用法示例。


在下文中一共展示了User.set_password方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import set_password [as 别名]
    def handle(self, *args, **options):
        file_name = args[0]
        f = open(file_name, "rb")
        d = csv.DictReader(f)
        for row in d:
            username = row["username"]

            if User.objects.filter(username=username).exists():
                print "User %s exists." % (username)
            else:
                first_name = row.get("first_name", "")
                last_name = row.get("last_name", "")
                email = row.get("email", "")
                locality = row.get("locality", "")
                gender = row.get("gender", "")
                password = row.get("password", "")

                user = User(username=username, email=email, first_name=first_name, last_name=last_name)

                user.set_password(password)
                user.save()

                user.profile.gender = gender
                try:
                    user.profile.locality = Entity.objects.get(id=locality)
                except ObjectDoesNotExist:
                    print "user %s locality id %s does not exist" % (username, locality)
                user.profile.save()
开发者ID:hasadna,项目名称:open-shot,代码行数:30,代码来源:add_users.py

示例2: attempt_login

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import set_password [as 别名]
def attempt_login(request):
    matches = authenticate_users(request.POST['email'], request.POST['password'])

    if len(matches) == 1:
        # Exactly one match, cool, just authenticate the user
        user = authenticate(user=matches[0])
        log_user_in(request, user)
        return matches, None

    elif len(matches) > 1:
        # Multiple matches, let the caller handle this
        return matches, None

    elif len(matches) == 0:
        # Incorrect credentials. Check if this is a user from the old userpage system
        old_member = authenticate_sherpa2_user(request.POST['email'], request.POST['password'])
        if old_member is not None:
            # Actually, it is! Let's try to import them.
            if User.get_users().filter(memberid=old_member.memberid, is_inactive=False).exists():
                return matches, 'old_memberid_but_memberid_exists'

            # Check if a pending user exists. This shouldn't ever happen (a pending user is recently
            # enrolled, and an existing user will have been member for a long time).
            if User.objects.filter(memberid=old_member.memberid, is_pending=True).exists():
                # Give the same error ("user exists, you need to use your new password")
                return matches, 'old_memberid_but_memberid_exists'

            # Verify that they exist in the membersystem (this turned out to be an incorrect assumption)
            if not Actor.get_personal_members().filter(memberid=old_member.memberid).exists():
                # We're not quite sure why this can happen, so we'll just give them the invalid
                # credentials message - but this might be confusing for those who were able to log
                # in previously.
                return matches, 'invalid_credentials'

            # Create the new user
            try:
                # Check if the user's already created as inactive
                user = User.get_users().get(memberid=old_member.memberid, is_inactive=True)
                user.is_inactive = False
                user.set_password(request.POST['password'])
                user.save()
            except User.DoesNotExist:
                # New user
                user = User(identifier=old_member.memberid, memberid=old_member.memberid)
                user.set_password(request.POST['password'])
                user.save()

            # Update the email on this actor, in case it were to differ from the sherpa2 email
            user.update_personal_data({'email': request.POST['email']})

            # Import any fjelltreffen-annonser from the old system
            import_fjelltreffen_annonser(user)

            authenticate(user=user)
            log_user_in(request, user)
            return [user], None

        else:
            # No luck, just provide the error message
            return matches, 'invalid_credentials'
开发者ID:simensma,项目名称:sherpa,代码行数:62,代码来源:util.py

示例3: attempt_registration_nonmember

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import set_password [as 别名]
def attempt_registration_nonmember(request):
    error_messages = []

    # Check that name is provided
    if not validator.name(request.POST['name']):
        error_messages.append('invalid_name')

    # Check that the email address is valid
    if not validator.email(request.POST['email']):
        error_messages.append('invalid_email')

    # Check that the email address isn't in use
    if User.objects.filter(identifier=request.POST['email']).exists():
        error_messages.append('email_exists')

    # Check that the password is long enough
    if len(request.POST['password']) < settings.USER_PASSWORD_LENGTH:
        error_messages.append('too_short_password')

    if len(error_messages) > 0:
        request.session['user.registration_nonmember_attempt'] = {
            'name': request.POST['name'],
            'email': request.POST['email']
        }
        return None, error_messages

    user = User(identifier=request.POST['email'], email=request.POST['email'])
    user.first_name, user.last_name = request.POST['name'].rsplit(maxsplit=1)
    user.set_consent_accepted_privacy_policy_date(None, False)
    user.set_password(request.POST['password'])
    user.save()
    user.set_consent_dnt(
        Forening.DNT_CENTRAL_ID,
        'email',
        True if request.POST.get('consent-dnt-communication-email') else False,
        save=True,
    )
    authenticate(user=user)
    log_user_in(request, user)

    try:
        message = render_to_string('common/user/login/registered_nonmember_email.txt', request=request)
        send_mail(EMAIL_REGISTERED_SUBJECT, message, settings.DEFAULT_FROM_EMAIL, [user.get_email()])
    except (SMTPException, SSLError, UnicodeEncodeError):
        # Silently log and ignore this error. Consider warning the user that the email wasn't sent?
        logger.warning(
            "Klarte ikke å sende registreringskvitteringepost",
            exc_info=sys.exc_info(),
            extra={'request': request}
        )

    return user, None
开发者ID:Turistforeningen,项目名称:sherpa,代码行数:54,代码来源:util.py

示例4: create_user

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import set_password [as 别名]
    def create_user(self, form, commit=True, **kwargs):
        email = form.cleaned_data['email']
        try:
            user = User.objects.get(email__iexact=email)
        except User.DoesNotExist:
            user = User()
            user.username = email
            user.email = email

        user.set_password(User.objects.make_random_password(getattr(settings, 'ACCOUNT_RANDOM_PASSWD_LENGTH', 10)))
        user.save()

        return user
开发者ID:CharlesCliff,项目名称:dannysite.com,代码行数:15,代码来源:views.py

示例5: create_user

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import set_password [as 别名]
    def create_user(self, form, commit=True, **kwargs):
        email = form.cleaned_data['email']
        try:
            user = User.objects.get(email__iexact=email)
        except User.DoesNotExist:
            user = User()
            user.username = email
            user.email = email

        user.set_password(User.objects.make_random_password())
        user.save()

        return user
开发者ID:RyanLyu,项目名称:dannysite.com,代码行数:15,代码来源:views.py

示例6: createuser

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import set_password [as 别名]
def createuser():
    import getpass
    from user.models import User

    db = Session()
    while True:
        name = raw_input('username:')
        if db.query(User).filter(User.username == name).count():
            print 'user exists'
        else:
            break
    pwd = getpass.getpass('password:')
    user = User(username=name)
    user.set_password(pwd)
    db.add(user)
    db.commit()
开发者ID:lodevil,项目名称:pyrinet,代码行数:18,代码来源:manage.py

示例7: attempt_registration_nonmember

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import set_password [as 别名]
def attempt_registration_nonmember(request):
    error_messages = []

    # Check that name is provided
    if not validator.name(request.POST['name']):
        error_messages.append('invalid_name')

    # Check that the email address is valid
    if not validator.email(request.POST['email']):
        error_messages.append('invalid_email')

    # Check that the email address isn't in use
    if User.objects.filter(identifier=request.POST['email']).exists():
        error_messages.append('email_exists')

    # Check that the password is long enough
    if len(request.POST['password']) < settings.USER_PASSWORD_LENGTH:
        error_messages.append('too_short_password')

    if len(error_messages) > 0:
        request.session['user.registration_nonmember_attempt'] = {
            'name': request.POST['name'],
            'email': request.POST['email']
        }
        return None, error_messages

    user = User(identifier=request.POST['email'], email=request.POST['email'])
    user.first_name, user.last_name = request.POST['name'].rsplit(' ', 1)
    user.set_password(request.POST['password'])
    user.save()
    authenticate(user=user)
    log_user_in(request, user)

    try:
        t = loader.get_template('common/user/login/registered_nonmember_email.txt')
        c = RequestContext(request)
        send_mail(EMAIL_REGISTERED_SUBJECT, t.render(c), settings.DEFAULT_FROM_EMAIL, [user.get_email()])
    except (SMTPException, SSLError):
        # Silently log and ignore this error. Consider warning the user that the email wasn't sent?
        logger.warning(u"Klarte ikke å sende registreringskvitteringepost",
            exc_info=sys.exc_info(),
            extra={'request': request}
        )

    return user, None
开发者ID:simensma,项目名称:sherpa,代码行数:47,代码来源:util.py

示例8: handle

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import set_password [as 别名]
    def handle(self, *args, **options):
        file_name = args[0]
        f = open(file_name, 'rb')
        d = csv.DictReader(f)
        i = 1
        for row in d:
            ordinal = int(row['ordinal'])
            locality_name = row['locality']
            ballot = row['ballot']
            mayor = bool(row['mayor'])
            
            fullname = row['name']

            locality = Entity.objects.filter(division__index=3).get(name_he=locality_name)
            candidatelist = locality.candidatelist_set.get(ballot=ballot)

            last_name, first_name = fullname.split(' ', 1)
            username = u'c_%04d' % i

            user = User(
                username=username,
                first_name=first_name,
                last_name=last_name,
            )

            password = random.randint(1,99999)
            s = u'%s, %s, %s, %s, %s' % (locality_name, first_name, last_name, username, password)
            print s.encode('utf-8')
            user.set_password(password)
            user.save()

            user.profile.locality = locality
            user.profile.verification = u'V'

            user.profile.save()

            candidate = Candidate(candidate_list=candidatelist, user=user,
                            ordinal=ordinal, for_mayor=mayor)
            candidate.save()

            i += 1
开发者ID:RobotnickIsrael,项目名称:open-shot,代码行数:43,代码来源:add_candidates.py

示例9: _create_users

# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import set_password [as 别名]
    def _create_users(self):
        default_admin = User(
                first_name = 'admin',
                last_name = 'admin',
                username = 'admin',
                birthday = timezone.now(),
                telephone = 123456789,
                emergency_contact = 119,
                email = '[email protected]',
                occupation = 'ADMIN',
                is_admin = True
            )
        default_admin.set_password('pass1234')
        default_admin.save()

        icondir = os.path.join(settings.BASE_DIR, 'media', 'users', 'seed_icons')

        #デモで使うユーザー
        testuser = User(
                first_name = 'インター',
                last_name = 'リンク',
                username = 'ページ531',
                birthday = timezone.now() - timezone.timedelta(days=10000),
                telephone = 123456789,
                emergency_contact = 119,
                email = '[email protected]',
                occupation = '会社員',
                region="Tokyo",
            )
        testuser.set_password('pass1234')
        testuser.save()

        #ちゃんとしたユーザー
        for i in range(20):
            lastname = str(i)
            username = username_sample[i]
            email = "test%[email protected]" %(i+1)
            user = User(
                first_name = 'user',
                last_name = lastname,
                username = username,
                birthday = timezone.now() - timezone.timedelta(days=6000+i*600),
                telephone = 123456789,
                emergency_contact = 119,
                email = email,
                occupation = ['会社員','プログラマー','デザイナー'][i%3],
                region = self.prefec_list[i],
            )
            user.set_password('pass1234')
            user.save()

        #モブキャラ
        for i in range(1,30):
            firstname = 'demo_user'
            lastname = str(i)
            username = 'demo_user_'+str(i)
            email = "demo%[email protected]"%i
            role_type = 'helper' if i > 20 else 'sufferer'
            user = User(
                first_name=firstname,
                last_name=lastname,
                username=username,
                birthday=timezone.now() - timezone.timedelta(days=6000+i*600),
                telephone=123456789,
                emergency_contact=119,
                email=email,
                occupation='BUG_TEST',
                region=self.prefec_list[i%47],
                role = role_type,
            )
            user.set_password('pass1234')
            user.save()
开发者ID:internship2016,项目名称:sovolo,代码行数:74,代码来源:seed_data.py


注:本文中的user.models.User.set_password方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。