Beispiel #1
0
	def load_userdata_into_session(session):
		if 'user' in session:
			user = session['user']
		#	 is user in the userdata table? else make it and go to the settings page
			userdata = UserData.get_by_user(user)
			if userdata is None:
				userdata = UserData()
				userdata.usercode = Usercode().new_code()
				userdata.user = user
				userdata.email = user.email()
				userdata.nickname = user.nickname()
				userdata.apikey = Apikey().new_code()
				userdata.pastes_hidden_by_default = False
				userdata.put()
				session['redirect'] = '/settings'
				session['flash'] = 'Maybe you\'d like to change your default settings. If not, <a href="/">paste away</a>.'
			session['usercode'] = userdata.usercode
			session['nickname'] = userdata.nickname
			session['email'] = userdata.email
			session['pastes_hidden_by_default'] = userdata.pastes_hidden_by_default
			session['friends_hidden_by_default'] = userdata.friends_hidden_by_default
			session['num_friend_requests'] = FriendRequest.get_number_of_requests(userdata.usercode)
			session['got_userdata'] = True
		else:
			session['nickname'] = 'Anonymous'
			session['pastes_hidden_by_default'] = False
			session['friends_hidden_by_default'] = False
			session['num_friend_requests'] = 0
			session['got_userdata'] = False
		return session
Beispiel #2
0
	def get_session(request_uri):
		session = sessions.Session()
		user = users.get_current_user()
		session['login_url'] = users.create_login_url(request_uri)
		session['logout_url'] = users.create_logout_url(request_uri)
		if 'user' in session and session['user'] != user:
			session.delete()
			session = sessions.Session()
		if user is None:
			return PersistentRequestHandler.load_userdata_into_session(session)
		else:
			session['user'] = user
			if 'got_userdata' in session and session['got_userdata']:
				session['num_friend_requests'] = FriendRequest.get_number_of_requests(session['usercode'])
				return session
			return PersistentRequestHandler.load_userdata_into_session(session)