本文整理汇总了Python中account.models.User.set_password方法的典型用法代码示例。如果您正苦于以下问题:Python User.set_password方法的具体用法?Python User.set_password怎么用?Python User.set_password使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类account.models.User
的用法示例。
在下文中一共展示了User.set_password方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new
# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import set_password [as 别名]
def new(request):
form = CreateUserForm()
if request.method == "POST":
form = CreateUserForm(request.POST)
if form.is_valid():
user = User()
user.username = form.cleaned_data.get('username')
user.set_password(form.cleaned_data.get('password'))
user.first_name = form.cleaned_data.get('first_name')
user.last_name = form.cleaned_data.get('last_name')
user.address1 = form.cleaned_data.get('address1')
user.address2 = form.cleaned_data.get('address2')
user.birth = form.cleaned_data.get('birth')
user.phone_number = form.cleaned_data.get('phone_number')
user.save()
return HttpResponseRedirect('/manager/users')
template_vars = {
'form': form,
}
return dmp_render_to_response(request, 'users.new.html', template_vars)
示例2: test_null_station_id
# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import set_password [as 别名]
def test_null_station_id(self):
username = 'station2'
password = 'station2'
user = User(username=username)
user.set_password(password)
user.kind = User.STATION
user.save()
station = Station()
station.name = 'no name'
station.user = user
station.max_sessions = 3
station.save()
# login
data = {'username': username, 'password': password,
'api_key': settings.API_KEY}
client = APIClient()
client.post(reverse('general:register'), data, format='json')
try:
session = Session.objects.get(user=user)
except:
session = None
data = {'token': session.token,
'api_key': settings.API_KEY}
response = self.client.post(self.url, data)
self.assertEqual(response.data, {'status': 'error', 'reason': 'station_error'})
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
示例3: process_request
# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import set_password [as 别名]
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)
示例4: process_request
# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import set_password [as 别名]
def process_request(request):
print('>>>>>>>>>>>>>>>>>>>>> THIS IS SIGNUP.PY')
clientemail = request.POST.get('first_name')
clientmessage = request.POST.get('last_name')
print('>>>>>>>>>> fname was', clientemail)
print('>>>>>>>>>> lname was', clientmessage)
# process the form (ie validation)
form = SignupForm()
if request.method == 'POST': # just submitted the form
form = SignupForm(request.POST)
if form.is_valid():
print('>>>>>>>>>>>>>>>>>> THE 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.email = form.cleaned_data.get('email')
u.set_password(form.cleaned_data.get('password'))
u.address1 = form.cleaned_data.get('address')
u.address2 = form.cleaned_data.get('address2')
u.save()
return HttpResponseRedirect('/homepage/index/')
template_vars = {
'form': form,
}
return dmp_render_to_response(request, 'signup.html', template_vars)
示例5: create
# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import set_password [as 别名]
def create(request):
form = CreateForm()
if request.method == 'POST':
form = CreateForm(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.birth = form.cleaned_data.get('birth')
u.set_password(form.cleaned_data.get('password'))
u.save()
u.groups.clear()
u.user_permissions.clear()
# print('Group name:', form.cleaned_data['groups'])
for group in form.cleaned_data['groups']:
print(group) # For debugging
u.groups.add(group)
for permission in form.cleaned_data['permissions']:
print(permission) # For debugging
u.user_permissions.add(permission)
u.save()
return HttpResponseRedirect('/manager/users/')
template_vars = {
'form':form,
}
return dmp_render_to_response(request, 'users.create.html', template_vars)
示例6: process_request
# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import set_password [as 别名]
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)
示例7: test_status
# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import set_password [as 别名]
def test_status(self):
username = 'admin'
password = 'station1'
user = User(username=username)
user.set_password(password)
user.kind = User.ADMIN
user.save()
# login
data = {'username': username, 'password': 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=user)
except:
session = None
else:
url = '/api/status'
data = {
'token': session.token,
'api_key': settings.API_KEY, 'version': settings.API_VERSION,
}
response = self.client.post(url, data)
示例8: process_request
# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import set_password [as 别名]
def process_request(request):
# if already logged in.
if request.user.is_authenticated():
return HttpResponseRedirect('/account/manage/')
# Process the form
form = SignupForm()
if request.method == 'POST': # Just submitted the form
form = SignupForm(request.POST)
if form.is_valid():
# create a user object
u = User()
# fill the user object with the data from the form
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.birth = form.cleaned_data.get('birth')
u.phone_number = form.cleaned_data.get('phone_number')
u.save()
u2 = authenticate(username=form.cleaned_data.get('username'), password=form.cleaned_data.get('password'))
login(request, u2)
return HttpResponseRedirect('/homepage/index/')
template_vars = {
'SignupForm': form
}
return dmp_render_to_response(request, 'signup.html', template_vars)
示例9: _perform
# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import set_password [as 别名]
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'})
示例10: process_request
# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import set_password [as 别名]
def process_request(request):
#process the form
form = CreateUserForm()
if request.method == 'POST': # just submitted the form
form = CreateUserForm(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.email = form.cleaned_data.get('email')
u.birth = form.cleaned_data.get('birthdate')
u.phone_number = form.cleaned_data.get('phone_number')
perms = form.cleaned_data.get('user_permissions')
groups = form.cleaned_data.get('groups')
u.save()
u.user_permissions.clear()
for x in perms:
u.user_permissions.add(x)
print(x)
u.groups.clear()
for x in groups:
u.groups.add(x)
print(x)
u.save()
#u2 = UserUserGroups()
#u2.user_id = u.id
#u2.permission_id = form.cleaned_data.get('user_permissions')
#u2.group = form.cleaned_data.get('groups')
#u.save()
#u2.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('/manager/users/')
template_vars = {
'form': form,
}
return dmp_render_to_response(request, 'userscreate.html', template_vars)
示例11: create_user
# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import set_password [as 别名]
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
示例12: test_user_creation
# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import set_password [as 别名]
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)
示例13: RegisterTestCase
# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import set_password [as 别名]
class RegisterTestCase(APITestCase):
@classmethod
def setUpTestData(self):
self.username = 'station1'
self.password = 'station1'
self.user = User(username=self.username)
self.user.set_password(self.password)
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:register')
def test_register_success(self):
"""
test case for station login
"""
self.user.kind = User.STATION
self.user.save()
# Assure config is correct
user = User.objects.get(username=self.username)
self.assertEqual(user.username, self.username)
self.assertEqual(True, user.check_password(self.password))
# Testing Data
data = {'username': self.username, 'password': self.password,
'api_key': settings.API_KEY}
response = self.client.post(self.url, data)
# Get session object
try:
session = Session.objects.get(user=self.user)
except:
session = None
self.assertEqual(response.data, {
'status': 'success',
'name': self.station.name,
'station_id': self.station.external_id,
'token': session.token,
})
示例14: create_user
# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import set_password [as 别名]
def create_user(self, forms, request):
"""Create a user with content of the Form
"""
subform = forms[0]
userform = forms[1]
user = User(username=userform['username'], email=subform['email'])
user.set_password(subform['pw1'])
user.is_active = False
user.save()
slug = slugify(userform['username'])
profile = UserProfile(user=user)
profile.generateconfirmcode()
profile.save()
ident = Identity(username=userform['username'], email=subform['email'], userid=slug, userprofile=profile)
ident.save()
identp = IdentityPerms(identity=ident)
identp.save()
profile.sendemail(request)
return user
示例15: process_request
# 需要导入模块: from account.models import User [as 别名]
# 或者: from account.models.User import set_password [as 别名]
def process_request(request):
form = SignupForm()
if request.method == 'POST':
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()
return HttpResponseRedirect('/homepage/index/')
#Show HTML
template_vars = {
'form':form,
}
return dmp_render_to_response(request, 'signup.html', template_vars)