• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.UserProfile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中users.models.UserProfile的典型用法代码示例。如果您正苦于以下问题:Python UserProfile类的具体用法?Python UserProfile怎么用?Python UserProfile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: newUserProfile

 def newUserProfile(self):
     """
         This method or function creates the new user along with the profile
         that is initially disabled, returns the number of the Franchisee
         which referenced where applicable.
     """
     # when the user registers with Code
     if self._validFranchiseeCode['flag'] == True and self._validFranchiseeCode['id'] >0:
         
         franchisee = UserProfile.objects.get(identification=self._validFranchiseeCode['id'])
         
         newProfile = UserProfile(
                     identification=self._user, activationKey=self._activationKey,
                     keyExpires=self._keyExpires, refFranchiseeCode=self._franchiseeCode,
                     refFranchisee=franchisee)
         #update Code in list for user; assigning values ​​necessary to use the code and date of use
         CreateCodes.objects.filter(code=self._data['franchiseeCode']).update(useFlagCode=True, dateUseFlag=datetime.datetime.now())
         
     # when the user is logged without Code
     else:
         newProfile = UserProfile(
                     identification=self._user, activationKey=self._activationKey,
                     keyExpires=self._keyExpires, refFranchiseeCode=None)
     
     # Save the profile
     newProfile.save()
开发者ID:alejo8591,项目名称:etv,代码行数:26,代码来源:UserRegistration.py


示例2: register

def register(request):

	if request.method == 'GET':
		form = UserForm()
		greeting = 'Please register an account'

		context = {
			'form': form,
			'greeting': greeting
		}
		
		return render(request, 'users/register.html', context)

	else:
		form = UserForm(request.POST)
		
		if form.is_valid():
			user = User(username=form.cleaned_data['username'],
				email=form.cleaned_data['email'], 
				first_name=form.cleaned_data['first_name'], 
				last_name=form.cleaned_data['last_name'])
			user.set_password(form.cleaned_data['password'])
			user.save()
			profile = UserProfile(user=user)
			profile.save()
			return redirect('/login/')
		else:
			context = {
				'form': form,
				'greeting': 'Invalid fields, please check errors.'
			}
			return render(request, 'users/register.html', context)
开发者ID:alexm118,项目名称:Django-Chat-App,代码行数:32,代码来源:views.py


示例3: create_user

def create_user(request):
    #If the user is trying to add info to the server,
    if request.method == 'POST':
        #Feed as arguments to RegisterForm the inputs from the user.
        create_user_form = RegisterForm(request.POST)
        #If username and password are of the right length and email is of the valid form,
        #And password and confirm password identical, 
        if create_user_form.is_valid():
            #Don't save the user in creation as a new user yet. 
            new_user = create_user_form.save()
            pw = create_user_form.cleaned_data.get('password')
            new_user.set_password( pw )
            new_user.save()
 
            #Then create UserProfile object from User object.
            new_UserProfile = UserProfile(user=new_user)
            #new_UserProfile.user = new_user
            new_UserProfile.save() #Then save. 
 
            #Render a Welcome to GroupFit page if the input info is valid. 
            #No need to customize welcome page unless we want to just switch the name: Welcome, username!
            return render(request, 'welcome.html')
 
            #Send an email as well.
    else:
        #If the user didn't plug in anything, create_user_form will be an empty shell?
        create_user_form = RegisterForm()
    return render(request, 'register.html', {'create_user_form': create_user_form})
开发者ID:clee15,项目名称:groupfit,代码行数:28,代码来源:views.py


示例4: test_is_publisher

 def test_is_publisher(self):
     c = Collection()
     u = UserProfile(nickname='f')
     c.save()
     u.save()
     CollectionUser(collection=c, user=u).save()
     eq_(c.is_publisher(u), True)
开发者ID:jaliste,项目名称:zamboni,代码行数:7,代码来源:test_models.py


示例5: add_edit_core

