当前位置: 首页>>代码示例>>Python>>正文


Python User.set_password方法代码示例

本文整理汇总了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
开发者ID:bbenne10,项目名称:atlsinfonia,代码行数:32,代码来源:routes.py

示例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)
开发者ID:abdelhai,项目名称:dyform,代码行数:27,代码来源:views.py

示例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)
开发者ID:kirillsavelyev,项目名称:python-tceh,代码行数:28,代码来源:auth.py

示例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))
开发者ID:eyscode,项目名称:gestor-proyectos-ewm,代码行数:35,代码来源:views.py

示例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()
开发者ID:fernandotakai,项目名称:questions,代码行数:27,代码来源:question_tests.py

示例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)
开发者ID:laDanz,项目名称:BuLiTipp,代码行数:36,代码来源:views.py

示例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
开发者ID:elesant,项目名称:DjangoBase,代码行数:32,代码来源:views.py

示例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
开发者ID:ILoveMuffins,项目名称:SystemSpecyfikacjiWymagan,代码行数:10,代码来源:serializers.py

示例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')
开发者ID:fernandotakai,项目名称:questions,代码行数:11,代码来源:user_tests.py

示例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()
开发者ID:HughePaul,项目名称:Website,代码行数:59,代码来源:utils.py

示例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'))
开发者ID:rwdxll,项目名称:flask_blog,代码行数:12,代码来源:controllers.py

示例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'))
开发者ID:Third9,项目名称:flask-login_test,代码行数:13,代码来源:login.py

示例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()}
开发者ID:tsh,项目名称:workload,代码行数:14,代码来源:api.py

示例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')
开发者ID:adicu,项目名称:intro-webapps,代码行数:14,代码来源:routes.py

示例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
开发者ID:GaloC,项目名称:gplib,代码行数:14,代码来源:libs.py


注:本文中的models.User.set_password方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。