def obj_create(self, bundle, **kwargs): # get the API key associated with the request apikey = api.auth.DatabaseAuthentication().get_identifier( bundle.request) # try and get an existing user try: bundle.obj = User.objects.get(email=bundle.data['email']) # no existing user, create them except User.DoesNotExist as e: if 'password' not in bundle.data: kwargs['password'] = User.generate_password( api.auth.get_nonce(32)) bundle = super(UserResource, self).obj_create(bundle, **kwargs) # create a new account entry account = Account() account.api_account = apikey.account # set the api key's account as the creator account.save() # add the user as an admin to the new account accountuser = AccountUser(account=account, user=bundle.obj, is_admin=True) accountuser.save() return bundle
def getFollowers(self, account = None): if account: return Account.gql("WHERE following = :1", account.key()) elif self.account: return Account.gql("WHERE following = :1", self.account.key()) else: return None
def obj_create(self, bundle, **kwargs): bundle = super(UserResource, self).obj_create(bundle, **kwargs) # create a new account entry and set the new user as the admin account = Account() account.save() # add the user as an admin to the new account accountuser = AccountUser(account=account, user=bundle.obj, is_admin=True) accountuser.save() return bundle
def get(self): user = users.get_current_user() if user: account = Account.gql("WHERE userId = :1", user.user_id()).get() if account: self.redirect('/') else: self.redirect('/register') else: self.redirect(users.create_login_url(self.request.uri))
def get(self): current_user = users.get_current_user() account = Account.gql("WHERE userId = :1", current_user.user_id()).get() newUsers = Account.gql("WHERE regDate > :1 ORDER BY regDate", account.lastSeen) account.put() # Template values, yay! template_values = { 'tab': 'admin', 'usernick': account.nickname, 'is_admin': True, 'newUserCount': newUsers.count(), 'newUsers': newUsers } # We get the template path then show it path = os.path.join(os.path.dirname(__file__), '../views/admin.html') self.response.out.write(template.render(path, template_values)) # I still haven't understood why we need to make the path...
def create_account(session): account = Account(first_name=names.get_first_name(), last_name=names.get_last_name()) session.add(account) password_generator = PasswordGenerator() authentication = Authentication(account=account, login='******'.format( account.first_name, account.last_name).lower(), password=password_generator.generate()) session.add(authentication) session.commit() return account
def get(self, nickname): account = Account.gql("WHERE nickname = :1", nickname).get() messages = Message.gql("WHERE author IN :1 ORDER BY date DESC LIMIT 10", account.following) template_values = { 'title': nickname + '\'s feed', 'link': 'http://pintme.appspot.com/user/' + nickname, 'description': 'Personnal user feed for ' + nickname, 'items': messages } # We get the template path then show it path = os.path.join(os.path.dirname(__file__), '../views/rss.xml') self.response.out.write(template.render(path, template_values))
def get(self, nickname): # Get the users account using nickname called_user = Account.gql("WHERE nickname = :1", nickname).get() if called_user: if called_user.avatar: self.response.headers['Content-Type'] = "image/jpg" data = memcache.get('avatar'+nickname) if data is None: data = called_user.avatar.data memcache.add('avatar'+nickname, data, 60) self.response.out.write(data) else: self.response.headers['Content-Type'] = "image/gif" self.response.out.write(open('zoid.gif','rb').read()) else: self.response.headers['Content-Type'] = "image/gif" self.response.out.write(open('zoid.gif','rb').read())
def post(self): # Query: search & result list search = self.request.get('search') # Convert the search to lower case search = string.lower(search) results = list() # Make a loop to find results results_query = Account.all() for result in results_query: if string.lower(result.nickname) == search: results.append(result) # If there's no result 'not results' is True template_values = { 'no_result': not results, 'results': results } # We get the template path then show it path = os.path.join(os.path.dirname(__file__), '../views/search_result.html') self.response.out.write(template.render(path, template_values))
def get(self): token = self.request.get('token') if token == '': self.redirect('/settings') user = users.get_current_user() account = Account.gql("WHERE userId = :1", user.user_id()).get() sg = SessionKeyGenerator(__lastfmApiKey__, __lastfmApiSecret__) session_key = sg.get_web_auth_session_key_with_token(token) lastfm = LastFm() lastfm.sessionKey = session_key lastfm.put() account.lastFm = lastfm.key() account.put() authedUser = get_authenticated_user(__lastfmApiKey__, __lastfmApiSecret__, session_key) lastfm.userName = authedUser.get_name() lastfm.put() self.redirect('/settings')
def post(self): # Declaration: new Account # Query: nickname new_user = Account() nickname = self.request.get('nickname') if len(nickname) < 3: self.redirect('/register') # Query: nickname taken ? nick_taken = Account.gql("WHERE nickname = :1", nickname).get() if nick_taken: self.redirect('/register') else: # If not let's create the new user ! new_user.userId = users.get_current_user().user_id() new_user.nickname = nickname new_user.put() self.redirect('/')
def getFromNickname(self, nickname): nickAccount = Account.gql( "WHERE nickname = :1", nickname ).get() if nickAccount: self.account = nickAccount
def getFromSession(self): user = users.get_current_user() if user: self.account = Account.gql("WHERE userId = :1", user.user_id()).get()