當前位置: 首頁>>代碼示例>>Python>>正文


Python models.User類代碼示例

本文整理匯總了Python中account.models.User的典型用法代碼示例。如果您正苦於以下問題:Python User類的具體用法?Python User怎麽用?Python User使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了User類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: process_request

def process_request(request):
  
  #process the form
  form = SignupForm()
  if request.method == 'POST':  # just submitted the form
    form = SignupForm(request.POST)
    if form.is_valid():
      u = User()
      u.username = form.cleaned_data.get('username')
      u.first_name = form.cleaned_data.get('first_name')
      u.last_name = form.cleaned_data.get('last_name')
      u.address1 = form.cleaned_data.get('address1')
      u.address2 = form.cleaned_data.get('address2')
      u.set_password(form.cleaned_data.get('password'))
      u.save()
      # authenticate(username=form.cleaned_data.get('username'),password=form.cleaned_data.get('password'))
      # login(request, form.user)    
      # create a user object
      # fill the user object with the data from the form
      return HttpResponseRedirect('/homepage/index/')
      
  template_vars = {
    'form': form,
  }
  return dmp_render_to_response(request, 'signup.html', template_vars)
開發者ID:trev91,項目名稱:CHF,代碼行數:25,代碼來源:signup.py

示例2: process_request

def process_request(request):

    form = CreateAccountForm()
    if request.method == "POST":
        form = CreateAccountForm(request.POST)
        if form.is_valid():
            # create the user here
            u = User()
            u.username = form.cleaned_data.get("username")
            u.first_name = form.cleaned_data.get("first_name")
            u.last_name = form.cleaned_data.get("last_name")
            u.BirthDate = form.cleaned_data.get("BirthDate")
            u.Phone = form.cleaned_data.get("Phone")
            u.set_password(form.cleaned_data.get("password"))

            u.save()

            return HttpResponse(
                """
            <script>
                window.location.href = '/homepage/index/';
            </script>
          """
            )

    template_vars = {"form": form}

    return dmp_render_to_response(request, "createaccount.html", template_vars)
開發者ID:jdkoelliker,項目名稱:CHFSite,代碼行數:28,代碼來源:createaccount.py

示例3: create_account

def create_account(request):
    c = {}
    c.update(csrf(request))
    is_signed_in = request.user.is_authenticated()
    is_admin = request.user.is_superuser
    matched = False
    if request.method == 'POST':
        match = models.User.objects.filter(username=request.POST['usr'])
        if len(match) > 0:
            matched = True
            return render(request,'sign-up.html',{'signed_in': is_signed_in,'admin':is_admin, 'guest': not is_signed_in,'matched':matched})
        else:
            djuser = models.User.objects.create_user(username = request.POST['usr'],
                                                     email = request.POST['mail'],
                                                     password= request.POST['pass'],
                                                     )
            djuser.first_name = request.POST['name'],
            djuser.last_name = request.POST['lastname'],
            user = User( address = request.POST['addr'],
                         phone_num = request.POST['tel'],
                         gender = request.POST['gender'],
                         avatar = None,
                         userType = 'Normal',
                         )
            user.user = djuser
            djuser.save()
            user.save()
        is_signed_in = request.user.is_authenticated()
        is_admin = request.user.is_superuser
        return redirect('/main/')
開發者ID:hvdharya,項目名稱:SysRaVi,代碼行數:30,代碼來源:views.py

示例4: _perform

 def _perform(self, username, password):
     session = self._app.db.session()
     user = session.query(User).filter_by(username=username).first()
     if user is None:
         new_user = User(username=username)
         new_user.set_password(password)
         session.add(new_user)
         return BusinessResponse.response_ok({})
     else:
         return BusinessResponse.response_invalid_data({'message': 'User with this name already exists'})
開發者ID:qrees,項目名稱:tornado-chat,代碼行數:10,代碼來源:business_logic.py

示例5: save

 def save (self):
     user = User(username=self.cleaned_data['username'],
             email=self.cleaned_data['email'],
             is_staff=self.cleaned_data['is_staff'],
             is_active=self.cleaned_data['is_active'],
             is_superuser=self.cleaned_data['is_superuser'],
             )
     user.save()
     for g in self.cleaned_data['groups']:
         user.groups.add(g)
     for p in self.cleaned_data['user_permissions']:
         user.user_permissions.add(p)
     return user