def add_edit_core(request,form="",id=0):
    """
    This function calls the AddCoreForm from forms.py
    If a new core is being created, a blank form is displayed and the super user can fill in necessary details.
    If an existing core's details is being edited, the same form is displayed populated with current core details for all fields

    """
    dajax = Dajax()
    if id:
        core_form = AddCoreForm(form, instance=User.objects.get(id=id))
        if core_form.is_valid():
            core_form.save()
            dajax.script("updateSummary();")
        else:
            template = loader.get_template('ajax/admin/editcore.html')
            html=template.render(RequestContext(request,locals()))
            dajax.assign(".bbq-item",'innerHTML',html)
    else:
        core_form = AddCoreForm(form)
        if core_form.is_valid():
            core=core_form.save()
            core.set_password("default")
            core.save()
            core_profile = UserProfile( user=core, is_core=True)
            core_profile.save()
            dajax.script("updateSummary();")
        else:
            template = loader.get_template('ajax/admin/addcore.html')
            html=template.render(RequestContext(request,locals()))
            dajax.assign(".bbq-item",'innerHTML',html)
    return dajax.json()
开发者ID:ShaastraWebops,项目名称:Shaastra-2013-Website,代码行数:31,代码来源:ajax.py


示例6: send_forget_password_email

def send_forget_password_email(request, user):
    username = user.username
    email = user.email
    salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
    activation_key = hashlib.sha1(salt+email).hexdigest()
    
    #Create and save user profile
    UserProfile.objects.filter(account=user).delete()
    new_profile = UserProfile(account=user, activation_key=activation_key)
    new_profile.save()

    # Send email with activation key
    profile_link = request.META['HTTP_HOST'] + \
        reverse('users:forget_password_confirm', kwargs={'activation_key': activation_key})
    email_subject = 'Password Reset'
    email_body = render_to_string('index/forget_password_email.html',
                    {'username': username, 'profile_link': profile_link,
                    'active_time': new_profile.active_time})
    msg = EmailMultiAlternatives(email_subject, email_body, settings.EMAIL_HOST_USER, [email])
    msg.attach_alternative(email_body, "text/html")

    try:
        Thread(target=msg.send, args=()).start()
    except:
        print ("There is an error when sending email to %s's mailbox" % username)
开发者ID:drowsy810301,项目名称:NTHUFC,代码行数:25,代码来源:views.py


示例7: send_activation_email

def send_activation_email(request, user):
    username = user.username
    email = user.email
    salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
    activation_key = hashlib.sha1(salt + email).hexdigest()

    # Create and save user profile
    new_profile = UserProfile(user=user, activation_key=activation_key)
    new_profile.save()

    # Send email with activation key
    activation_link = request.META['HTTP_HOST'] + \
        reverse('users:confirm', kwargs={'activation_key': activation_key})
    email_subject = 'Account confirmation'
    email_body = render_to_string('index/activation_email.html',
                    {'username': username, 'activation_link': activation_link,
                    'active_time': new_profile.active_time})

    msg = EmailMultiAlternatives(email_subject, email_body, EMAIL_HOST_USER, [email])
    msg.attach_alternative(email_body, "text/html")

    try:
        Thread(target=msg.send, args=()).start()
    except:
        logger.warning("There is an error when sending email to %s's mailbox" % username)
开发者ID:bbiiggppiigg,项目名称:NTHUOJ_web,代码行数:25,代码来源:user_info.py


示例8: test_users_list_truncate_display_name

def test_users_list_truncate_display_name():
    u = UserProfile(username='oscar',
                    display_name='Some Very Long Display Name', pk=1)
    truncated_list = users_list([u], None, 10)
    eq_(truncated_list,
        u'<a href="%s" title="%s">Some Very...</a>' % (u.get_url_path(),
                                                       u.name))
开发者ID:psyko0815,项目名称:olympia,代码行数:7,代码来源:test_helpers.py


示例9: test_is_subscribed

 def test_is_subscribed(self):
     c = Collection.objects.get(pk=512)
     u = UserProfile()
     u.nickname = "unique"
     u.save()
     c.subscriptions.create(user=u)
     assert c.is_subscribed(u), "User isn't subscribed to collection."
开发者ID:sgarrity,项目名称:zamboni,代码行数:7,代码来源:test_models.py


示例10: test_browserid_password

    def test_browserid_password(self):
        for source in amo.LOGIN_SOURCE_BROWSERIDS:
            u = UserProfile(password=self.utf, source=source)
            assert u.check_password('foo')

        u = UserProfile(password=self.utf, source=amo.LOGIN_SOURCE_UNKNOWN)
        assert not u.check_password('foo')
