def add_user(user):
    db = connect_db(app.config.get('DB'))
    User.set_db(db)
    Comment.set_db(db)
    #
    db_user = User()
    db_user.username = user['username']
    db_user.real_name = user['name']
    db_user.salt, db_user.password = make_salt_passwd(DEFAULT_PASSWORD)
    #
    db.save_doc(db_user)
def add_user(user):
    db = connect_db(app.config.get("DB"))
    User.set_db(db)
    Comment.set_db(db)
    #
    db_user = User()
    db_user.username = user["username"]
    db_user.real_name = user["name"]
    db_user.salt, db_user.password = make_salt_passwd(DEFAULT_PASSWORD)
    #
    db.save_doc(db_user)
示例#3
0
def sign_up():
  errors = []
  form = SignUpForm(request.form)
  if request.method == 'POST' and form.validate():
    username = form.username.data
    real_name = form.real_name.data
    salt, passwd_hash = make_salt_passwd(form.password.data)
    user = list(User.view('users/by_username', key = username))
    if user:
      errors.append('User already exists')
    else:
      new_user = User(username = username, real_name = real_name,
        salt = salt, password = passwd_hash)
      g.db.save_doc(new_user)
      flash('You have successfully registered')
      return redirect(url_for('index.index'))
  errors.extend(format_form_errors(form.errors.items()))
  return render_template('sign_up.html', form = form, errors = errors)
示例#4
0
def sign_up():
    errors = []
    form = SignUpForm(request.form)
    if request.method == 'POST' and form.validate():
        username = form.username.data
        real_name = form.real_name.data
        salt, passwd_hash = make_salt_passwd(form.password.data)
        user = list(User.view('users/by_username', key=username))
        if user:
            errors.append('User already exists')
        else:
            new_user = User(username=username,
                            real_name=real_name,
                            salt=salt,
                            password=passwd_hash)
            g.db.save_doc(new_user)
            flash('You have successfully registered')
            return redirect(url_for('index.index'))
    errors.extend(format_form_errors(form.errors.items()))
    return render_template('sign_up.html', form=form, errors=errors)