コード例 #1
0
ファイル: admin.py プロジェクト: hreeder/RomeoAuth
def viewuser(uid):
	user = ldaptools.getuser(uid)
	if not user:
		flash("'%s' is not a valid username" % uid, "danger")
		return redirect("/admin")
	user = user.__dict__
	return render_template("admin_viewuser.html", user=user)
コード例 #2
0
ファイル: admin.py プロジェクト: hreeder/RomeoAuth
def userlookup():
	user = None
	if "userid" in request.form:
		user = ldaptools.getuser(request.form["userid"])
		if not user:
			flash("Unable to find '%s' as a username." % request.form['userid'], "danger")
			return redirect("/admin")
		else:
			user = user.__dict__
	return redirect("/admin/user/%s" % request.form['userid'])
コード例 #3
0
ファイル: admin.py プロジェクト: hreeder/RomeoAuth
def admin_user(uid, action, value=None):
	user = ldaptools.getuser(uid)
	validActions = ['activate', 'disable', 'delete', 'addgroup', 'delgroup']
	if not user:
                flash("'%s' is not a valid username" % uid, "danger")
                return redirect("/admin")
	if action not in validActions:
		flash("'%s' is not a valid action to perform to %s" % (action, uid), "danger")
		return redirect("/admin/user/%s" % uid)

	currentStatus = user.accountStatus[0]

	if action == "activate" and currentStatus == "inactive":
		result = ldaptools.modattr(uid, MOD_REPLACE, "accountStatus", "romeo")
		assert(result)
		flash("Successfully re-activated %s" % uid, "success")
		return redirect("/admin/user/%s" % uid)
	elif action == "disable" and currentStatus == "romeo":
                result = ldaptools.modattr(uid, MOD_REPLACE, "accountStatus", "inactive")
                assert(result)
                flash("Successfully disabled %s" % uid, "success")
                return redirect("/admin/user/%s" % uid)
	elif action == "delete":
		if ldaptools.deleteuser(uid):
			flash("Deleted %s" % uid, "success")
			return redirect("/admin")
		else:
			flash("SOMETHING BAD HAPPENED OH GOD PANIC", "danger")
			return redirect("/admin")
	elif action == "addgroup" and value and value not in user.get_authgroups():
		ldaptools.modgroup(uid, MOD_ADD, str(value))
		flash("%s added to %s" % (uid, value), "success")
		return redirect("/admin/user/%s" % uid)
	elif action == "delgroup" and value and value in user.get_authgroups():
		ldaptools.modgroup(uid, MOD_DELETE, str(value))
		flash("%s removed from %s" % (uid, value), "success")
		return redirect("/admin/user/%s" % uid)
	flash("Unable to perform that action, maybe it's an invalid action due to the user's current state", "danger")
	return redirect("/admin/user/%s" % uid)
コード例 #4
0
ファイル: registration.py プロジェクト: hreeder/RomeoAuth
def create_account():
	capcode = request.form.get("capcode")
	if not validate_keycaptcha(capcode):
		flash("Captcha Incorrect, Please Try Again")
		return redirect("/signup")

	attrs = {}
	attrs["uid"] = request.form.get("username")
	attrs["email"] = request.form.get("email")
	attrs["userPassword"] = request.form.get("password")

	attrs["characterName"] = request.form.get("characterName")
	attrs["accountStatus"] = "romeo"

	for key in attrs:
		attrs[key] = str(attrs[key])

	import re
	def special_match(strg, search=re.compile(r'[^-_\.a-zA-Z0-9]+').search):
		return bool(search(strg))

	if special_match(attrs["uid"]):
		flash("Usernames can only contain Numbers, Letters and - _ . characters.", "danger")
		return redirect("/signup")

	try:
		ldaptools.adduser(attrs)
	except ALREADY_EXISTS:
		flash("User already exists", "danger")
		return redirect("/")

	user = ldaptools.getuser(attrs["uid"])
	login_user(user)
	flash("Created and logged in as %s" % attrs["uid"], "success")

	return redirect("/")