本文整理汇总了Python中mongoengine.django.auth.User.set_password方法的典型用法代码示例。如果您正苦于以下问题:Python User.set_password方法的具体用法?Python User.set_password怎么用?Python User.set_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongoengine.django.auth.User
的用法示例。
在下文中一共展示了User.set_password方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import set_password [as 别名]
def handle(self, **kwargs):
while True:
username = self._get_string('Username')
if User.objects(username=username).count() > 0:
print "That username is already in use"
continue
else:
break
while True:
email = self._get_string('Email', required=False)
if User.objects(email=email).count() > 0:
print "That email is already in use"
continue
else:
break
password = self._get_string('Password', getpass.getpass)
first_name = self._get_string('First name')
last_name = self._get_string('Last name')
u = User(username=username)
u.first_name = first_name
u.last_name = last_name
u.email = email
u.set_password(password)
u.is_staff = True
u.is_superuser = False
u.save()
print 'User "%s %s" successfully added' % (first_name, last_name)
示例2: index
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import set_password [as 别名]
def index(request):
firstname = "";
lastname = "";
username = "";
password = "";
email = "";
if request.method == 'GET':
return render(request, 'myapp/signup.html', {'rangerDay':range(1,32),'rangerYear':range(2014,1905,-1),})
elif request.method == 'POST':
firstname = request.POST['txtFirstName']
lastname = request.POST['txtLastName']
username = request.POST['txtUserName']
password = request.POST['txtPassWord']
email= request.POST['txtEmail']
try:
user = User()
user.username = username
user.first_name = firstname
user.last_name = lastname
user.email = email
user.set_password(password);
user.save()
_profile = UserProfile()
_profile.user_id = user
_profile.save()
user.backend = 'mongoengine.django.auth.MongoEngineBackend'
logout(request)
login(request, user)
return HttpResponseRedirect('/mainscreen')
except mongoengine.errors.NotUniqueError as e:
return getSignupError(request,'Đã tồn tại trong hệ thống',firstname,lastname,username,password,email)
示例3: index
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import set_password [as 别名]
def index(request):
message = None
#Login
if request.method == 'POST' and request.POST['name'] and request.POST['password']:
username = str(request.POST['name']).lower()
u = authenticate(username=username, password=request.POST['password'])
if u is None:
if request.POST.has_key('should_register'):
if len(User.objects(username=request.POST['name'])) == 0:
u = User(username=username)
u.set_password(request.POST['password'])
u.save()
auth_login(request, authenticate(username=username, password=request.POST['password']))
else:
message = 'Sorry, that username is taken :('
else:
message = 'Sorry, the name or password was wrong. Do you not have an account yet? Just fill out the form and check "New Account"'
else:
auth_login(request, u)
chat = Chat.objects.order_by('+time')
return render_to_response('chat/chat.html', {
'message': message,
'chat': chat[len(chat)-50:],
'user': request.user,
})
示例4: register
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import set_password [as 别名]
def register(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
User_save = User(username=username, password=password)
User_save.set_password(password)
User_save.save()
return render(request,'index.html')
else:
return render(request,'register.html')
示例5: signup
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import set_password [as 别名]
def signup(request):
firstname= request.POST.get('firstname', '')
lastname= request.POST.get('lastname', '')
username= request.POST.get('username', '')
password= request.POST.get('password', '')
email= request.POST.get('email', '')
user = User(first_name = firstname, last_name= lastname, username= username, password= password, email= email)
user.set_password(password)
user.save()
user.backend = 'mongoengine.django.auth.MongoEngineBackend'
request.session["user"] = user.username
request.session["admin"] = user.is_superuser
return JsonResponse({'status': 1, "msg": "SignUp OK"})
示例6: index
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import set_password [as 别名]
def index(request):
firstname = "";
lastname = "";
username = "";
password = "";
email = "";
if request.method == 'GET':
return render(request, 'myapp/signup.html', {'rangerDay':range(1,32),'rangerYear':range(2014,1905,-1),})
elif request.method == 'POST':
try:
#parameter
firstname = request.POST['txtFirstName']
lastname = request.POST['txtLastName']
username = request.POST['txtUserName']
password = request.POST['txtPassWord']
email= request.POST['txtEmail']
if str(firstname).strip() == "":
return getSignupError(request,'First name can not be empty!',firstname,lastname,username,password,email)
elif str(lastname).strip() == "":
return getSignupError(request,'Last name can not be empty!',firstname,lastname,username,password,email)
elif str(username).strip() == "":
return getSignupError(request,'User name can not be empty!',firstname,lastname,username,password,email)
elif str(password).strip() == "":
return getSignupError(request,'Pass word can not be empty!',firstname,lastname,username,password,email)
elif str(email).strip() == "":
return getSignupError(request,'Email can not be empty!',firstname,lastname,username,email)
#insert new user
user = User()
user.username = username
user.first_name = firstname
user.last_name = lastname
user.email = email
user.set_password(password);
user.save()
user.backend = 'mongoengine.django.auth.MongoEngineBackend'
logout(request)
login(request, user)
#create new profile
_profile = UserProfile()
_profile.user_id = request.user
_profile.save()
return HttpResponseRedirect('/home')
except mongoengine.errors.ValidationError as ex:
return getSignupError(request,str(ex.errors['email']),firstname,lastname,username,password,email)
except mongoengine.errors.NotUniqueError as e:
return getSignupError(request,'User has already exists!',firstname,lastname,username,password,email)
except Exception as e:
return getSignupError(request,str(e),firstname,lastname,username,password,email)
示例7: create_new_observer
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import set_password [as 别名]
def create_new_observer(self, email, name, surname, affiliation, password):
"""
Create a new, inactive ``Observer``, generates a
``profile`` and emails its activation key,
returning the new ``Observer``.
"""
new_observer = RegisteredObserver()
user = User()
user.email = email
user.username = email
user.is_active = False
new_observer.name = name
new_observer.surname = surname
user.name = name + surname
new_observer.affiliation = affiliation
user.set_password(password)
new_observer.set_password(password)
new_observer.approved = False
new_observer.registration_confirmed = False
sha1 = hashlib.sha1()
sha1.update(str(random.random()))
salt = sha1.hexdigest()[:5]
sha1 = hashlib.sha1()
sha1.update(salt.encode('ascii', 'ignore') + email.encode('ascii', 'ignore') + name.encode('ascii', 'ignore') + affiliation.encode('ascii', 'ignore'))
new_observer.activation_key = sha1.hexdigest()
user.save()
new_observer.user = user
new_observer.save()
from django.core.mail import send_mail
subject = "Registration activation request for NZDIS: Tobacco Free"
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
message = render_to_string('activation_email.txt',
{ 'activation_key': new_observer.activation_key,
'name': new_observer.name,
})
logger.debug("Trying to email this:\n" + message)
try:
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [new_observer.user.email])
except:
pass
# TODO what should we do if the email connection fails?
# should never happen on the server
return new_observer
示例8: handle
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import set_password [as 别名]
def handle(self, **kwargs):
username = self._get_string('Username')
email = self._get_string('Email', required=False)
password = self._get_string('Password', getpass.getpass)
first_name = self._get_string('First name')
last_name = self._get_string('Last name')
user = User(username=username)
user.first_name = first_name
user.last_name = last_name
user.email = email
user.set_password(password)
user.is_staff = True
user.save()
print 'User "%s %s" successfully added' % (first_name, last_name)
示例9: authenticate
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import set_password [as 别名]
def authenticate(self, username=None, password=None, domain=None):
base = settings.LDAP_BASE
scope = ldap.SCOPE_SUBTREE
filter = "(&(objectclass=person) (uid=%s))" % username
ret = ['dn']
try:
l = ldap.initialize(settings.LDAP_SERVER);
l.protocol_version = ldap.VERSION3
l.simple_bind_s()
except ldap.LDAPError:
return None
try:
result_id = l.search(base, scope, filter, ret)
result_type, result_data = l.result(result_id, 0)
if (len(result_data) != 1):
return None
l.simple_bind_s(result_data[0][0],password)
u = User.objects(username=username).first()
if u is None:
from random import choice
import string
temp_pass = ""
for i in range(8):
temp_pass = temp_pass + choice(string.letters)
u = User(username=username)
u.email = username + settings.LDAP_EMAIL_DOMAIN
u.set_password(temp_pass)
u.is_staff = True
u.is_superuser = False
u.is_active = True
u.save()
return u
except ldap.INVALID_CREDENTIALS:
return None
示例10: register
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import set_password [as 别名]
def register(request):
logger.debug('Register requested from IP %s' % request.META.get('REMOTE_ADDR'))
if request.user.is_authenticated():
return HttpResponseRedirect(reverse('web.index'))
if request.method == 'GET':
ctx = {'user': request.user, 'form': forms.RegisterForm(), }
return render(request, 'pages/register.html', ctx)
if request.method == 'POST':
form = forms.RegisterForm(request.POST)
if not form.is_valid():
ctx = {'form': form, }
return render(request, 'pages/register.html', ctx)
else:
new_user = User()
random_username = ''.join(random.sample(string.ascii_lowercase * 30, 20))
new_user.username = random_username
new_user.email = form.cleaned_data['email']
new_user.is_active = True
new_user.is_staff = False
new_user.is_superuser = False
new_user.set_password(form.cleaned_data['password'])
new_user.save()
user_doc = mongo.db.user.find_one({'username': new_user.username})
user_doc['writing_api_key'] = ''.join(random.sample(string.ascii_lowercase * 30, 20))
user_doc['reading_api_key'] = ''.join(random.sample(string.ascii_lowercase * 30, 20))
del user_doc['_id']
mongo.db.user.update({'username': new_user.username}, {'$set': user_doc})
logger.info('New user registered with email: %s' % new_user.email)
# log in
auth_login(request, authenticate(username=random_username, password=form.cleaned_data.get("password")))
return HttpResponseRedirect(reverse('web.settings'))
示例11: index
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import set_password [as 别名]
def index(request):
if request.method == 'GET':
context={}
return render(request, 'myapp/d-NewCus.html', context)
elif request.method == 'POST':
firstname = request.POST['txtFirstName']
lastname = request.POST['txtLastName']
idNo = request.POST['txtidNo']
Address = request.POST['txtAddress']
HomeAddress = request.POST['txtHomeAddress']
PhoneNumber = request.POST['txtPhoneNumber']
About = request.POST['txaAbout']
try:
user_name='student'
debt_owner=User.objects.get(username=user_name)
user = User()
user.username = firstname + lastname
user.first_name = firstname
user.last_name = lastname
user.set_password(idNo);
user.save()
_customer = Customer()
_customer.cus_id = user
_customer.id_no = idNo
_customer.cus_code=firstname
_customer.address = Address
_customer.home_address = HomeAddress
_customer.fone_number = PhoneNumber
_customer.about = About
_customer.status = 1
_customer.debt_owner = debt_owner
_customer.save()
user.backend = 'mongoengine.django.auth.MongoEngineBackend'
context={"status":"success"}
return render(request, 'myapp/d-mainScreen.html', context)
except Exception as e:
print(e)
示例12: register
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import set_password [as 别名]
def register(request):
if request.method == 'POST' and request.POST['name'] and request.POST['password']:
u = User(username=request.POST['name'])
u.set_password(request.POST['password'])
u.save()
return render_to_response('user/register.html')