开发者ID:KKcorps,项目名称:zamboni,代码行数:7,代码来源:test_models.py


示例11: authenticate

    def authenticate(self, **kwargs):
        """Authenticate the user based on an OpenID response."""
        # Require that the OpenID response be passed in as a keyword
        # argument, to make sure we don't match the username/password
        # calling conventions of authenticate.

        openid_response = kwargs.get('openid_response')
        if openid_response is None:
            return None

        if openid_response.status != SUCCESS:
            return None

        user = None
        try:
            user_openid = UserOpenID.objects.get(
                claimed_id__exact=openid_response.identity_url)
            log.debug("Drupal openid user resgistered already: %s" % (openid_response.identity_url,))
            return None
        except UserOpenID.DoesNotExist:
            drupal_user = drupal.get_openid_user(openid_response.identity_url)
            if drupal_user:
                user_data = drupal.get_user_data(drupal_user)
                profile = UserProfile(**user_data)
                profile.save()
                if profile.user is None:
                    profile.create_django_user()
                self.associate_openid(profile.user, openid_response)
                return profile.user
开发者ID:Suggsgested,项目名称:lernanta,代码行数:29,代码来源:backends.py


示例12: register_post_fb

def register_post_fb(request):
    """
        This is the user registration view for fb
    """
    form = FacebookUserForm(request.POST)
    facebook_id = request.POST['facebook_id']
    access_token = request.POST['access_token']
    if form.is_valid():
        data = form.cleaned_data
        new_user = User(first_name = data['first_name'], last_name=data['last_name'], username= data['username'], email = data['email'])
        new_user.set_password('default')
        new_user.save()
        userprofile = UserProfile(
                user = new_user,
                gender     = data['gender'],
                age = data['age'],
                branch = data['branch'],
                mobile_number = data['mobile_number'],
                college = data['college'],
                college_roll = data['college_roll'],
                facebook_id = facebook_id,
                access_token = access_token,
                )
        userprofile.save()
        new_user = authenticate(username = data['username'], password = "default")
        auth_login(request, new_user)
        return HttpResponseRedirect(settings.SITE_URL)
    return render_to_response('users/register.html', locals(), context_instance = RequestContext(request))
开发者ID:ShaastraWebops,项目名称:Shaastra-2013-Website,代码行数:28,代码来源:views.py


示例13: test_persona_sha512_base64_maybe_not_latin1

 def test_persona_sha512_base64_maybe_not_latin1(self):
     passwd = u'fo\xf3'
     hsh = hashlib.sha512(self.bytes_ + passwd.encode('latin1')).hexdigest()
     u = UserProfile(password='sha512+base64$%s$%s' %
                     (encodestring(self.bytes_), hsh))
     assert u.check_password(self.utf) is False
     assert u.has_usable_password() is True
开发者ID:arpitnigam,项目名称:olympia,代码行数:7,代码来源:test_models.py


示例14: test_persona_sha512_md5_base64

 def test_persona_sha512_md5_base64(self):
     md5 = hashlib.md5('password').hexdigest()
     hsh = hashlib.sha512(self.bytes_ + md5).hexdigest()
     u = UserProfile(password='sha512+MD5+base64$%s$%s' %
                     (encodestring(self.bytes_), hsh))
     assert u.check_password('password') is True
     assert u.has_usable_password() is True
开发者ID:arpitnigam,项目名称:olympia,代码行数:7,代码来源:test_models.py


示例15: send_forget_password_email

def send_forget_password_email(request, user):
    username = user.username
    email = user.email
    salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
    activation_key = hashlib.sha1(salt + email).hexdigest()
    # Create and save user profile
    UserProfile.objects.filter(user=user).delete()
    new_profile = UserProfile(user=user, activation_key=activation_key)
    new_profile.save()

    # Send email with activation key
    profile_link = request.META["HTTP_HOST"] + reverse(
        "users:forget_password_confirm", kwargs={"activation_key": activation_key}
    )
    email_subject = "Password Reset"
    email_body = render_to_string(
        "index/forget_password_email.html",
        {"username": username, "profile_link": profile_link, "active_time": new_profile.active_time},
    )
    msg = EmailMultiAlternatives(email_subject, email_body, EMAIL_HOST_USER, [email])
    msg.attach_alternative(email_body, "text/html")

    try:
        Thread(target=msg.send, args=()).start()
    except:
        logger.warning("There is an error when sending email to %s's mailbox" % username)
