本文整理汇总了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)
示例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)
示例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/')
示例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'})
示例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
示例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
示例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))
示例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)
示例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
示例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()
示例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
示例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'})
示例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")
示例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
示例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})