コード例 #1
0
ファイル: c_user.py プロジェクト: srobo-legacy/userman
    def auto(self, args):
        """Automate user creation:
  * Create the new user
  * Set a random password
  * Email them the new password

Usage:
	user auto USERNAME FIRST_NAME LAST_NAME EMAIL [LANG]
"""
        if len(args) < 4:
            print self.auto.__doc__
            return

        # Avoid creating multiple users with similar names
        u = self._get_user( args[0], match_case = False )

        if u.in_db:
            print "User '%s' already exists" % (args[0] )
            return

        u.cname = args[1]
        u.sname = args[2]
        u.email = args[3]

        if not u.save():
            return False

        if len(args) > 4:
            u.set_lang( args[4] )
        else:
            "Default to English"
            u.set_lang( "english" )

        mailer.send_template( "welcome", u, { "PASSWORD": u.init_passwd } )
        print "User '%s' created and mailed." % (args[0])
コード例 #2
0
ファイル: c_user.py プロジェクト: Krenair/userman
    def auto(self, args):
        """Automate user creation:
  * Create the new user
  * Set a random password
  * Email them the new password

Usage:
	user auto USERNAME FIRST_NAME LAST_NAME EMAIL [LANG]
"""
        if len(args) < 4:
            print self.auto.__doc__
            return

        u = sr.users.user( args[0] )

        if u.in_db:
            print "User '%s' already exists" % (args[0] )
            return

        u.cname = args[1]
        u.sname = args[2]
        u.email = args[3]

        if not u.save():
            return False

        if len(args) > 4:
            u.set_lang( args[4] )
        else:
            "Default to English"
            u.set_lang( "english" )

        mailer.send_template( "welcome", u, { "PASSWORD": u.init_passwd } )
        print "User '%s' created and mailed." % (args[0])
コード例 #3
0
ファイル: c_teams.py プロジェクト: srobo-legacy/userman
    def __init__(self, args):
        CmdBase.__init__(self, args)
        CDESC, CSV_FNAME = args[0], args[1]

        college_group = college_find(CDESC)
        newusers = self.form_new_users(CSV_FNAME, college_group)

        print
        print "Will create %i users" % len(newusers)

        disp = [["username", "fname", "lname", "email"]]
        disp += [[u.username, u.cname, u.sname, u.email] for u in newusers]
        print_table(disp)

        teamno = None
        lang = "english"

        for arg in args[2:]:
            name, val = arg.split("=")

            if name == "team":
                teamno = int(val)
            elif name == "lang":
                lang = val
            else:
                raise Exception("Unsupported argument \"%s\"", arg)

        if teamno == None:
            teamno = new_team()

        print
        print "They will form team %i." % teamno
        print "And will be associated with %s: %s." % (college_group.name,
                                                       college_group.desc)

        students_group = sr.group("students")
        team_group = get_team(teamno)

        print "Is this OK? (yes/no)",
        resp = raw_input()
        resp = resp.lower().strip()

        if resp == "yes":
            print "Creating users..."

            for u in newusers:
                print "\t", u.username
                passwd = sr.users.GenPasswd()
                # Password has to be set after user is in db
                u.save()
                u.set_passwd(new=passwd)
                u.set_lang(lang)
                mailer.send_template("welcome", u, {"PASSWORD": passwd})

            print "Saving groups."
            for g in students_group, team_group, college_group:
                g.user_add(newusers)
                g.save()
コード例 #4
0
ファイル: c_teams.py プロジェクト: samphippen/userman
    def __init__(self, args):
        CmdBase.__init__(self, args)
        CDESC, CSV_FNAME = args[0], args[1]

        college_group = college_find( CDESC )
        newusers = self.form_new_users( CSV_FNAME )

        print
        print "Will create %i users" % len(newusers)

        disp = [["username", "fname", "lname", "email"]]
        disp += [ [u.username, u.cname, u.sname, u.email] for u in newusers ]
        print_table( disp )

        teamno = None
        lang = "english"

        for arg in args[2:]:
            name, val = arg.split("=")

            if name == "team":
                teamno = int(val)
            elif name == "lang":
                lang = val
            else:
                raise Exception("Unsupported argument \"%s\"", arg)

        if teamno == None:
            teamno = new_team()

        print
        print "They will form team %i." % teamno
        print "And will be associated with %s: %s." % ( college_group.name, college_group.desc )

        students_group = sr.group("students")
        team_group = get_team(teamno)

        print "Is this OK? (yes/no)",
        resp = raw_input()
        resp = resp.lower().strip()

        if resp == "yes":
            print "Creating users..."

            for u in newusers:
                print "\t", u.username
                passwd = sr.users.GenPasswd()
                # Password has to be set after user is in db
                u.save()
                u.set_passwd( new = passwd )
                u.set_lang( lang )
                mailer.send_template( "welcome", u, { "PASSWORD": passwd } )

            print "Saving groups."
            for g in students_group, team_group, college_group:
                g.user_add(newusers)
                g.save()
