本文整理汇总了Python中oasis.lib.Users2.create方法的典型用法代码示例。如果您正苦于以下问题:Python Users2.create方法的具体用法?Python Users2.create怎么用?Python Users2.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oasis.lib.Users2
的用法示例。
在下文中一共展示了Users2.create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: users_update_from_feed
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import create [as 别名]
def users_update_from_feed(upids):
""" Given a list of upids, go through and try to fetch details from
feed, updating/creating the accounts if needed.
"""
for upid in upids:
user_id = Users2.uid_by_uname(upid)
if not user_id: # we don't know who they are, so create them.
for feed in UFeeds.all_list():
try:
out = feeds_run_user_script(feed.script, args=[upid, ])
except BaseException as err:
L.error("Exception in user feed '%s': %s" % (feed.script, err))
continue
res = out.splitlines()
if res[0].startswith("ERROR"):
L.error("Error running user feed '%s': %s" % (feed.script, res))
continue
line = res[1]
studentid = ""
try:
(upid, name, email, studentid) = line.split(',')
except ValueError:
try:
(upid, name, email) = line.split(',')
except ValueError:
continue
given = name.split(" ")[0]
try:
family = " ".join(name.split(" ")[1:])
except ValueError:
family = ""
Users2.create(upid,
'',
given,
family,
2,
studentid,
email,
None,
'feed',
'',
True)
break
else:
L.error("Error running user feed for existing account %s" % user_id)
return
示例2: login_webauth_submit
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import create [as 别名]
def login_webauth_submit():
""" The web server should have verified their credentials and
provide it in env['REMOTE_USER']
Check them, then set up the session or redirect back with an error.
If we haven't seen them before, check with our user account feed(s)
to see if we can find them.
"""
if 'REMOTE_USER' not in request.environ:
L.error("REMOTE_USER not provided by web server and 'webauth' is being attempted.")
return redirect(url_for("login_webauth_error"))
username = request.environ['REMOTE_USER']
if '@' in username and OaConfig.webauth_ignore_domain:
username = username.split('@')[0]
user_id = Users2.uid_by_uname(username)
if not user_id:
Users2.create(username, '', '', '', 1, '', '', None, 'unknown', '', True)
user_id = Users2.uid_by_uname(username)
user = Users2.get_user(user_id)
session['username'] = username
session['user_id'] = user_id
session['user_givenname'] = user['givenname']
session['user_familyname'] = user['familyname']
session['user_fullname'] = user['fullname']
session['user_authtype'] = "httpauth"
audit(1, user_id, user_id, "UserAuth",
"%s successfully logged in via webauth" % session['username'])
if 'redirect' in session:
target = OaConfig.parentURL + session['redirect']
del session['redirect']
return redirect(target)
return redirect(url_for("main_top"))
示例3: setup_usercreate
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import create [as 别名]
def setup_usercreate():
""" Show a page allowing the admin to enter user details
to create an account.
"""
user_id = session['user_id']
if not check_perm(user_id, -1, "useradmin"):
flash("You do not have User Administration access.")
return redirect(url_for('setup_top'))
new_uname = ""
new_fname = ""
new_sname = ""
new_email = ""
new_pass = ""
new_confirm = ""
error = None
if request.method == "POST":
form = request.form
if "usercreate_cancel" in form:
flash("User Account Creation Cancelled")
return redirect(url_for('setup_usersearch'))
if "usercreate_save" in form:
new_uname = form.get('new_uname', "")
new_fname = form.get('new_fname', "")
new_sname = form.get('new_sname', "")
new_email = form.get('new_email', "")
new_pass = form.get('new_pass', "")
new_confirm = form.get('new_confirm', "")
if not all((new_uname, new_email, new_pass, new_confirm)):
error = "Please fill in all fields."
elif Users2.uid_by_uname(new_uname):
error = "ERROR: An account already exists with that name"
elif new_confirm == "" or not new_confirm == new_pass:
error = "Passwords don't match (or are empty)"
else: # yaay, it's ok
# uname, passwd, givenname, familyname, acctstatus,
# studentid, email=None, expiry=None, source="local"
Users2.create(new_uname,
"nologin-creation",
new_fname,
new_sname,
2,
'',
new_email)
Users2.set_password(Users2.uid_by_uname(new_uname), new_pass)
flash("New User Account Created for %s" % new_uname)
new_uname = ""
new_fname = ""
new_sname = ""
new_email = ""
new_pass = ""
new_confirm = ""
if error:
flash(error)
return render_template(
'setup_usercreate.html',
new_uname=new_uname,
new_fname=new_fname,
new_sname=new_sname,
new_email=new_email,
new_pass=new_pass,
new_confirm=new_confirm
)