Ejemplo n.º 1
0
            def post(self):
                loggedInCheck(self)
                adminCheck(self)
                
                have_error = False
                username = (self.request.get('username')).lower()      
                password = self.request.get('password')
                verify = self.request.get('verify')
                email = self.request.get('email')
                firstName = self.request.get('firstName')
                lastName = self.request.get('lastName')
        
                params = dict(username = username,
                              email = email)
        
                if username.lower() == "testadmin":
                    params['error_username'] = "******"
                    have_error = True
                    
                if not valid_username(username):
                    params['error_username'] = "******"
                    have_error = True
        
                if not valid_password(password):
                    params['error_password'] = "******"
                    have_error = True
                elif password != verify:
                    params['error_verify'] = "Your passwords didn't match."
                    have_error = True
        
                if not valid_email(email):
                    params['error_email'] = "That's not a valid email."
                    have_error = True
        
                if have_error:
                    self.render('templates/admin/adduser.html', **params)
                else:                    
                    init = db.GqlQuery("SELECT * FROM User WHERE username=:1",username)

                    u = User(key_name = username, 
                             username = username,
                             usernamehash = get_hash(username),
                             userrole = "nonadmin",
                             password = password, 
                             email = email,
                             firstName = firstName,
                             lastName = lastName)
                    #u.put()
                    if len(list(init)) == 0:                        
                        u.put()
                        time.sleep(2)
                        self.redirect("/admin/adduser?e=false&u="+username)
                    else:
                        u.password = password #new password
                        u.userrole = init[0].userrole
                        u.put()
                        time.sleep(2)
                        self.redirect("/admin/adduser?e=true&u="+username)
Ejemplo n.º 2
0
 def get(self):
     
     init = db.GqlQuery("SELECT * FROM User WHERE username=:1",'testadmin')
     if len(list(init)) == 0:
         username = '******'
         u = User(key_name = username, 
                  username = username,
                  usernamehash = get_hash(username),
                  userrole = "admin",
                  password = str(get_hash('testadmin')), 
                  email = '',
                  firstName = '',
                  lastName = '')
         u.put()
     else:
         self.write('Application has already been initialized. Please contact an administrator')