当前位置: 首页>>代码示例>>Python>>正文


Python lib.Users2类代码示例

本文整理汇总了Python中oasis.lib.Users2的典型用法代码示例。如果您正苦于以下问题:Python Users2类的具体用法?Python Users2怎么用?Python Users2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Users2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup_usersearch

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
    )
开发者ID:colincoghill,项目名称:oasisqe,代码行数:29,代码来源:views_setup.py

示例2: setup_change_pass_submit

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"))
开发者ID:colincoghill,项目名称:oasisqe,代码行数:27,代码来源:views_setup.py

示例3: users_update_from_feed

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
开发者ID:tkanesh,项目名称:oasisqe,代码行数:51,代码来源:External.py

示例4: setup_myprofile

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
    )
开发者ID:colincoghill,项目名称:oasisqe,代码行数:14,代码来源:views_setup.py

示例5: login_forgot_pass_submit

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")
开发者ID:tkanesh,项目名称:oasisqe,代码行数:48,代码来源:__init__.py

示例6: cadmin_assign_coord

def cadmin_assign_coord(course_id):
    """ Set someone as course coordinator
"""
    course = Courses2.get_course(course_id)
    if not course:
        abort(404)

    if not "coord" in request.form:
        abort(400)

    new_uname = request.form["coord"]
    # TODO: Sanitize username
    try:
        new_uid = Users2.uid_by_uname(new_uname)
    except KeyError:
        flash("User '%s' Not Found" % new_uname)
    else:
        if not new_uid:
            flash("User '%s' Not Found" % new_uname)
        else:
            Permissions.add_perm(new_uid, course_id, 3)  # courseadmin
            Permissions.add_perm(new_uid, course_id, 4)  # coursecoord
            flash("%s can now control the course." % (new_uname,))

    return redirect(url_for("cadmin_config", course_id=course_id))
开发者ID:jamesdoherty,项目名称:oasisqe,代码行数:25,代码来源:views_cadmin.py

示例7: cadmin_editgroup_addperson

def cadmin_editgroup_addperson(course_id, group_id):
    """ Add a person to the group.
    """
    group = None
    try:
        group = Groups.Group(g_id=group_id)
    except KeyError:
        abort(404)

    if not group:
        abort(404)

    if "uname" not in request.form:
        abort(400)

    new_uname = sanitize_username(request.form['uname'])
    try:
        new_uid = Users2.uid_by_uname(new_uname)
    except KeyError:
        flash("User '%s' Not Found" % new_uname)
    else:
        if not new_uid:
            flash("User '%s' Not Found" % new_uname)
        elif new_uid in group.members():
            flash("%s is already in the group." % new_uname)
        else:
            group.add_member(new_uid)
            flash("Added %s to group." % (new_uname,))

    return redirect(url_for('cadmin_editgroup',
                            course_id=course_id,
                            group_id=group_id))
开发者ID:tkanesh,项目名称:oasisqe,代码行数:32,代码来源:views_cadmin.py

示例8: cadmin_editgroup_member

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))
开发者ID:ehchua,项目名称:oasisqe,代码行数:32,代码来源:views_cadmin.py

示例9: cadmin_editgroup_member

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))
开发者ID:tkanesh,项目名称:oasisqe,代码行数:30,代码来源:views_cadmin.py

示例10: login_email_passreset

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"))
开发者ID:tkanesh,项目名称:oasisqe,代码行数:26,代码来源:__init__.py

示例11: cadmin_assign_coord

def cadmin_assign_coord(course_id):
    """ Set someone as course coordinator
    """
    cur_user = session['user_id']
    course = Courses2.get_course(course_id)
    if not course:
        abort(404)

    if "coord" not in request.form:
        abort(400)

    new_uname = sanitize_username(request.form['coord'])
    try:
        new_uid = Users2.uid_by_uname(new_uname)
    except KeyError:
        flash("User '%s' Not Found" % new_uname)
    else:
        if not new_uid:
            flash("User '%s' Not Found" % new_uname)
        else:
            L.info("courseadmin: user %s assigned as coordinator to course %s by %s" % (new_uid, course_id, cur_user))
            Permissions.add_perm(new_uid, course_id, 3)  # courseadmin
            Permissions.add_perm(new_uid, course_id, 4)  # coursecoord
            flash("%s can now control the course." % (new_uname,))

    return redirect(url_for('cadmin_config', course_id=course_id))
开发者ID:ehchua,项目名称:oasisqe,代码行数:26,代码来源:views_cadmin.py

示例12: setup_change_pass

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,
    )
开发者ID:colincoghill,项目名称:oasisqe,代码行数:9,代码来源:views_setup.py

示例13: group_update_from_feed

def group_update_from_feed(group_id, refresh_users=False):
    """ Update group membership from it's feed
        Returns (added, removed, unknown) with usernames of users
    """
    group = Groups.Group(g_id=group_id)
    if not group.source == 'feed':
        return

    feed = Feeds.Feed(f_id=group.feed)
    scriptrun = ' '.join([feed.script, group.feedargs])
    try:
        output = feeds_run_group_script(feed.script, args=[group.feedargs, ])
    except BaseException as err:
        L.error("Exception in group feed '%s': %s" % (scriptrun, err))
        raise

    removed = []
    added = []
    unknown = []
    old_members = group.member_unames()
    new_members = output.split()[1:]
    for uname in new_members:
        uid = Users2.uid_by_uname(uname)
        if not uid:
            users_update_from_feed([uname, ])
            L.info("Group feed contained unknown user account %s" % uname)
            unknown.append(uname)
            continue
        if uname not in old_members:
            group.add_member(uid)
            added.append(uname)

    for uname in old_members:
        if uname not in new_members:
            uid = Users2.uid_by_uname(uname)
            group.remove_member(uid)
            removed.append(uname)

    if refresh_users:
        for uname in group.member_unames():
            uid = Users2.uid_by_uname(uname)
            user_update_details_from_feed(uid, uname)

    return added, removed, unknown
开发者ID:tkanesh,项目名称:oasisqe,代码行数:44,代码来源:External.py

示例14: login_local_submit

def login_local_submit():
    """ They've entered some credentials on the local login screen.
        Check them, then set up the session or redirect back with an error.
    """
    if 'username' not in request.form or 'password' not in request.form:
        L.info("Failed Login")
        flash("Incorrect name or password.")
        return redirect(url_for("login_local"))

    username = sanitize_username(request.form['username'])
    password = request.form['password']

    user_id = Users2.verify_pass(username, password)
    if not user_id:
        L.info("Failed Login for %s" % username)
        flash("Incorrect name or password.")
        return redirect(url_for("login_local"))

    user = Users2.get_user(user_id)
    if not user['confirmed']:
        flash("""Your account is not yet confirmed. You should have received
                 an email with instructions in it to do so.""")
        return redirect(url_for("login_local"))
    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'] = "local"

    audit(1, user_id, user_id, "UserAuth",
          "%s successfully logged in locally" % (session['username'],))

    if 'redirect' in session:
        L.info("Following redirect for %s" % username)
        target = OaConfig.parentURL + session['redirect']
        del session['redirect']
        return redirect(target)
    L.info("Successful Login for %s" % username)
    return redirect(url_for("main_top"
                            ""))
开发者ID:tkanesh,项目名称:oasisqe,代码行数:41,代码来源:__init__.py

示例15: cadmin_exam_viewmarked

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
    )
开发者ID:tkanesh,项目名称:oasisqe,代码行数:53,代码来源:views_cadmin.py


注:本文中的oasis.lib.Users2类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。