def get(self): user = users.get_current_user() if user or get_testing(): if get_testing(): userPerms = Permissions() userPerms.role = 2 else: userPerms = get_permissions(users.get_current_user().user_id()) if userPerms: role = userPerms.role else: role = 0 if self.request.get('key') and role >= 1: try: k = db.Key(encoded=self.request.get('key')) result = db.get(k) db.delete(result) self.response.out.write(json.dumps(True)) except: self.response.out.write(json.dumps(False)) else: self.response.out.write(json.dumps(False)) else: self.redirect("/")
def get(self): user = users.get_current_user() if user or get_testing(): if get_testing(): userPerms = Permissions() userPerms.role = 2 else: userPerms = get_permissions(str(users.get_current_user().user_id())) if userPerms: role = userPerms.role else: role = 0 if role >=2: name = self.request.get('name') if name: new_section = Section() new_section.name = name new_section.put() out = {} out['sID']=str(new_section.key()) self.response.out.write(json.dumps(out)) #currently not used b/c there's no callback that gets the sections & outputs them. It's only internal right now. else: self.response.out.write(json.dumps(False)) #currently not used self.redirect("/admin") #if ajax updating of admin page is implemented, we should delete this. else: self.redirect("/") else: self.redirect("/")
def get(self): TOKEN = gdata.gauth.AeLoad(users.get_current_user().user_id()) if TOKEN: client = gdata.docs.client.DocsClient(source=SETTINGS['APP_NAME']) client.auth_token = gdata.gauth.AeLoad(users.get_current_user().user_id()) #could try to put back as TOKEN? self.response.out.write('moo baby') client.ssl = True feed = client.GetDocList(auth_token=gdata.gauth.AeLoad(users.get_current_user().user_id())) #auth_token=TOKEN self.response.out.write(feed) self.response.out.write('moo boobob') self.response.headers['Content-Type'] = 'text/plain' for entry in feed.entry: self.response.out.writeln(entry.title.text) else: # Get unauthorized request token gdata.gauth.AeDelete(users.get_current_user().user_id()) client = gdata.docs.client.DocsClient(source=SETTINGS['APP_NAME']) client.ssl = True # Force communication through HTTPS oauth_callback_url = ('http://%s/get_oauth_token' % self.request.host) request_token = client.GetOAuthToken( SETTINGS['SCOPES'], oauth_callback_url, SETTINGS['CONSUMER_KEY'], consumer_secret=SETTINGS['CONSUMER_SECRET']) gdata.gauth.AeSave(request_token, "tmp_"+users.get_current_user().user_id()) # Authorize request token domain = None#'cornellsun.com' self.redirect(str(request_token.generate_authorization_url(google_apps_domain=domain)))
def get(self): # We don't reference users with Deskers - b/c sometimes editors use share accounts (i.e. news-editor, etc.). So we just use names user = users.get_current_user() if user or get_testing(): #if a user is logged in. I would have used @logged_in but OpenId doesn't play nice with it. Oh well. if get_testing(): userPerms = Permissions() userPerms.role = 2 else: userPerms = get_permissions(str(users.get_current_user().user_id())) if userPerms: role = userPerms.role else: role = 0 if role >=1: #check the permissions. This pattern is repeated for most of the functions. Again, would have used @logged_in but OpenId doesn't like it name = self.request.get('name') section = self.request.get('section') date = self.request.get('date') if name and section and date: new_desker = Desker() new_desker.name = name new_desker.section = section new_desker.date = datetime.strptime(date,"%Y-%m-%d") new_desker.put() out = {} out['dID']=str(new_desker.key()) self.response.out.write(json.dumps(out)) else: #if bad permissions, do this self.response.out.write(json.dumps(False)) else: #if user isn't logged in, do this self.redirect("/")
def get(self): #not sure what to do for this right now. Maybe have stuff #for editing sections & users? #important to set permissions for deskers - the possible deskers that show up are the ones that #have permissions for that section user = users.get_current_user() if user or get_testing(): if get_testing(): userPerms = Permissions() userPerms.role = 2 else: userPerms = get_permissions(str(users.get_current_user().user_id())) if userPerms: role = userPerms.role else: role = 0 if role >=2: template_values = { 'sections': get_section_list(), 'user': user, 'login_url': "/apps_login?domain=cornellsun.com", 'logout_url': users.create_logout_url('/') } path = os.path.join(os.path.dirname(__file__), 'templates/admin.html') self.response.out.write(template.render(path, template_values)) else: self.redirect("/") else: self.redirect("/apps_login?domain=cornellsun.com")
def get(self): aID = self.request.get('aID') assignment = get_ass_from_memcache(aID) #Do I want to make this function work for getting the week as well as just one? #Then I'd have to add a 'self.request.get('week')' if statement. Screw it for now. out_assignment = {} curPerms = None assigned = None if users.get_current_user() or get_testing(): if get_testing(): curPerms = Permissions() curPerms.role = 2 else: curPerms = get_permissions(str(users.get_current_user().user_id())) assigned = get_assigned(str(users.get_current_user().user_id()),str(assignment.key())) #I am assuming that staffers don't have permissions if curPerms is not None or assigned is not None: out_assignment = to_dict(assignment) elif assignment.public == True: #no status, weight, docLink, public out_assignment = to_dict(assignment) del out_assignment['status'] del out_assignment['weight'] del out_assignment['docLink'] del out_assignment['public'] else: out_assignment['dueDate'] = assignment.dueDate.strftime("%Y-%m-%d") out_assignment['title'] = "You may not view this assignment. Please ask to be assigned to it or have your editor make it publicly viewable" out_assignment['aID'] = str(assignment.key()) self.response.out.write(json.dumps(out_assignment))
def get(self): if users.get_current_user(): TOKEN = gdata.gauth.AeLoad(users.get_current_user().user_id()) else: TOKEN = None if TOKEN: check_token = False else: check_token = True template_values = { #'check_token' = check_token, 'aID': self.request.get('aID'), } path = os.path.join(os.path.dirname(__file__), 'assignment.html') self.response.out.write(template.render(path, template_values))
def get(self): WeekData = get_week_details(datetime.today().isocalendar()[1],datetime.today().strftime("%Y"),1) if users.get_current_user(): userInfo = UserInfo.all().filter("uID =",str(users.get_current_user().user_id())).fetch(1) userPerms = get_permissions(str(users.get_current_user().user_id())) TOKEN = gdata.gauth.AeLoad(users.get_current_user().user_id()) role = 0 elif get_testing(): userInfo = [] new_userInfo = UserInfo() new_userInfo.prefSection = str(Section.all().fetch(1)[0].key()) userInfo.append(new_userInfo) userPerms = Permissions() userPerms.role = 2 TOKEN = None else: userPerms = None TOKEN = None role = 0 userInfo = None if userPerms: role = userPerms.role if userInfo: prefSection = userInfo[0].prefSection else: prefSection = str(Section.all().fetch(1)[0].key()) # this must be changed based on the Default model that the admin sets if TOKEN: check_token = False else: check_token = True user = users.get_current_user() template_values = { 'user': user, #if user is none, nobody here 'login_url': "/apps_login?domain=cornellsun.com", 'check_token': check_token, 'logout_url': users.create_logout_url('/'), 'start_day': WeekData[0], 'end_day': WeekData[1], 'role': role, #0= not logged in, 1=editor, 2=admin 'prefSection': prefSection, 'sections': get_section_list() } path = os.path.join(os.path.dirname(__file__), 'templates/dashboard.html') self.response.out.write(template.render(path, template_values))
def get(self, id): user = users.get_current_user() if not user: self.redirect(users.create_login_url(self.request.uri)) return logging.warn("Logged in as %s (%s)", user.nickname(), user.user_id()) self.render_to_response("story_edit.html", story=Story.get_by_id(int(id, 10)), request_too_large_error=False)
def get(self): user_id = users.get_current_user().user_id() saved_request_token = gdata.gauth.AeLoad("tmp_"+user_id) gdata.gauth.AeDelete ("tmp_" + user_id) request_token = gdata.gauth.AuthorizeRequestToken(saved_request_token, self.request.uri) #upgrade the token access_token = client.GetAccessToken(request_token) #save the upgraded token gdata.gauth.AeSave(access_token, user_id) self.redirect('/test')
def post(self): out = None if users.get_current_user(): fullprofile = False if not self.request.params.get('profile', False) else True self.response.headers['Content-Type'] = 'application/json' out = UserProfile().brief() else: cont = self.request.params.get('continue', "/") out = {'login_url': users.create_login_url(cont)} self.response.out.write(simplejson.dumps(out))
def __init__(self): self.user = users.get_current_user() m = md5.new() m.update(self.user.email().strip().lower()) self.user.md5 = str(m.hexdigest()) self.key = db.Key.from_path('UserModel',str(self.user.user_id())) self.model = UserModel.get(self.key) if self.model is None: """if the user isn't in the UserModel table, create a new entry""" self.model = UserModel(key=self.key)
def get(self): user = users.get_current_user() logins = LoginRecord.all().order('-timestamp').fetch(20) logging.warn([x.user for x in logins]) self.render_template("index.html", { 'login_url': users.create_login_url('/login'), 'logout_url': users.create_logout_url('/'), 'user': user, 'logins': logins, })
def post(self, eventid): # We use locals() which confuses pylint. # pylint: disable-msg=W0612 #################################################### event = models.Event.get_by_id(long(eventid)) if not event: self.redirect('/') current_user = openid_users.get_current_user() if not current_user: self.redirect('/') return #################################################### response, guests = event_lists.get_event_responses(event, current_user) # Check if the person is trying to add friends try: extra_guests = range( 0, int(self.request.get('friends', '0'))-len(guests)) except ValueError: extra_guests = [] if extra_guests: self.response.out.write(render( 'templates/response-friends.html', locals())) return # Remove the current information if response is not None: response.delete() for guest in guests: guest.delete() response = models.Response(event=event, guest=False) response.attending = self.request.get('attending').lower() != 'no' response.put() guest_names = self.request.get_all('guest_name') guest_emails = self.request.get_all('guest_email') assert len(guest_names) == len(guest_emails) for name, email in zip(guest_names, guest_emails): name, email = name.strip(), email.strip() if not name or not email: continue response = models.Response(event=event, guest=True) response.attending = True response.guest_name = name response.guest_email = email response.put() self.redirect('/event/%s/response/show' % event.key().id())
def get(self): session = get_current_session() session['fileID'] = urllib.unquote(self.request.get('fileID')) if not session['fileID']: session['fileID'] = "changeThis.txt" #user: session['user'] = str(users.get_current_user()) if self.request.get('auth') != 'true': session['user'] = str(datetime.datetime.now()) else: if not users.get_current_user(): self.redirect(users.create_login_url(self.request.uri)) session['data'] = "Please wait while the app loads..." template_values = {'user': session['user'], 'fileID': session['fileID'], 'data' : session['data']} path = os.path.join(os.path.dirname(__file__), 'index.html') self.response.out.write(template.render(path, template_values))
def get(self): user = users.get_current_user() if user or get_testing(): if get_testing(): userPerms = Permissions() userPerms.role = 2 else: userPerms = get_permissions(users.get_current_user().user_id()) if userPerms: role = userPerms.role else: role = 0 if self.request.get("aID") and self.request.get("email"): aID = self.request.get("aID") email = self.request.get("email") curAssignees = Assignee.all().filter("aID =",aID) in_datastore = False #check if assignee is already assigned for assignee in curAssignees: if assignee == email: in_datastore == True; if not in_datastore: assignee = Assignee() assignee.assignment = aID assignee.assignee = email assignee.put() out = to_dict(assignee) self.response.out.write(json.dumps(out)) else: self.response.out.write(json.dumps(False)) else: self.redirect("/")
def get(self): start_day = self.request.get('start_day') end_day = self.request.get('end_day') section = self.request.get('section') assignments = Assignment.all().filter("dueDate >=",datetime.strptime(start_day,"%Y-%m-%d")).filter("dueDate <=",datetime.strptime(end_day,"%Y-%m-%d")).order('dueDate').order('weight') if self.request.get('section'): assignments.filter("section =",section) out_assignments = [] out_assignment = {} curPerms = None assigned = None if users.get_current_user() or get_testing(): if get_testing(): curPerms = Permissions() curPerms.role = 2 assigned = None else: curPerms = get_permissions(str(users.get_current_user().user_id())) #I am assuming that staffers don't have permissions assigned = get_assigned(str(users.get_current_user().user_id()),str(assignment.key())) #This is necessary to check permissions [if it's assigned to a staffer, that staffer can see it] for a in assignments.fetch(1000): if curPerms is not None or assigned is not None: #put back '' when we use permissions and assigned again out_assignment = to_dict(a) elif a.public == True: #no status, weight, docLink, public out_assignment = to_dict(assignment) del out_assignment['status'] del out_assignment['weight'] del out_assignment['docLink'] del out_assignment['public'] else: #break - put the break in b/c later we don't want to have all these "can't view this" signs out_assignment['dueDate'] = a.dueDate.strftime("%Y-%m-%d") out_assignment['title'] = "You may not view this assignment. Please ask to be assigned to it or have your editor make it publicly viewable" out_assignment['aID'] = str(a.key()) out_assignments.append(out_assignment) self.response.out.write(json.dumps(out_assignments))
def get(self): session = get_current_session() session['fileID'] = urllib.unquote(self.request.get('fileID')) if not session['fileID']: session['fileID'] = "changeThis.txt" #user: session['user'] = str(users.get_current_user()) if self.request.get('auth') != 'true': session['user'] = str(datetime.datetime.now()) else: if not users.get_current_user(): self.redirect(users.create_login_url(self.request.uri)) session['data'] = "Please wait while the app loads..." template_values = { 'user': session['user'], 'fileID': session['fileID'], 'data': session['data'] } path = os.path.join(os.path.dirname(__file__), 'index.html') self.response.out.write(template.render(path, template_values))
def get(self, key=None): if not key: key = self.request.get('id') key = long(key) event = models.Event.get_by_id(key) current_user = openid_users.get_current_user() response, guests = event_lists.get_event_responses(event, current_user) self.response.headers['Content-Type'] = 'text/html' self.response.out.write(r( 'templates/event.html', locals()))
def get(self): user = users.get_current_user() if user or get_testing(): assignment = self.request.get('assignment') if get_testing(): uID = str(users.User('*****@*****.**').user_id()) else: uID = str(users.get_current_user().user_id()) if assignment: pickup = PickUp() pickup.uID = uID pickup.requested = datetime.now() pickup.assignment = assignment pickup.put() out = {} out['pickupID'] = str(pickup.key()) self.response.out.write(json.dumps(out)) else: self.response.out.write(json.dumps(False)) else: self.redirect("/")
def get(self): user = users.get_current_user() if user or get_testing: if get_testing(): userPerms = Permissions() userPerms.role = 2 else: #this is the userPerms for the user trying to change other users permissions userPerms = get_permissions(str(users.get_current_user().user_id())) if userPerms: role = userPerms.role else: role = 0 if role >=2: if self.request.get('userEmail'): #have to have something to input/edit user = users.User(self.request.get('userEmail')) #has to be a valid google account. #this is now the userPerms for the user who is being modified userPerms = get_permssions(str(user.user_id())) if not userPerms: #look @ CreateModifyUserPrefs for explanation of what's going on here userPerms = Permissions() else: userPerms = userPerms[0] userPerms.uID = str(user.user_id()) if self.request.get('role'): userPerms.role = self.request.get('role') if self.request.get('section'): userPerms.section = self.request.get('section') userPerms.put() out = {} out['uPermsKey'] = str(userPerms.key()) self.redirect("/admin") #self.response.out.write(json.dumps(out)) if we were doing ajax, we would use this. However, we are not, and thus we're just redirecting to /admin else: self.response.out.write(json.dumps(False)) else: self.redirect("/") else: self.redirect("/")
def get(self, eventid): #################################################### event = models.Event.get_by_id(long(eventid)) if not event: self.redirect('/') current_user = openid_users.get_current_user() if not current_user: self.redirect('/') return #################################################### response, guests = event_lists.get_event_responses(event, current_user) self.response.out.write(render( 'templates/response-show.html', locals()))
def get(self): user = users.get_current_user() if user or get_testing(): if get_testing(): userInfo = UserInfo() userInfo.uID = str(users.User("*****@*****.**").user_id()) else: userInfo = UserInfo.all().filter('uID =', str(users.get_current_user().user_id())).fetch(1) if not userInfo: #if there is no record, make a new record userInfo = UserInfo() else: #if there is a record, userInfo is currently an array. We need to get the object out of the array userInfo = userInfo[0] if self.request.get('phone'): userInfo.phone = self.request.get('phone') if self.request.get('section'): userInfo.prefSection = self.request.get('section') userInfo.put() out = {} out['uInfoKey'] = str(userInfo.key()) self.response.out.write(json.dumps(out)) else: self.redirect("/")
def get(self): user = users.get_current_user() if user or get_testing(): if get_testing(): userInfo = None else: userInfo = UserInfo.all().filter("uID =",users.get_current_user().user_id()).fetch(1) if userInfo: template_values = { 'prefSection': userInfo.prefSection, 'phone': userInfo.phone, 'sections': get_section_list() } else: template_values = { 'prefSection': "", 'phone': "", 'sections': get_section_list() } path = os.path.join(os.path.dirname(__file__), 'templates/pref.html') self.response.out.write(template.render(path, template_values)) else: self.redirect("/apps_login?domain=cornellsun.com")
def get(self): user = users.get_current_user() if not user: self.redirect(users.create_login_url(self.request.uri)) return logging.info("User: nickname: %s, email: %s", user.nickname(), user.email()) #from api_preferences import facebook as fb_prefs, google_friend_connect as gfc self.render_to_response("start.html", #FACEBOOK_API_KEY=fb_prefs.get('api_key'), #FACEBOOK_CROSS_DOMAIN_RECEIVER_URL=fb_prefs.get('cross_domain_receiver_url'), #GOOGLE_FRIEND_CONNECT_SITE_ID=gfc.get('site_id'), request_too_large_error=False, logout_url=users.create_logout_url(self.request.uri), email=user.email(), nickname=user.nickname())
def get(self, year=None, month=None, day=None): now = datetime.datetime.now() if users.is_current_user_admin(): published_only=False else: published_only=True current_user = openid_users.get_current_user() events_lists = event_lists.get_event_lists( published_only=published_only, user=current_user) next_event = event_lists.get_next_event() self.response.headers['Content-Type'] = 'text/html' self.response.out.write(r( self.template, locals()))
def render(t, kw): req = kw['self'].request extra = { 'req': req, 'openid_user': openid_users.get_current_user(), 'openid_login_jsurl': openid_users.create_login_url('/refresh'), 'openid_login_url': openid_users.create_login_url(req.path), 'openid_logout_url': openid_users.create_logout_url(req.path), 'appengine_user': appengine_users.get_current_user(), 'appengine_admin': appengine_users.is_current_user_admin(), 'appengine_logout_url': appengine_users.create_logout_url(req.path), } # Don't let people trample on these variables common = set(extra.keys()).intersection(kw.keys()) if common: raise SystemError('The following keys are reserved %s' % common) kw.update(extra) return template.render(t, kw)
def get(self): user = users.get_current_user() if user or get_testing(): if get_testing(): userPerms = Permissions() userPerms.role = 2 else: userPerms = get_permissions(str(users.get_current_user().user_id())) if userPerms: role = userPerms.role else: role = 0 #We assume that we're going to get good keys for now. mod = False #if we are modifying the data, or creating it if role >= 1: if not self.request.get('aID'): assignment = Assignment() assignment.created = datetime.now() assignment.creator = 'mooman'#users.get_current_user().user_id() PUT BACK OH YEAHHHHH else: assignment = get_ass_from_memcache(self.request.get('aID')) mod = True if self.request.get('title'): assignment.title = self.request.get('title') elif not mod: # so if mod is false (we are creating a new assignment), # and there was no input, set value to default # but if mod is true, and there was no input, keep value the same (i.e. do nothing) assignment.title = "" if self.request.get('descript'): assignment.descript = self.request.get('descript') elif not mod: assignment.descript = "" if self.request.get('status'): assignment.status = self.request.get('status') elif not mod: assignment.status = "" if self.request.get('dueDate'): assignment.dueDate = datetime.strptime(self.request.get('dueDate'),"%Y-%m-%d") elif not mod: oneDay = timedelta(days=1) tomorrow = datetime.today()+oneDay assignment.dueDate = tomorrow if self.request.get('weight'): assignment.weight = int(self.request.get('weight')) elif not mod: assignment.weight = 0 if self.request.get('section'): assignment.section = self.request.get('section') elif not mod: assignment.section = "" if self.request.get('docLink'): #methinks there will be a lot of stuff that goes into this. this is not right as is assignment.docLink = self.request.get('docLink') elif not mod: assignment.docLink = "" assignment.modified = datetime.now() if self.request.get('creator'): assignment.creator = self.request.get('creator') elif not mod: assignment.creator = "" if self.request.get('public'): if self.request.get('public') == "True": assignment.public = True else: assignment.public = False elif not mod: assignment.public = False assignment.put() #this fixes the issue of memcache and datastore being out of sync memcache.set(self.request.get('aID'),assignment) new_assignee_IDs = [] out = {} new_assignee = False if self.request.get_all('uID'): #the assignee routine. To delete, use DeleteEntity for passed_assignee in self.request.get_all('uID'): in_datastore = False assignees = Assignee.all().filter("assignment =",str(assignment.key())).fetch(1000) if assignees: for assignee in assignees: if str(assignee.assignee) == passed_assignee: in_datastore = True if in_datastore == False: new_assignee = Assignee() new_assignee.assignment = str(assignment.key()) new_assignee.assignee = passed_assignee new_assignee.put() new_assignee_IDs.append(str(new_assignee.key())) out = to_dict(assignment) out['aID']=str(assignment.key()) if new_assignee: out['assigneeIDs'] = new_assignee_IDs out['uIDs'] = self.request.get_all('uID') self.response.out.write(json.dumps(out)) else: self.redirect("/") else: self.redirect("/")
def get(self): if users.get_current_user(): login = LoginRecord() logging.warn(login.user) login.put() self.redirect('/')