示例#1
0
文件: user.py 项目: ezpuzz/supysonic
def add_user():
    if request.method == 'GET':
        return render_template('adduser.html')

    error = False
    (name, passwd, passwd_confirm, mail,
     admin) = map(request.form.get,
                  ['name', 'passwd', 'passwd_confirm', 'mail', 'admin'])
    if name in (None, ''):
        flash('The name is required.')
        error = True
    if passwd in (None, ''):
        flash('Please provide a password.')
        error = True
    elif passwd != passwd_confirm:
        flash("The passwords don't match.")
        error = True

    if admin is None:
        admin = True if User.query.filter(
            User.admin == True).count() == 0 else False
    else:
        admin = True

    if not error:
        status = UserManager.add(name, passwd, mail, admin)
        if status == UserManager.SUCCESS:
            flash("User '%s' successfully added" % name)
            return redirect(url_for('user_index'))
        else:
            flash(UserManager.error_str(status))

    return render_template('adduser.html')
示例#2
0
def add_user():
    if request.method == "GET":
        return render_template("adduser.html")

    error = False
    (name, passwd, passwd_confirm, mail, admin) = map(
        request.form.get, ["name", "passwd", "passwd_confirm", "mail", "admin"]
    )
    if name in (None, ""):
        flash("The name is required.")
        error = True
    if passwd in (None, ""):
        flash("Please provide a password.")
        error = True
    elif passwd != passwd_confirm:
        flash("The passwords don't match.")
        error = True

    if admin is None:
        admin = True if User.query.filter(User.admin == True).count() == 0 else False
    else:
        admin = True

    if not error:
        status = UserManager.add(name, passwd, mail, admin)
        if status == UserManager.SUCCESS:
            flash("User '%s' successfully added" % name)
            return redirect(url_for("user_index"))
        else:
            flash(UserManager.error_str(status))

    return render_template("adduser.html")
示例#3
0
文件: user.py 项目: jelmer/supysonic
def add_user():
	if request.method == 'GET':
		return render_template('adduser.html')

	error = False
	(name, passwd, passwd_confirm, mail, admin) = map(request.form.get, [ 'name', 'passwd', 'passwd_confirm', 'mail', 'admin' ])
	if name in (None, ''):
		flash('The name is required.')
		error = True
	if passwd in (None, ''):
		flash('Please provide a password.')
		error = True
	elif passwd != passwd_confirm:
		flash("The passwords don't match.")
		error = True

	if admin is None:
		admin = True if User.query.filter(User.admin == True).count() == 0 else False
	else:
		admin = True

	if not error:
		status = UserManager.add(name, passwd, mail, admin)
		if status == UserManager.SUCCESS:
			flash("User '%s' successfully added" % name)
			return redirect(url_for('user_index'))
		else:
			flash(UserManager.error_str(status))

	return render_template('adduser.html')
示例#4
0
 def user_add(self, name, admin, password, email):
     if not password:
         password = getpass.getpass()
         confirm  = getpass.getpass('Confirm password: '******'t match"
             return
     status = UserManager.add(name, password, email, admin)
     if status != UserManager.SUCCESS:
         print >>sys.stderr, UserManager.error_str(status)
示例#5
0
文件: user.py 项目: ezpuzz/supysonic
def user_add():
	if not request.user.admin:
		return request.error_formatter(50, 'Admin restricted')

	username, password, email, admin = map(request.args.get, [ 'username', 'password', 'email', 'adminRole' ])
	if not username or not password or not email:
		return request.error_formatter(10, 'Missing parameter')
	admin = True if admin in (True, 'True', 'true', 1, '1') else False

	status = UserManager.add(username, password, email, admin)
	if status == UserManager.NAME_EXISTS:
		return request.error_formatter(0, 'There is already a user with that username')

	return request.formatter({})
示例#6
0
文件: user.py 项目: ezpuzz/supysonic
def user_add():
    if not request.user.admin:
        return request.error_formatter(50, 'Admin restricted')

    username, password, email, admin = map(
        request.args.get, ['username', 'password', 'email', 'adminRole'])
    if not username or not password or not email:
        return request.error_formatter(10, 'Missing parameter')
    admin = True if admin in (True, 'True', 'true', 1, '1') else False

    status = UserManager.add(username, password, email, admin)
    if status == UserManager.NAME_EXISTS:
        return request.error_formatter(
            0, 'There is already a user with that username')

    return request.formatter({})
示例#7
0
文件: cli.py 项目: ezpuzz/supysonic
def user_add(name, admin=False, email=None):
    password = prompt_pass("Please enter a password")
    if password:
        status = UserManager.add(name, password, email, admin)
        if status != UserManager.SUCCESS:
            print >>sys.stderr, UserManager.error_str(status)
示例#8
0
文件: cli.py 项目: ezpuzz/supysonic
def user_add(name, admin=False, email=None):
    password = prompt_pass("Please enter a password")
    if password:
        status = UserManager.add(name, password, email, admin)
        if status != UserManager.SUCCESS:
            print >> sys.stderr, UserManager.error_str(status)