def post(self, path): self.head() self.response.headers['Content-Type'] = 'text/html' if not user.validate_user(self): message = '' if len(self.request.get('_user')) > 0: message = 'Invalid username or password' # give a user a form to sign in path = os.path.join(os.path.dirname(__file__), 'templates/login.html') self.response.write( template.render(path, { 'url': self.request.url, 'message': message })) return u = self.request._user template_file = 'templates/records.html' template_info = { 'url': self.request.url, 'name': u.first_name + ' ' + u.last_name, 'email': u.email, 'scores': grades.scores(u.email), } if u.status == 'staff': template_file = 'templates/records_staff.html' template_info['user_list'] = user.user_list() path = os.path.join(os.path.dirname(__file__), template_file) self.response.write(template.render(path, template_info))
def post(self,path): self.head() self.response.headers['Content-Type'] = 'text/html' if not user.validate_user(self): message = '' if len(self.request.get('_user')) > 0: message = 'Invalid username or password' # give a user a form to sign in path = os.path.join(os.path.dirname(__file__), 'templates/login.html') self.response.write(template.render(path,{'url': self.request.url,'message':message})) return u = self.request._user template_file = 'templates/records.html' template_info = { 'url': self.request.url, 'name': u.first_name + ' ' + u.last_name, 'email': u.email, 'scores': grades.scores(u.email), } if u.status == 'staff': template_file = 'templates/records_staff.html' template_info['user_list'] = user.user_list() path = os.path.join(os.path.dirname(__file__), template_file) self.response.write(template.render(path,template_info))
def post(self,token): self.head() self.response.headers['Content-Type'] = 'text/html' if not validate_user(self) or self.request._user.status != 'staff': self.response.write('Only staff members can edit users.') return email = self.request.get('email').strip() last_name = self.request.get('last_name').strip() first_name = self.request.get('first_name').strip() mit_id = self.request.get('mit_id').strip() section = self.request.get('section').strip() status = self.request.get('status').strip() reset_password = self.request.get('reset_password').strip() message = '' user = find_user(None,email=email) if len(last_name) != 0: if user is None: message = "User %s doesn't exist." % email elif len(last_name) == 0: message = 'Last name cannot be blank.' elif len(mit_id) != 9 or mit_id[0] != '9' or not mit_id.isdigit(): message = 'MIT ID must be 9 digits, starting with a "9".' else: user.last_name = last_name user.first_name = first_name user.mit_id = mit_id user.section = section user.status = status if reset_password: user.password = hash_password(email,mit_id), user.put() # display a form for editing user info template_file = 'templates/edit_user.html' template_info = { 'url': self.request.url, 'status_url': self.request.url[:self.request.url.find('/user/edit_user')], 'message': message, 'sections': course.sections, 'user': user, 'scores': grades.scores(email), 'assignments': course.assignments, 'actions': grades.get_scores(email), } path = os.path.join(os.path.dirname(__file__), template_file) self.response.write(template.render(path,template_info))