def create(self, **kw): request_handler = kw.get('request_handler') user = User() user.username = kw.get('username') user.email = kw.get('email') user.is_staff = True user.is_superuser = False user.is_active = True try: EmailHelper.validateEmail(user.email) except Exception, e: logging.exception(e); return self.render_to_json({'status': 'error', 'msg': 'Invalid email.'}, request_handler)
def _get_facebook_friends(self, user): fb_friends = [] profile = User.get_profile(user.id) if profile: token = simplejson.loads(profile.tokens)['facebook'] #TODO - resolver problema de cache do UserProfile url = 'https://graph.facebook.com/me/friends?access_token=%s' % token response = MSSCurl().get(url=url) for user in response['data']: #profile = MSSCurl().get(url='https://graph.facebook.com/%s' % user['id']) fb_friends.extend(self._get_related_friends(user['name'])) return fb_friends
def _get_twitter_friends(self, user): tw_friends = [] profile = User.get_profile(user.id) if profile: token = simplejson.loads(profile.tokens)['twitter'] consumer_key = "f1j3JookvHIoe2MBL7HEg" consumer_secret = 'kdgLHtmyFh24UVIDIBtFRC9T5LUlRhgtCskIlG1P08' access_token_key = '353770828-OeTG1nMJEuMHIKEdVQvrFloXnI9hcUXBROZ8oyiX' access_token_secret = 'u30TQhtFmWB9bKgyXrhJ7SNLGuuxO2n3dJfswv66k' api = twitter.Api(consumer_key, consumer_secret, access_token_key, access_token_secret) try: users = api.GetFriends('sauloaride') except twitter.TwitterError, e: logging.exception("Can not get twitter friends on %s" % e) for user in users: tw_friends.extend(self._get_related_friends(user.name))
def authenticated_fn(self, *args, **kw): request_handler = kw.get('request_handler') cache = get_cache() username = cache.get(kw.get('auth')) if not username: return self.render_to_json( { 'status': 'error', 'msg': 'User not authenticated.' }, request_handler) else: user = User().get_by(username=username) if not user: return self.render_to_json( { 'status': 'error', 'msg': 'User not authenticated.' }, request_handler) return fn(self, user=user, *args, **kw)
def _get_related_friends(self, name): return User.search(name.split(' '))
def _get_mss_users(self): return User.all()
def create_user(last_name='should-be-last-name-1', first_name='test_create_user-1', email='should-be-email', username='******'): user = User() user.last_name = last_name user.first_name = first_name user.username = username user.gender = User._MALE user.created = datetime.now() user.last_login = datetime.now() user.email = email user.is_staff = False user.is_superuser = False user.is_active = True password = '******' m = hashlib.sha1() m.update(password) user.password = '******' + m.hexdigest() user.save() return user
def test_user_can_be_saved(): session = get_session() user = User() user.last_name = 'should-be-last-name' user.first_name = 'should-be-first-name' user.username = '******' user.created = datetime.now() user.last_login = datetime.now() user.password = '******' user.gender = 'M' user.email = 'should-be-email' user.is_staff = False user.is_superuser = False user.is_active = True user.save() user_db = session.query(User).filter( User.username == 'should-be-username').first() assert user_db.username == user.username user_db.delete()