開發者ID:Czlyc,項目名稱:ylinux,代碼行數:13,代碼來源:forms.py

示例6: create_user

def create_user(name, password, email, 
                phone_number, phone_activation_code, 
                email_activation_key):
    obj = User(
        name=name,
        password=password,
        email=email,
        phone_number=phone_number,
        phone_activation_code=phone_activation_code,
        email_activation_key=email_activation_key
    )
    # Encrypts the password.
    obj.set_password(password)
    return obj
開發者ID:guptauddhav,項目名稱:fourmetro,代碼行數:14,代碼來源:utils.py

示例7: register

def register(request):
    if request.method == "POST":
        uf = UserForm(request.POST)
        if uf.is_valid():
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            user = User()
            user.username = username
            user.password = password
            user.save()
            return render_to_response('success.html',{'username':username}, context_instance = RequestContext(request))
    else:
        uf = UserForm()
        return render_to_response('register.html', {'uf' : uf}, context_instance = RequestContext(request))
開發者ID:yfjelley,項目名稱:cqt,代碼行數:14,代碼來源:views.py

示例8: test_user_creation

 def test_user_creation(self):
     """
     Create user
     """
     u = User(username=self.user_username, email=self.user_email)
     u.set_password(self.user_password)
     u.save()
     self.assertIsNotNone(u.id)
     self.assertTrue(User.objects.filter(
         username=self.user_username).exists())
     self.assertEqual(User.objects.get(
         username=self.user_username).email, self.user_email)
     self.assertTrue(User.objects.get(username=self.user_username).is_active)
     self.assertIsNotNone(User.objects.get(
         username=self.user_username).created_at)
開發者ID:pombredanne,項目名稱:snippit,代碼行數:15,代碼來源:test_models.py

示例9: create_from_sha

    def create_from_sha(project, new_rev, create=True):
        from account.models import User

        new_rev_commit = project.git.commit(new_rev)

        # Extract the project tree and diffs
        parents = [p for p in new_rev_commit.parents]

        # Extract formatted author details
        new_author = new_rev_commit.author
        author_info = User.from_commit(new_author, project)
        author, author_name, author_email = author_info

        # Extract formatted committer details
        new_committer = new_rev_commit.committer
        committer_info = User.from_commit(new_committer, project)
        committer, committer_name, committer_email = committer_info

        fts = datetime.datetime.utcfromtimestamp
        utc = pytz.timezone("UTC")

        author_time = new_rev_commit.author_time
        author_time = utc.localize(fts(author_time))

        commit_time = new_rev_commit.commit_time
        commit_time = utc.localize(fts(commit_time))

        # The actual Commit object is fairly heavy
        c = Commit(
            commit_time=commit_time,
            sha1sum=new_rev_commit.sha().hexdigest(),
            author=author,
            author_name=author_name,
            author_email=author_email,
            author_time=author_time,
            committer=committer,
            committer_name=committer_name,
            committer_email=committer_email,
            message=new_rev_commit.message,
            diff=[],
            tree=[],
            parents=parents,
            project=project,
        )

        if create:
            c.save()
        return c
開發者ID:justinvh,項目名稱:llab,代碼行數:48,代碼來源:models.py

示例10: setUpTestData

    def setUpTestData(self):
        self.student_id = 'B03705024'

        self.username = 'station1'
        self.password = 'station1'
        self.user = User(username=self.username)
        self.user.set_password(self.password)
        self.user.kind = User.STATION
        self.user.save()

        self.name = 'NTU'
        self.station = Station()
        self.station.name = self.name
        self.station.user = self.user
        self.station.external_id = 1
        self.station.max_sessions = 3
        self.station.save()

        # login
        data = {'username': self.username, 'password': self.password,
                'api_key': settings.API_KEY, 'version': settings.API_VERSION}
        client = APIClient()
        client.post(reverse('register'), data, format='json')

        try:
            session = Session.objects.get(user=self.user)
        except:
            session = None
        self.session = session
        self.token = session.token

        self.authcode = AuthCode(kind='70', code='70-ZU2U0RAKX-KOXLUYHJI-7C05B')
        self.authcode.save()
