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


Python User.createUser方法代码示例

本文整理汇总了Python中users.User.createUser方法的典型用法代码示例。如果您正苦于以下问题:Python User.createUser方法的具体用法?Python User.createUser怎么用?Python User.createUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在users.User的用法示例。


在下文中一共展示了User.createUser方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: signup

# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import createUser [as 别名]
def signup():
  ''' User Sign up page: Very basic email + password sign up form that will also login users. '''
  ## Data is used throughout for the jinja2 templates
  data={
    'active': "signup", # Sets the current page
    'loggedin': False # Don't show the logout link
  }

  ## Define the SignupForm
  form = SignupForm(request.form)
  ## Validate and then create userdata
  if request.method == "POST":
    if form.validate():
      ## Take form data
      email = form.email.data
      password = form.password.data
      company = form.company.data
      contact = form.contact.data
      userdata = {
        'username': email,
        'email': email,
        'password': password,
        'company': company,
        'contact': contact
      }

      ## Create user 
      user = User()
      result = user.createUser(userdata, g.rdb_conn)
      ## Check results for success or failure
      if result == "exists":
        data['error'] = True
        data['msg'] = 'User already exists'
      elif result is not False:
        stathat.ez_count(app.config['STATHAT_EZ_KEY'], app.config['ENVNAME'] + ' User Signup', 1)
        print("/signup - New user created") 
        cdata = cookies.genCdata(result, app.config['SECRET_KEY'])
        data['loggedin'] = True
        data['msg'] = 'You are signed up'
        data['error'] = False
        ## Build response
        resp = make_response(redirect(url_for('dashboard_page')))
        timeout = int(time.time()) + int(app.config['COOKIE_TIMEOUT'])
        ## Set the cookie secure as best as possible
        resp.set_cookie('loggedin', cdata, expires=timeout, httponly=True)
        return resp
    else:
      stathat.ez_count(app.config['STATHAT_EZ_KEY'], app.config['ENVNAME'] + ' Failed User Signup', 1)
      print("/signup - Failed user creation") 
      data['msg'] = 'Form is not valid'
      data['error'] = True

  ## Return Signup Page
  return render_template('signup.html', data=data, form=form)
开发者ID:mose,项目名称:cloudroutes-service,代码行数:56,代码来源:web.py

示例2: signup

# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import createUser [as 别名]
def signup():
    """
    User Sign up page: Very basic email + password
    sign up form that will also login users.
    """
    # Data is used throughout for the jinja2 templates
    data = {"active": "signup", "loggedin": False}  # Sets the current page  # Don't show the logout link

    # Define the SignupForm
    form = SignupForm(request.form)
    # Validate and then create userdata
    if request.method == "POST":
        if form.validate():
            # Take form data
            email = form.email.data
            password = form.password.data
            company = form.company.data
            contact = form.contact.data
            userdata = {"username": email, "email": email, "password": password, "company": company, "contact": contact}

            # Create user
            user = User()
            user.config = app.config
            result = user.createUser(userdata, g.rdb_conn)
            # Check results for success or failure
            if result == "exists":
                flash("User already exists.", "danger")
            elif result is not False:
                try:
                    stathat.ez_count(app.config["STATHAT_EZ_KEY"], app.config["ENVNAME"] + " User Signup", 1)
                except:
                    pass
                print("/signup - New user created")
                cdata = cookies.genCdata(result, app.config["SECRET_KEY"])
                data["loggedin"] = True
                flash("You are signed up.", "success")

                # Generate confirmation token
                generate_confirmation_token(email, result, time.time())

                # Build response
                resp = make_response(redirect(url_for("member.dashboard_page")))
                timeout = int(time.time()) + int(app.config["COOKIE_TIMEOUT"])
                # Set the cookie secure as best as possible
                resp.set_cookie("loggedin", cdata, expires=timeout, httponly=True)
                return resp
        else:
            stathat.ez_count(app.config["STATHAT_EZ_KEY"], app.config["ENVNAME"] + " False User Signup", 1)
            print("/signup - False user creation")
            flash("Form is not valid.", "danger")

    # Return Signup Page
    return render_template("user/signup.html", data=data, form=form)
开发者ID:pathcl,项目名称:runbook,代码行数:55,代码来源:views.py

示例3: setUp

# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import createUser [as 别名]
    def setUp(self):
        try:
            g.rdb_conn = r.connect(
                host=app.config['DBHOST'], port=app.config['DBPORT'],
                auth_key=app.config['DBAUTHKEY'], db=app.config['DATABASE'])

            userdata = {
                'username': '[email protected]',
                'email': '[email protected]',
                'password': 'password456',
                'company': 'company',
                'contact': 'tester'
            }

            # Create test user
            user = User()
            user.createUser(userdata, g.rdb_conn)

        except RqlDriverError:
            # If no connection possible throw 503 error
            abort(503, "No Database Connection Could be Established.")
开发者ID:bshyong,项目名称:cloudroutes-service,代码行数:23,代码来源:tests.py

示例4: setUp

# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import createUser [as 别名]
    def setUp(self):
        try:
            g.rdb_conn = r.connect(
                host=app.config["DBHOST"],
                port=app.config["DBPORT"],
                auth_key=app.config["DBAUTHKEY"],
                db=app.config["DATABASE"],
            )

            userdata = {
                "username": "[email protected]",
                "email": "[email protected]",
                "password": "password456",
                "company": "company",
                "contact": "tester",
            }

            # Create test user
            user = User()
            user.createUser(userdata, g.rdb_conn)

        except RqlDriverError:
            # If no connection possible throw 503 error
            abort(503, "No Database Connection Could be Established.")
开发者ID:CodingFlow,项目名称:cloudroutes-service,代码行数:26,代码来源:base.py


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