开发者ID:jpdyuki,项目名称:NTHUOJ_web,代码行数:26,代码来源:user_info.py


示例16: post

 def post(self, request, *args, **kwargs):
     user_form = UserForm(request.POST)
     user_profile_form = SignUpProfileForm(request.POST)
     if user_form.is_valid() and user_profile_form.is_valid():
         user = user_form.save()
         user_profile = UserProfile(
             user = user,
             city = user_profile_form.data['city'],
             country = user_profile_form.data['country']
         )
         try:
             user_profile.save()
             user = authenticate(
                 username=user_form.data.get('username'),
                 password=user_form.data.get('password1')
             )
             login(self.request, user)
         except:
             transaction.rollback()
         return HttpResponseRedirect(self.success_url)
     else:
         context = {}
         context['user_form'] = user_form
         context['user_profile_form'] = user_profile_form
         context['cities'] = City.objects.all()
         context['countries'] = Country.objects.all()
         return self.render_to_response(context)
开发者ID:aeroheart-c6,项目名称:alab-server,代码行数:27,代码来源:views.py


示例17: view_profile

def view_profile(request, user_id, **kwargs):
	query_set = User.objects.filter(id=user_id)
	if not query_set.exists():
		return view_profile(request, request.user.id, error_messages=['User with user_id='+str(user_id)+' could not be found.'])
	user = query_set[0]

	profile = None
	query_set = UserProfile.objects.filter(user=user)
	if not query_set.exists():
		profile = UserProfile()
		profile.user = user
		profile.save()
	else:
		profile = query_set[0]

	context_dict = {}

	if int(user_id) == int(request.user.id):
		context_dict = {
			'user_form': EditUserForm(initial=model_to_dict(user)),
			'profile_form': UserProfileForm(initial=model_to_dict(profile)),
			'available_backends': load_backends(settings.AUTHENTICATION_BACKENDS),
			'editing': 'editing' in kwargs and kwargs['editing'] == 'editing',
		}
	context_dict['disp_user'] = user
	context_dict['disp_user_is_sm'] = (user.is_superuser) or (Permission.objects.get(codename='site_manager') in user.user_permissions.all()) #user.has_perm('users.site_manager')

	if 'error_messages' in kwargs:
		context_dict['error_messages'] = kwargs['error_messages']

	return render(request, 'profile.html', context_dict)
开发者ID:mas2tg,项目名称:cs3240-f16-team07,代码行数:31,代码来源:views.py


示例18: test_valid_old_password

 def test_valid_old_password(self):
     hsh = hashlib.md5('sekrit').hexdigest()
     u = UserProfile(password=hsh)
     assert u.check_password('sekrit') is True
     # Make sure we updated the old password.
     algo, salt, hsh = u.password.split('$')
     eq_(algo, 'sha512')
     eq_(hsh, get_hexdigest(algo, salt, 'sekrit'))
开发者ID:chowse,项目名称:zamboni,代码行数:8,代码来源:test_models.py


示例19: test_user_link_unicode

def test_user_link_unicode():
    """make sure helper won't choke on unicode input"""
    u = UserProfile(username=u'jmüller', display_name=u'Jürgen Müller', pk=1)
    eq_(user_link(u), u'<a href="%s">Jürgen Müller</a>' % u.get_url_path())

    u = UserProfile(username='\xe5\xaf\x92\xe6\x98\x9f', pk=1)
    eq_(user_link(u),
        u'<a href="%s">%s</a>' % (u.get_url_path(), u.username))
开发者ID:Dreadchild,项目名称:zamboni,代码行数:8,代码来源:test_helpers.py


示例20: test_user_link

def test_user_link():
    u = UserProfile(username='jconnor', display_name='John Connor', pk=1)
    eq_(user_link(u),
        '<a href="%s" title="%s">John Connor</a>' % (u.get_url_path(),
                                                     u.name))

    # handle None gracefully
    eq_(user_link(None), '')
开发者ID:psyko0815,项目名称:olympia,代码行数:8,代码来源:test_helpers.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python serializers.UserSerializer类代码示例发布时间:2022-05-27
下一篇:
Python models.UserNotification类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap