本文整理汇总了Python中user.models.User.save方法的典型用法代码示例。如果您正苦于以下问题:Python User.save方法的具体用法?Python User.save怎么用?Python User.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user.models.User
的用法示例。
在下文中一共展示了User.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register_3
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import save [as 别名]
def register_3(request):
if email:
#register
try:
user = User.objects.get(email=email)
except:
ip = request.META.get('REMOTE_ADDR')
facebook = request.POST["facebook"]
iso = request.POST["iso"]
name = request.POST["name"]
user = User()
try:
country = Country.objects.get(iso=iso)
except:
country = Country.objects.get(id=1)
user.country_error = iso
user.username = email
user.name = name
user.email = email
user.facebook = facebook
user.country = country
user.ip = ip
user.date = datetime.now()
user.confirmed = 1
user.save()
else:
res = "not login"
return HttpResponse(res)
示例2: register
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import save [as 别名]
def register():
form = RegisterForm()
if form.validate_on_submit():
salt = bcrypt.gensalt()
hashed_password = bcrypt.hashpw(form.password.data, salt)
code = str(uuid.uuid4())
user = User(
username=form.username.data,
password=hashed_password,
email=form.email.data,
first_name=form.first_name.data,
last_name=form.last_name.data,
change_configuration={
"new_email": form.email.data.lower(),
"confirmation_code": code
}
)
# email the user
body_html = render_template('mail/user/register.html', user=user)
body_text = render_template('mail/user/register.txt', user=user)
email(user.email, "Welcome to Flaskbook", body_html, body_text)
user.save()
return redirect(url_for('home_app.home'))
return render_template('user/register.html', form=form)
示例3: handle
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import save [as 别名]
def handle(self, *args, **options):
file_name = args[0]
f = open(file_name, "rb")
d = csv.DictReader(f)
for row in d:
username = row["username"]
if User.objects.filter(username=username).exists():
print "User %s exists." % (username)
else:
first_name = row.get("first_name", "")
last_name = row.get("last_name", "")
email = row.get("email", "")
locality = row.get("locality", "")
gender = row.get("gender", "")
password = row.get("password", "")
user = User(username=username, email=email, first_name=first_name, last_name=last_name)
user.set_password(password)
user.save()
user.profile.gender = gender
try:
user.profile.locality = Entity.objects.get(id=locality)
except ObjectDoesNotExist:
print "user %s locality id %s does not exist" % (username, locality)
user.profile.save()
示例4: attempt_login
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import save [as 别名]
def attempt_login(request):
matches = authenticate_users(request.POST['email'], request.POST['password'])
if len(matches) == 1:
# Exactly one match, cool, just authenticate the user
user = authenticate(user=matches[0])
log_user_in(request, user)
return matches, None
elif len(matches) > 1:
# Multiple matches, let the caller handle this
return matches, None
elif len(matches) == 0:
# Incorrect credentials. Check if this is a user from the old userpage system
old_member = authenticate_sherpa2_user(request.POST['email'], request.POST['password'])
if old_member is not None:
# Actually, it is! Let's try to import them.
if User.get_users().filter(memberid=old_member.memberid, is_inactive=False).exists():
return matches, 'old_memberid_but_memberid_exists'
# Check if a pending user exists. This shouldn't ever happen (a pending user is recently
# enrolled, and an existing user will have been member for a long time).
if User.objects.filter(memberid=old_member.memberid, is_pending=True).exists():
# Give the same error ("user exists, you need to use your new password")
return matches, 'old_memberid_but_memberid_exists'
# Verify that they exist in the membersystem (this turned out to be an incorrect assumption)
if not Actor.get_personal_members().filter(memberid=old_member.memberid).exists():
# We're not quite sure why this can happen, so we'll just give them the invalid
# credentials message - but this might be confusing for those who were able to log
# in previously.
return matches, 'invalid_credentials'
# Create the new user
try:
# Check if the user's already created as inactive
user = User.get_users().get(memberid=old_member.memberid, is_inactive=True)
user.is_inactive = False
user.set_password(request.POST['password'])
user.save()
except User.DoesNotExist:
# New user
user = User(identifier=old_member.memberid, memberid=old_member.memberid)
user.set_password(request.POST['password'])
user.save()
# Update the email on this actor, in case it were to differ from the sherpa2 email
user.update_personal_data({'email': request.POST['email']})
# Import any fjelltreffen-annonser from the old system
import_fjelltreffen_annonser(user)
authenticate(user=user)
log_user_in(request, user)
return [user], None
else:
# No luck, just provide the error message
return matches, 'invalid_credentials'
示例5: attempt_registration_nonmember
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import save [as 别名]
def attempt_registration_nonmember(request):
error_messages = []
# Check that name is provided
if not validator.name(request.POST['name']):
error_messages.append('invalid_name')
# Check that the email address is valid
if not validator.email(request.POST['email']):
error_messages.append('invalid_email')
# Check that the email address isn't in use
if User.objects.filter(identifier=request.POST['email']).exists():
error_messages.append('email_exists')
# Check that the password is long enough
if len(request.POST['password']) < settings.USER_PASSWORD_LENGTH:
error_messages.append('too_short_password')
if len(error_messages) > 0:
request.session['user.registration_nonmember_attempt'] = {
'name': request.POST['name'],
'email': request.POST['email']
}
return None, error_messages
user = User(identifier=request.POST['email'], email=request.POST['email'])
user.first_name, user.last_name = request.POST['name'].rsplit(maxsplit=1)
user.set_consent_accepted_privacy_policy_date(None, False)
user.set_password(request.POST['password'])
user.save()
user.set_consent_dnt(
Forening.DNT_CENTRAL_ID,
'email',
True if request.POST.get('consent-dnt-communication-email') else False,
save=True,
)
authenticate(user=user)
log_user_in(request, user)
try:
message = render_to_string('common/user/login/registered_nonmember_email.txt', request=request)
send_mail(EMAIL_REGISTERED_SUBJECT, message, settings.DEFAULT_FROM_EMAIL, [user.get_email()])
except (SMTPException, SSLError, UnicodeEncodeError):
# Silently log and ignore this error. Consider warning the user that the email wasn't sent?
logger.warning(
"Klarte ikke å sende registreringskvitteringepost",
exc_info=sys.exc_info(),
extra={'request': request}
)
return user, None
示例6: doAdd
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import save [as 别名]
def doAdd(request):
param = request.POST
user = User()
user.name = param['name']
user.gender = param['gender']
user.ip = request.META['REMOTE_ADDR']
filename = '/a.jpg'
f = file(filename, 'w+')
f.write(request.FILES['photo'])
f.close
user.photo = filename
user.save()
return render_to_response('user/add.html')
示例7: create_user
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import save [as 别名]
def create_user(self, form, commit=True, **kwargs):
email = form.cleaned_data['email']
try:
user = User.objects.get(email__iexact=email)
except User.DoesNotExist:
user = User()
user.username = email
user.email = email
user.set_password(User.objects.make_random_password(getattr(settings, 'ACCOUNT_RANDOM_PASSWD_LENGTH', 10)))
user.save()
return user
示例8: post
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import save [as 别名]
def post(self):
context = self.get_context()
form = context.get('form')
if form.validate():
user = User()
form.populate_obj(user)
user.password = str(flask_bcrypt.generate_password_hash(user.password),'utf-8')
user.save()
return redirect(url_for('user.login'))
flash('Your request failed to pass','newAccount')
return redirect(url_for('user.new'))
示例9: create_user
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import save [as 别名]
def create_user(self, form, commit=True, **kwargs):
email = form.cleaned_data['email']
try:
user = User.objects.get(email__iexact=email)
except User.DoesNotExist:
user = User()
user.username = email
user.email = email
user.set_password(User.objects.make_random_password())
user.save()
return user
示例10: _add_user
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import save [as 别名]
def _add_user(request, email, password, band_id, facebook = "", name = "", country = ""):
#import ipdb; ipdb.set_trace()
key = hashlib.md5(email).hexdigest()
try:
country = Country.objects.get(id=country)
except:
country = Country.objects.get(id=1)
if not facebook:
confirmed = 0
try:
html = "Hello!"
html = html + "<br><br>To confirm your vote "
html = html + "<a href='http://rockranking.com/user/validate/" + key + "/'>click here</a>"
html = html + "<br><br>If you can not access the link, please copy this"
html = html + "<br>http://rockranking.com/user/validate/" + key + "/"
html = html + "<br>and paste in your browser"
html = html + "<br><br>Rock Ranking Team \m/"
_send_email(email,html)
email_feedback = 'sent'
except:
email_feedback = 'error to sent'
else:
confirmed = 1
email_feedback = 'facebook login'
try:
user = User()
user.username = ""
user.name = name
user.email = email
user.password = hashlib.md5(password).hexdigest()
user.email_feedback = email_feedback
user.facebook = facebook
user.country = country
user.ip = request.META.get('REMOTE_ADDR')
user.key = key
user.date = datetime.now()
user.action = "add_band_%s" % band_id
user.confirmed = confirmed
user.save()
return True
except:
return False
示例11: attempt_registration_nonmember
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import save [as 别名]
def attempt_registration_nonmember(request):
error_messages = []
# Check that name is provided
if not validator.name(request.POST['name']):
error_messages.append('invalid_name')
# Check that the email address is valid
if not validator.email(request.POST['email']):
error_messages.append('invalid_email')
# Check that the email address isn't in use
if User.objects.filter(identifier=request.POST['email']).exists():
error_messages.append('email_exists')
# Check that the password is long enough
if len(request.POST['password']) < settings.USER_PASSWORD_LENGTH:
error_messages.append('too_short_password')
if len(error_messages) > 0:
request.session['user.registration_nonmember_attempt'] = {
'name': request.POST['name'],
'email': request.POST['email']
}
return None, error_messages
user = User(identifier=request.POST['email'], email=request.POST['email'])
user.first_name, user.last_name = request.POST['name'].rsplit(' ', 1)
user.set_password(request.POST['password'])
user.save()
authenticate(user=user)
log_user_in(request, user)
try:
t = loader.get_template('common/user/login/registered_nonmember_email.txt')
c = RequestContext(request)
send_mail(EMAIL_REGISTERED_SUBJECT, t.render(c), settings.DEFAULT_FROM_EMAIL, [user.get_email()])
except (SMTPException, SSLError):
# Silently log and ignore this error. Consider warning the user that the email wasn't sent?
logger.warning(u"Klarte ikke å sende registreringskvitteringepost",
exc_info=sys.exc_info(),
extra={'request': request}
)
return user, None
示例12: edit_user
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import save [as 别名]
def edit_user(user, session=None):
if not user.isawiz:
return
cls()
username = search()
shuser = show(username, session)
if shuser is None:
shuser = User(username)
print("\nEditing : {}\n".format(username))
try:
shuser.username = edit_field("Name: ", shuser.username)
shuser.password = edit_field("Password: ", shuser.password)
shuser.save(session)
print("{} saved".format(shuser.username))
except AssertionError as e:
print(e)
print("Changes not saved")
示例13: create
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import save [as 别名]
def create(name, email, avatar, social_ids=None, social_accounts=None):
user = User(
name=name,
email=email,
avatar=avatar,
social_ids=social_ids or [],
social_accounts=social_accounts or []
)
yield user.save()
return user
示例14: handle
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import save [as 别名]
def handle(self, *args, **options):
file_name = args[0]
f = open(file_name, 'rb')
d = csv.DictReader(f)
i = 1
for row in d:
ordinal = int(row['ordinal'])
locality_name = row['locality']
ballot = row['ballot']
mayor = bool(row['mayor'])
fullname = row['name']
locality = Entity.objects.filter(division__index=3).get(name_he=locality_name)
candidatelist = locality.candidatelist_set.get(ballot=ballot)
last_name, first_name = fullname.split(' ', 1)
username = u'c_%04d' % i
user = User(
username=username,
first_name=first_name,
last_name=last_name,
)
password = random.randint(1,99999)
s = u'%s, %s, %s, %s, %s' % (locality_name, first_name, last_name, username, password)
print s.encode('utf-8')
user.set_password(password)
user.save()
user.profile.locality = locality
user.profile.verification = u'V'
user.profile.save()
candidate = Candidate(candidate_list=candidatelist, user=user,
ordinal=ordinal, for_mayor=mayor)
candidate.save()
i += 1
示例15: join
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import save [as 别名]
def join(request):
user = User()
user.name = request.POST['name']
user.email = request.POST['email']
user.password = request.POST['password']
user.gender = request.POST['gender']
if User.objects.filter(email = user.email).exists() is not True:
user.save()
return HttpResponseRedirect('/user/joinsuccess')
# 입력폼 비교 구문과 이에따른 메시지 생성을 별도의 함수내에 구현하고, 그 수행 결과에 따른 action 만을
# 본 함수에서 구현하도록 한다.
# 응답으로 되돌려줄 리턴 값은
# email_available, user의 폼 입력 값들, 응답할 메시지
# 세 가지로 한다.
# elif len(User.objects.filter(email = user.email)) == 0:
# return render(request, 'user/joinform.html', {"email_availability": False, "user": user})
else:
return render(request, 'user/joinform.html', {"email_availability" : False, "user":user})