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


Python models.UserProfile类代码示例

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


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


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