Ejemplo n.º 1
0
def swordfish(context,request):
    logged_in = authenticated_userid(request)
    t_path = "../templates/register.pt"
    main = get_renderer(t_path).implementation()

    if not 'god' in context:
        context["god"] = User("god",
                              hashlib.sha1("eden".encode('UTF-8')).digest(), 
                              777777, 
                              firstName = "Jesus", 
                              lastName = "Christ", 
                              email = "*****@*****.**", 
                              phone = "777-777-7707", 
                              gradYear = 2013, 
                              inductionYear = 0, 
                              isofficer=True, 
                              isadvisor=True)

        context["god"].__parent__ = context
        
        return {'red':'',
                'main':get_renderer(t_path).implementation(),
                'content':'And on the eighth day, Man created God',
                'logged_in':authenticated_userid(request),
                'name':'Apotheosis Sucessful (:',
		'TutText': getTutText(context, view='')}
        
    return {'red':'',
            'main':get_renderer(t_path).implementation(),
            'content':'You already have a God',
            'logged_in':authenticated_userid(request),
            'name':'Apotheosis Failed D:',
	    'TutText': getTutText(context, view='')}
Ejemplo n.º 2
0
def add_user(context, request):
    logged_in = authenticated_userid(request)
    main = get_renderer('../templates/master.pt').implementation()
    schema = UserSchema()
    userform = Form(schema, buttons=('submit',),use_ajax=True)
    if 'username' in request.params:
        try:
            controls = request.POST.items()
            captured = userform.validate(controls)
        except deform.ValidationFailure, e:
            userform = e.render()
            return {'red':'',
                     'main':main,
                     'form':userform,
                     'content':'',
                     'logged_in':logged_in,
                     'name':'Add User',
		     'TutText': getTutText(context, view='')}
        username = request.params['username']
        if username in context:
            return {'red':'',
                     'logged_in':logged_in,
                     'main':main,
                     'form':'',
                     'content':'Sorry, the username '+username+' already exists in this system.  Please try again, or contact an administrator.',
                     'name':'Users',
		     'TutText': getTutText(context, view='')}
        password = hashlib.sha1(request.params["confirm"].encode('UTF-8')).digest()
        studentId = request.params['studentId']
        firstName = request.params['firstName']
        lastName = request.params['lastName']
        email = request.params['email']
        phone = request.params['phone']
        gradYear = request.params['gradYear']
        inductionYear = request.params['inductionYear']
        user = User(username,
                    password,
                    studentId,
                    firstName = firstName,
                    lastName = lastName,
                    email = email,
                    phone = phone,
                    gradYear = gradYear,
                    inductionYear = inductionYear)
        user.__parent__ = context
        context[username] = user
        serviceLog = ServiceLog(user)
        serviceLog.__parent__ = find_root(user)['serviceLogs']
        find_root(user)['serviceLogs'][username]=serviceLog
        user.serviceLog = ServiceLog
        find_root(context)['activityLogs'].user_creation(find_root(request.context)["users"][logged_in],user,request.application_url)
        return {'red':'users/',
                 'main':main,
                 'form':'',
                 'content':'The user '+firstName+' '+lastName+' was added to the system, with a username of '+username,
                 'logged_in':logged_in,
                 'name':'Redirecting...',
		 'TutText': getTutText(context, view='')}
Ejemplo n.º 3
0
def csvimport(context,request):
    logged_in = authenticated_userid(request)
    main = get_renderer('../templates/master.pt').implementation()
    schema = TextFieldSchema()
    importform = Form(schema, buttons=('submit',))
    if 'submit' in request.params:
        inputstring = str(request.params["text"])
        inputstring = inputstring.replace("\r","")
        inputstring = inputstring.replace(", ",",")
        lines = inputstring.split("\n")
        inputlist = []
        for line in lines:
            if not line == "":
                ul = line.split(",")
                user = User(
                            ul[2], #username
                            hashlib.sha1(ul[8].encode('UTF-8')).digest(), #password, encoded
                            ul[3], #studentID
                            firstName = ul[1],
                            lastName = ul[0],
                            email = ul[4],
                            phone = ul[5],
                            gradYear = ul[6],
                            inductionYear = ul[7]
                            )
                username = ul[2]
                if username in context:
                    return {'red':'',
                             'logged_in':logged_in,
                             'main':main,
                             'form':exportform.render(),
                             'content':"ERROR: the username "+username+" already exists in this system.  Please reassess your input data.",
                             'name':'Import From CSV',
			     'TutText': getTutText(context, view='')}
                user.__parent__ = context
                context[username] = user
                serviceLog = ServiceLog(user)
                serviceLog.__parent__ = find_root(user)['serviceLogs']
                find_root(user)['serviceLogs'][username]=serviceLog
                user.serviceLog = ServiceLog
                find_root(context)['activityLogs'].user_creation(find_root(request.context)["users"][logged_in],user,request.application_url)
        return {'red':'users/',
                 'main':main,
                 'logged_in':logged_in,
                 'form':'',
                 'content':'Imported Users from CSV',
                 'name':'Redirecting...',
		 'TutText': getTutText(context, view='')}
    return {'red':'',
             'main':main,
             'logged_in':logged_in,
             'form':importform.render(),
             'content':'',
             'name':'Import From CSV',
	     'TutText': getTutText(context, view='')}