開發者ID:azdkj532,項目名稱:ntu-vote-auth-server,代碼行數:33,代碼來源:test.py

示例11: setUpTestData

    def setUpTestData(self):
        self.username = 'station1'
        self.password = 'station1'
        self.user = User(username=self.username)
        self.user.set_password(self.password)
        self.user.kind = User.STATION
        self.user.save()

        self.name = 'NTU'
        self.station = Station()
        self.station.name = self.name
        self.station.user = self.user
        self.station.external_id = 1
        self.station.max_sessions = 3
        self.station.save()

        self.url = reverse('general:ping')
        # login
        data = {'username': self.username, 'password': self.password,
                'api_key': settings.API_KEY}
        client = APIClient()
        client.post(reverse('general:register'), data, format='json')

        try:
            session = Session.objects.get(user=self.user)
        except:
            session = None
        self.session = session
        self.token = session.token
開發者ID:NTUOSC,項目名稱:ntu-vote-auth-server,代碼行數:29,代碼來源:test.py

示例12: __call__

 def __call__ (self, *args, **kwargs):
   request = args[0]
   request.json = json.loads(request.body)
   
   if 'token' in request.json:
     session = User.get_session(request.json['token'])
     
     user = None
     try:
       user_id = session[SESSION_KEY]
       backend_path = session[BACKEND_SESSION_KEY]
       
     except KeyError:
       pass
       
     else:
       if backend_path in settings.AUTHENTICATION_BACKENDS:
         backend = load_backend(backend_path)
         user = backend.get_user(user_id)
         
     if user:
       request.user = user
       return self.target(*args, **kwargs)
       
   return http.JsonResponse({'status': 'login-required'})
   
開發者ID:TheSpellBook,項目名稱:Super-Neutron-Drive,代碼行數:25,代碼來源:auth.py

示例13: post

    def post(self):
        oldpwd = self.request.get("oldpwd")
        pwd = self.request.get("pwd")

        result, info = User.update_pwd(self.user.email, oldpwd, pwd)
        self.template_value["pwd_error"] = info
        self.render("setting.html")
開發者ID:benmao,項目名稱:xfox,代碼行數:7,代碼來源:views.py

示例14: gets_info

 def gets_info(cls, engagements, userinfo='tar_user'):
     from account.models import User
     if userinfo == 'tar_user':
         uids = [e.tar_uid for e in engagements]
     else:
         uids = [e.req_uid for e in engagements]
     users = User.gets(uids)
     id_users = dict([(user.id, user) for user in users])
     infos = []
     for e in engagements:
         info = dict(
             id=e.id,
             tar_uid=e.tar_uid,
             req_uid=e.req_uid,
             status=e.status,
             price=e.price,
             date=e.date.strftime('%B %d,%Y'),
             note=e.note,
             contact=e.contact,
             create_time=e.create_time.strftime('%B %d,%Y %H:%M:%S'),
         )
         if userinfo == 'tar_user':
             info.update({'user': id_users.get(e.tar_uid).get_simple_info()})
         else:
             info.update({'user': id_users.get(e.req_uid).get_simple_info()})
         infos.append(info)
     return infos
開發者ID:wakenmeng,項目名稱:bink_eat,代碼行數:27,代碼來源:engagement.py

示例15: register2

def register2(request):
    print("hhhhhhhhh====")
    if request.method == "POST":
        uf = UserForm(request.POST)
        if uf.is_valid():
            #獲取表單信息
			
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            phone = uf.cleaned_data['phone']
            email = uf.cleaned_data['email']
            #將表單寫入數據庫
            print('1111======')
            user = User()
            user.username = username
            user.password = password
            user.phone = phone
            user.email = email
            user.save()
            print('save======')
            #返回注冊成功頁麵
            return render(request, 'success.html', {'username':username})
    else:
        uf = UserForm()
        return render(request, 'register.html', {'uf':uf})
開發者ID:xinxiang16,項目名稱:website,代碼行數:25,代碼來源:views.py


注:本文中的account.models.User類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。