コード例 #5
0
ファイル: c_user.py プロジェクト: srobo-legacy/userman
    def rand_pass(self, args):
        """Email the user a new random password.
Usage:
	user rand_pass USERNAME"""

        if len(args) < 1:
            print self.rand_pass.__doc__
            return

        uname = args[0]
        u = self._get_user( uname )

        if not u.in_db:
            print "User '%s' not found\n" % ( uname )
            return False

        new_passwd = sr.users.GenPasswd()
        u.set_passwd( new = new_passwd )
        mailer.send_template( "new-password", u, { "PASSWORD": new_passwd } )
        return True
コード例 #6
0
ファイル: c_user.py プロジェクト: Krenair/userman
    def rand_pass(self, args):
        """Email the user a new random password.
Usage:
	user rand_pass USERNAME"""

        if len(args) < 1:
            print self.rand_pass.__doc__
            return

        uname = args[0]
        u = sr.users.user( uname )

        if not u.in_db:
            print "User '%s' not found\n" % (args[0])
            return False

        new_passwd = sr.users.GenPasswd()
        u.set_passwd( new = new_passwd )
        mailer.send_template( "new-password", u, { "PASSWORD": new_passwd } )
        return True
コード例 #7
0
ファイル: importschools.py プロジェクト: srobo-legacy/userman
    newname = sr.new_username(college_tla, first_name, last_name)
    u = sr.users.user(newname)

    u.cname = first_name
    u.sname = last_name
    u.email = team_leader['email']
    u.save()
    u.set_lang('english')
    u.save()

    college.user_add(u)
    college.desc = team_name
    college.save()

    for team in teamGroups:
        team.user_add(u)
        team.save()

    teachers.user_add(u)
    teachers.save()

    print "User {0} created".format(newname)

    if not args.no_emails:
        mailer.send_template("teacher_welcome", u, { "PASSWORD": u.init_passwd } )
        print "User {0} mailed".format(newname)

    count += 1

print >>sys.stderr, "Created {0} teams and skipped {1} more".format(count, skipped)
コード例 #8
0
    email = info['email'].strip()

    username = (first_name[0] + last_name).replace(' ', '').lower()

    u = sr.users.user(username)

    if u.in_db:
        print("Username {0} already in db, skipping import".format(username), file=sys.stderr)
        skipped += 1
        continue

    u.cname = first_name
    u.sname = last_name
    u.email = email
    u.save()
    u.set_lang('english')
    u.save()

    mentors.user_add(u)
    mentors.save()

    print("User {0} created".format(username))

    if not args.no_emails:
        mailer.send_template("mentor-welcome", u, { "PASSWORD": u.init_passwd } )
        print("User {0} mailed".format(username))

    count += 1

print("Created {0} mentors and skipped {1} more".format(count, skipped), file=sys.stderr)
コード例 #9
0
ファイル: importschools.py プロジェクト: srobo/userman
    print >>sys.stderr, "Creating groups + account for {0}".format(college_tla)

    first_name, last_name = the_contact['name'].split(' ')
    newname = sr.new_username(college_tla, first_name, last_name)
    u = sr.users.user(newname)

    u.cname = first_name
    u.sname = last_name
    u.email = the_contact['email']
    u.save()
    u.set_lang('english')
    u.save()

    college.user_add(u)
    college.save()

    for team in teamGroups:
        team.user_add(u)
        team.save()

    teachers.user_add(u)
    teachers.save()

    print "User {0} created".format(newname)

    mailer.send_template("teacher_welcome", u, { "PASSWORD": u.init_passwd } )
    print "User {0} mailed".format(newname)
    count += 1

print >>sys.stderr, "Created {0} teams and skipped {1} more".format(count, skipped)