本文整理汇总了Python中oasis.lib.Users2.get_user方法的典型用法代码示例。如果您正苦于以下问题:Python Users2.get_user方法的具体用法?Python Users2.get_user怎么用?Python Users2.get_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oasis.lib.Users2
的用法示例。
在下文中一共展示了Users2.get_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_change_pass_submit
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import get_user [as 别名]
def setup_change_pass_submit():
""" Set a new password """
user_id = session['user_id']
user = Users2.get_user(user_id)
if "newpass" not in request.form or "confirm" not in request.form:
flash("Please provide your new password")
return redirect(url_for("setup_change_pass"))
newpass = request.form['newpass']
confirm = request.form['confirm']
if len(newpass) < 7:
flash("Password is too short, please try something longer.")
return redirect(url_for("setup_change_pass"))
if not newpass == confirm:
flash("Passwords do not match")
return redirect(url_for("setup_change_pass"))
Users2.set_password(user_id=user_id, clearpass=newpass)
audit(1, user_id,
user_id,
"Setup", "%s reset password for %s." % (user['uname'], user['uname']))
flash("Password changed")
return redirect(url_for("setup_myprofile"))
示例2: cadmin_editgroup_member
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import get_user [as 别名]
def cadmin_editgroup_member(course_id, group_id):
""" Perform operation on group member. Remove/Edit/Etc
"""
cur_user = session['user_id']
group = None
try:
group = Groups.Group(g_id=group_id)
except KeyError:
abort(404)
if not group:
abort(404)
done = False
cmds = request.form.keys()
# "remove_UID", only know how to remove for now.
for cmd in cmds:
if '_' in cmd:
op, uid = cmd.split("_", 1)
if op == "remove":
uid = int(uid)
user = Users2.get_user(uid)
L.info("courseadmin: user %s removed from group %s by %s" % (uid, group_id, cur_user))
group.remove_member(uid)
flash("%s removed from group" % user['uname'])
done = True
if not done:
flash("No actions?")
return redirect(url_for('cadmin_editgroup',
course_id=course_id,
group_id=group_id))
示例3: setup_usersearch
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import get_user [as 别名]
def setup_usersearch():
""" Show a page allowing the admin search for users, or create new ones"""
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'))
users = []
nonefound = False
if request.method == "POST":
if 'usersearch_name' in request.form:
needle = request.form['usersearch_name']
if len(needle) < 2:
flash("Search term too short, please try something longer")
else:
uids = Users2.find(needle)
users = [Users2.get_user(uid) for uid in uids]
if len(users) == 0:
nonefound = True
else:
users.sort(key=lambda x: x['uname'])
return render_template(
'setup_usersearch.html',
users=users,
nonefound=nonefound
)
示例4: login_email_passreset
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import get_user [as 别名]
def login_email_passreset(code):
""" They've clicked on a password reset link.
Log them in (might as well) and send them to the password reset page."""
# This will also confirm their email if they haven't.
# Doesn't seem to be any harm in doing that
if len(code) > 20:
abort(404)
uid = Users.verify_confirm_code(code)
if not uid:
abort(404)
Users.set_confirm(uid)
Users.set_confirm_code(uid, "")
user = Users2.get_user(uid)
session['username'] = user['uname']
session['user_id'] = uid
session['user_givenname'] = user['givenname']
session['user_familyname'] = user['familyname']
session['user_fullname'] = user['fullname']
session['user_authtype'] = "local"
audit(1, uid, uid, "UserAuth",
"%s logged in using password reset email" % (session['username'],))
flash("Please change your password")
return redirect(url_for("setup_change_pass"))
示例5: cadmin_editgroup_member
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import get_user [as 别名]
def cadmin_editgroup_member(course_id, group_id):
""" Perform operation on group member. Remove/Edit/Etc
"""
group = None
try:
group = Groups.Group(g_id=group_id)
except KeyError:
abort(404)
if not group:
abort(404)
done = False
cmds = request.form.keys()
# expecting "remove_UID"
for cmd in cmds:
if '_' in cmd:
op, uid = cmd.split("_", 1)
if op == "remove":
uid = int(uid)
user = Users2.get_user(uid)
group.remove_member(uid)
flash("%s removed from group" % user['uname'])
done = True
if not done:
flash("No actions?")
return redirect(url_for('cadmin_editgroup',
course_id=course_id,
group_id=group_id))
示例6: setup_change_pass
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import get_user [as 别名]
def setup_change_pass():
""" Ask for a new password """
user_id = session['user_id']
user = Users2.get_user(user_id)
return render_template(
'setup_changepassword.html',
user=user,
)
示例7: cadmin_exam_viewmarked
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import get_user [as 别名]
def cadmin_exam_viewmarked(course_id, exam_id, student_uid):
""" Show a student's marked assessment results """
course = Courses2.get_course(course_id)
try:
exam = Exams.get_exam_struct(exam_id, course_id)
except KeyError:
exam = {}
abort(404)
results, examtotal = Assess.render_own_marked_exam(student_uid, exam_id)
if examtotal is False:
status = 0
else:
status = 1
marktime = Exams.get_mark_time(exam_id, student_uid)
firstview = Exams.get_student_start_time(exam_id, student_uid)
submittime = Exams.get_submit_time(exam_id, student_uid)
try:
datemarked = General.human_date(marktime)
except AttributeError:
datemarked = None
try:
datefirstview = General.human_date(firstview)
except AttributeError:
datefirstview = None
try:
datesubmit = General.human_date(submittime)
except AttributeError:
datesubmit = None
user = Users2.get_user(student_uid)
if submittime and firstview:
taken = submittime-firstview
takenmins = (taken.seconds/60)
else:
takenmins = None
return render_template(
"cadmin_markedresult.html",
course=course,
exam=exam,
results=results,
examtotal=examtotal,
datesubmit=datesubmit,
datemarked=datemarked,
datefirstview=datefirstview,
taken=takenmins,
user=user,
status=status
)
示例8: cadmin_exam_results
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import get_user [as 别名]
def cadmin_exam_results(course_id, exam_id):
""" View the results of an assessment """
course = Courses2.get_course(course_id)
if not course:
abort(404)
exam = Exams.get_exam_struct(exam_id, course_id)
if not exam:
abort(404)
if not int(exam['cid']) == int(course_id):
flash("Assessment %s does not belong to this course." % int(exam_id))
return redirect(url_for('cadmin_top', course_id=course_id))
exam['start_date'] = int(date_from_py2js(exam['start']))
exam['end_date'] = int(date_from_py2js(exam['end']))
exam['start_hour'] = int(exam['start'].hour)
exam['end_hour'] = int(exam['end'].hour)
exam['start_minute'] = int(exam['start'].minute)
exam['end_minute'] = int(exam['end'].minute)
groups = [Groups.Group(g_id=g_id)
for g_id
in Groups.active_by_course(course_id)]
results = {}
uids = set([])
totals = {}
for group in groups:
results[group.id] = Exams.get_marks(group, exam_id)
for user_id in results[group.id]:
uids.add(user_id)
if user_id not in totals:
totals[user_id] = 0.0
for qt, val in results[group.id][user_id].iteritems():
totals[user_id] += val['score']
questions = Exams.get_qts_list(exam_id)
users = {}
for uid in uids:
users[uid] = Users2.get_user(uid)
return render_template(
"cadmin_examresults.html",
course=course,
exam=exam,
results=results,
groups=groups,
users=users,
questions=questions,
when=datetime.now().strftime("%H:%m, %a %d %b %Y"),
totals=totals
)
示例9: setup_myprofile
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import get_user [as 别名]
def setup_myprofile():
""" Show an account summary for the current user account. """
user_id = session['user_id']
user = Users2.get_user(user_id)
course_ids = Users2.get_courses(user_id)
courses = []
for course_id in course_ids:
courses.append(Courses.get_course(course_id))
return render_template(
'setup_myprofile.html',
user=user,
courses=courses
)
示例10: cadmin_exam_unsubmit
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import get_user [as 别名]
def cadmin_exam_unsubmit(course_id, exam_id, student_uid):
""" "unsubmit" the student's assessment and reset their timer so they can
log back on and have another attempt.
"""
course = Courses2.get_course(course_id)
try:
exam = Exams.get_exam_struct(exam_id, course.id)
except KeyError:
exam = {}
abort(404)
Exams.unsubmit(exam_id, student_uid)
user = Users2.get_user(student_uid)
flash("""Assessment for %s unsubmitted and timer reset.""" % user["uname"])
return redirect(url_for("cadmin_exam_viewmarked", course_id=course.id, exam_id=exam["id"], student_uid=student_uid))
示例11: setup_user_remove_sysadmin
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import get_user [as 别名]
def setup_user_remove_sysadmin():
""" Remove sysadmin"""
user_id = session['user_id']
if not check_perm(user_id, 0, 1):
flash("You do not have User Administration access.")
return redirect(url_for('setup_top'))
new_user = request.form.get('userid', None)
if not new_user:
abort(400)
user = Users2.get_user(new_user)
delete_perm(new_user, 0, 1)
flash("%s is no longer a system admin on OASIS" % user['uname'])
return redirect(url_for("setup_usersearch"))
示例12: cadmin_permissions
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import get_user [as 别名]
def cadmin_permissions(course_id):
""" Present a page for them to assign permissions to the course"""
course = Courses2.get_course(course_id)
permlist = Permissions.get_course_perms(course_id)
perms = {}
for uid, pid in permlist: # (uid, permission)
if not uid in perms:
user = Users2.get_user(uid)
perms[uid] = {"uname": user["uname"], "fullname": user["fullname"], "pids": []}
perms[uid]["pids"].append(pid)
return render_template(
"courseadmin_permissions.html", perms=perms, course=course, pids=[5, 10, 14, 11, 8, 9, 15, 2]
)
示例13: login_forgot_pass_submit
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import get_user [as 别名]
def login_forgot_pass_submit():
""" Forgot their password. Grab their username and send them a reset email.
"""
if "cancel" in request.form:
flash("Password reset cancelled.")
return redirect(url_for("login_local"))
username = sanitize_username(request.form.get('username', None))
if username == "admin":
flash("""The admin account cannot do an email password reset,
please see the Installation instructions.""")
return redirect(url_for("login_forgot_pass"))
if username:
user_id = Users2.uid_by_uname(username)
else:
user_id = None
if not user_id:
flash("Unknown username ")
return redirect(url_for("login_forgot_pass"))
user = Users2.get_user(user_id)
if not user['source'] == "local":
flash("Your password is not managed by OASIS, "
"please contact IT Support.")
return redirect(url_for("login_forgot_pass"))
code = Users.gen_confirm_code()
Users.set_confirm_code(user_id, code)
email = user['email']
if not email:
flash("We do not appear to have an email address on file for "
"that account.")
return redirect(url_for("login_forgot_pass"))
text_body = render_template(os.path.join("email", "forgot_pass.txt"), code=code)
html_body = render_template(os.path.join("email", "forgot_pass.html"), code=code)
send_email(user['email'],
from_addr=None,
subject="OASIS Password Reset",
text_body=text_body,
html_body=html_body)
return render_template("login_forgot_pass_submit.html")
示例14: setup_useraudit
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import get_user [as 别名]
def setup_useraudit(audit_id):
""" Show all the audit entries for the given user 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'))
user = Users2.get_user(audit_id)
audits = get_records_by_user(audit_id)
for aud in audits:
aud['humantime'] = General.human_date(aud['time'])
return render_template(
'setup_useraudit.html',
user=user,
audits=audits
)
示例15: cadmin_editgroup
# 需要导入模块: from oasis.lib import Users2 [as 别名]
# 或者: from oasis.lib.Users2 import get_user [as 别名]
def cadmin_editgroup(course_id, group_id):
""" Present a page for editing a group, membership, etc.
"""
group = None
try:
group = Groups.Group(group_id)
except KeyError:
abort(404)
if not group:
abort(404)
course = Courses2.get_course(course_id)
if not course:
abort(404)
ulist = group.members()
members = [Users2.get_user(uid) for uid in ulist]
return render_template("courseadmin_editgroup.html", course=course, group=group, members=members)