本文整理汇总了Python中models.User.set_password方法的典型用法代码示例。如果您正苦于以下问题:Python User.set_password方法的具体用法?Python User.set_password怎么用?Python User.set_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.set_password方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import set_password [as 别名]
def add_user():
# dummy user and dummy member are created on first request.
# user is responsible for creating dummy events.
Event.create_table(fail_silently=True)
Member.create_table(fail_silently=True)
Minute.create_table(fail_silently=True)
Picture.create_table(fail_silently=True)
User.create_table(fail_silently=True)
#
# # create a dummy member
# try:
# member = Member(first_name="Bryan",
# last_name="Bennett",
# collegiate_chapter="Zeta Omicron "
# "(Georgia Southern University)",
# initiation_date=datetime.date(2006, 04, 06),
# office="Secretary, Warden",
# image_path="Bryan_Bennett.jpg")
# member.save()
# except IntegrityError as e:
# print e
#
# create a dummy user
try:
admin = User(username='bbenne10', email='[email protected]',
admin=True, active=True)
admin.set_password("password")
admin.save()
except IntegrityError as e:
print e
示例2: register
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import set_password [as 别名]
def register():
form = SignupForm()
if request.method == 'POST' and form.validate():
user_per_email = User.objects(email=form.email.data)
user_per_username = User.objects(username=form.username.data)
if user_per_email:
form.errors['email'] = ['Email is already taken.']
elif user_per_username:
form.errors['username'] = ['Username is already taken.']
else:
user = User(email=form.email.data, username=form.username.data)
user.set_password(form.password.data)
user.save()
login_user(user)
analytics.identify(str(user.id), {'email': str(user.email)})
analytics.track(str(user.id), 'Registered (srv)')
return redirect('/data')
for field, errors in form.errors.items():
# type(errors)
for error in errors:
flash(u"Error in %s - %s" % (
getattr(form, field).label.text, error))
return render_template('users/user.html', form=form)
示例3: signup
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import set_password [as 别名]
def signup():
if request.method == 'GET':
return render_template('signup.html', form=RegistrationForm())
form = RegistrationForm(request.form)
if form.validate_on_submit():
user = User(form.username.data, form.email.data)
form.populate_obj(user)
user.set_password(form.password.data)
db.session.add(user)
db.session.commit()
msg = Message(
'Successful registration!',
sender=('Blog Tceh Cource', '[email protected]'),
recipients=[form.email.data]
)
msg.body = 'Welcome to our blog!'
mail.send(msg)
flash('Successful registration! Please login.')
return redirect(url_for('auth.login'))
else:
return render_template('signup.html', form=form)
示例4: view_register
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import set_password [as 别名]
def view_register(request):
#registerform = RegisterForm()
error = None
vista = "register"
if request.POST:
#registerform = RegisterForm(request.POST)
#if registerform.is_valid():
nombre = request.POST.get('nombre', -1)
apellidos = request.POST.get("apellidos", -1)
email = request.POST.get("email", -1)
profiles = Profile.objects.all()
passw = request.POST.get("password", -1)
repassw = request.POST.get("repassw", -1)
if repassw == passw and email != -1 and apellidos != -1 and nombre != -1:
u = User(username=nombre, first_name=nombre, last_name=apellidos, email=email)
u.set_password(repassw)
u.save()
Client.objects.create(user=u, profile=profiles[0])
request.session['registrado'] = True
return redirect(to="/register")
else:
if repassw == passw:
error = "los password no son iguales"
else:
error = "Falta insertar datos"
mostrar = 0
if request.session.get('registrado'):
mostrar = 1
del request.session['registrado']
print error
return render_to_response("desktop/inicio.html", {"error": error, 'mostrar': mostrar, 'vista': vista},
context_instance=RequestContext(request))
示例5: test_get_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import set_password [as 别名]
def test_get_user():
user = User()
user.username = u"test"
user.set_password("test123")
assert user.save()
assert user._id
q = Question()
q.question = u"test"
q.author = u"anon"
q.user = user.username
assert q.save(validate=True)
assert q._id
user_from_question = q.get_user()
assert user_from_question._id == user._id
q.user = u"anon!"
q.save()
assert not q.get_user()
示例6: register
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import set_password [as 别名]
def register(request):
context = {}
context["news"] = get_news_by_request(request)
user = User()
if request.method == 'POST':
form = UserCreateForm(request.POST, instance = user)
if form.is_valid():
pw = user.password
user.set_password(user.password)
user.theme_id=4
user.input_type_id=1
if not open_registration:
user.is_active = False
form.save()
ro = ReminderOffsets.objects.get(value=0)
user.reminder_offset.add(ro)
ro = ReminderOffsets.objects.get(value=2)
user.reminder_offset.add(ro)
if open_registration:
group = Group.objects.filter(name="BuLiTipp")[0]
user.groups.add(group)
user = authenticate(username=user.username, password=pw)
djlogin(request, user)
messages.success(request, "Benutzer erfolgreich angelegt! Tritt als nächstes einer Tippgemeinschaft bei!")
return HttpResponseRedirect(reverse("user", args=["tgchange"]))
else:
mail.send("BuLiTipp: User registriert", "[email protected]", "Bitte administriere den neuen User " + user.username+ " !")
messages.success(request, "Benutzer erfolgreich angelegt! Du kannst dich einloggen sobald der Administrator dich freigeschaltet hat.")
return HttpResponseRedirect(reverse("home"))
else:
form = UserCreateForm(instance=user)
context["form"] = form
return render(request, 'registration/register.html', context)
示例7: api_user_add
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import set_password [as 别名]
def api_user_add(request):
response = {}
email = get_param(request, "email")
password = get_param(request, "password", strip=False)
password_conf = get_param(request, "password_conf", strip=False)
errors = {}
if is_blank(email):
errors["email"] = "Sorry! You need an e-mail address to sign up."
elif not is_valid_email(email):
errors["email"] = "Sorry! Please put a valid e-mail address."
if is_blank(password):
errors["password"] = "Sorry! You need a password to sign up."
if is_blank(password_conf):
errors["password_conf"] = "Please confirm your password."
elif password != password_conf:
errors["password_conf"] = "Oops! Your passwords do not match."
try:
User.objects.get(email=email)
errors["email"] = "Sorry! This e-mail address is being used."
except User.DoesNotExist:
pass
if len(errors.keys()) > 0:
response["errors"] = errors
return response, 200
new_user = User(email=email)
new_user.set_password(password)
new_user.save()
response["user"] = new_user.id
user_login(request, new_user)
return response, 201
示例8: create
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import set_password [as 别名]
def create(self, validated_data):
user = User(username=validated_data['username'],
first_name=validated_data['first_name'],
last_name=validated_data['last_name'],
email=validated_data['email'])
user.set_password(validated_data['password'])
user.save()
return user
示例9: test_verify_password
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import set_password [as 别名]
def test_verify_password():
user = User()
user.username = u"test"
user.set_password('test1234')
user.save()
assert user.verify_password('test1234')
assert not user.verify_password('test')
示例10: make_test_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import set_password [as 别名]
def make_test_user(self):
try:
user = User.query.filter(User.email == "[email protected]").one()
except NoResultFound:
user = User('[email protected]', 'testuser')
user.set_password('happycamper')
db.session.add(user)
amounts = {
"prepayfull" : TicketType.query.filter(TicketType.name == 'Full Camp Ticket (prepay)').one().cost,
"full" : TicketType.query.filter(TicketType.name == 'Full Camp Ticket').one().cost
}
#
# TODO: needs to cover:
#
# single full ticket, no prepay
# single full ticket with prepay
# multiple full tickets, no prepay
# multiple full tickets, with prepay
# multiple full tickets, some prepay
#
# kids & campervans?
#
# full, prepay
for full, pp in ((1,0), (0,1), (3,0), (0,3), (2,1)):
for pt in (BankPayment, GoCardlessPayment, GoogleCheckoutPayment):
total = (full * amounts['full']) + (pp * amounts['prepayfull'])
payment = pt(total)
payment.state = "inprogress"
if payment.provider == "gocardless":
payment.gcid = "%3dSDJADG" % (int(random.random() * 1000 ))
sess.add(payment)
tt = 'Full Camp Ticket'
for i in range(full):
t = Ticket(type_id = TicketType.query.filter(TicketType.name == tt).one().id)
t.payment = payment
t.expires = datetime.utcnow() + timedelta(days=app.config.get('EXPIRY_DAYS'))
user.tickets.append(t)
tt = 'Full Camp Ticket (prepay)'
for i in range(pp):
t = Ticket(type_id = TicketType.query.filter(TicketType.name == tt).one().id)
t.payment = payment
t.expires = datetime.utcnow() + timedelta(days=app.config.get('EXPIRY_DAYS'))
user.tickets.append(t)
user.payments.append(payment)
db.session.commit()
self.user = user
print user.name
for p in user.payments.all():
print p.provider, p.amount
print p.tickets.all()
示例11: join_process
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import set_password [as 别名]
def join_process():
if request.method == 'POST':
new_user = User()
new_user.email = request.form['user_email']
new_user.nickname = request.form['user_nickname']
new_user.set_password(request.form['user_password'])
new_user.is_admin = False
db.session.add(new_user)
db.session.commit()
return redirect(url_for('index'))
示例12: add_entries
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import set_password [as 别名]
def add_entries():
u = User(request.form['user_id'], request.form['nickname'])
u.set_password(request.form['password'])
db_session.add(u)
db_session.commit()
db_session.close()
flash('New User was successfully posted')
return redirect(url_for('show_entries'))
示例13: new_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import set_password [as 别名]
def new_user():
username = request.json.get('username')
password = request.json.get('password')
if username is None or password is None:
abort(400) # missing arguments
if User.query.filter_by(username=username).first() is not None:
abort(400) # existing user
user = User(username=username)
user.set_password(password)
db.session.add(user)
db.session.commit()
return jsonify({}), 201, {'Location': user.get_url()}
示例14: create_account
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import set_password [as 别名]
def create_account():
if request.method == 'GET':
return render_template('newaccount.html')
else:
username = request.form['username']
email = request.form['email']
password = request.form['password']
user = User(username, email)
user.set_password(password)
db.session.add(user)
db.session.commit()
return redirect('/login')
示例15: create_couch_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import set_password [as 别名]
def create_couch_user(username, password):
db = get_db("couchauth")
User.set_db(db)
users = User.view("couchauth/username")
query = users[username]
user = query.one()
if not user:
user = User()
user.username = username
user.set_password(password)
user.save()
return user