Beispiel #1
0
def get_user_info(request):
    logging.debug('iframe got get: %s' % request.GET)
    logging.debug('appname is %s' % settings.XIAONEI_APP_NAME)
    xn = request.xiaonei
    xn.check_session(request)
    user = XnUser.get_by_key_name('uid:'+xn.uid)
    if not user.sex:
        logging.debug('no extra user info yet. trying to get now')
        try:
            user_info = xn.users.getInfo(uids=[xn.uid], fields=['name','sex','headurl','birthday','hometown_location'])[0]
            logging.debug('got userinfo: %s' % user_info)
        except XiaoneiError, e:
            logging.error('Failed calling users.getinfo')
            logging.error(e)
            return HttpResponse('error with users.getinfo', mimetype='text/html')
        except:
Beispiel #2
0
def get_or_create_xnuser(xn):
    """Utility function
    Get XnUser if already exists,
    Otherwise, call xn api to get user info and create XnUser instance
    @param xn: An authenticated Xiaonei instance 
    """
    #use memcache to cache the user instance
    user = memcache.get(xn.uid)
    if not user:
        user = XnUser.get_by_key_name('uid:'+xn.uid)
        if user is None:
            logging.debug('no user found in db, getting userinfo again')
            try:
                user_info = xn.users.getInfo(uids=[xn.uid], fields=['name'])[0]
                logging.debug('got userinfo: %s' % user_info)
            except XiaoneiError, e:
                logging.error('Failed calling users.getinfo')
                logging.error(e)
                raise
            except:
Beispiel #3
0
def get_user_by_uid(uid):
    return XnUser.get_by_key_name('uid:'+uid)
Beispiel #4
0
 except:
     logging.error('Unknown error while calling users.getinfo')
     exception = sys.exc_info()[0]
     logging.exception(exception)
     raise
 else:
     birthday = user_info['birthday']
     if birthday:
         year, month, day = birthday.split('-')
         logging.debug('got year: %s, month: %s, day: %s' % (year, month, day))
 try:
     user, created = XnUser.get_or_insert_by_uid(xn.uid, 
                                                 username=user_info['name'], 
                                                 sex=int(user_info['sex']),
                                                 pic_url=user_info['headurl'], 
                                                 birth_year=year,
                                                 birth_month=month,
                                                 birth_day=day,
                                                 home_country=user_info['hometown_location'].get('country',''),
                                                 home_province=user_info['hometown_location'].get('province',''),
                                                 home_city=user_info['hometown_location'].get('city',''))
 except BadValueError, e:
     logging.error('Failed to save user data: %s' % e)
     raise
 except:
     logging.error("Unexpected error while creating user")
     exception = sys.exc_info()[0]
     logging.exception(exception)
     raise
 else:
     logging.debug('got user[created: %s]: %s' % (created,user.username))
     friends = friends_get(xn)
Beispiel #5
0
def get_user_from_db(uid):
    return XnUser.get_by_key_name('uid:'+uid)
Beispiel #6
0
     logging.debug('no user found in db, getting userinfo again')
     try:
         user_info = xn.users.getInfo(uids=[xn.uid], fields=['name'])[0]
         logging.debug('got userinfo: %s' % user_info)
     except XiaoneiError, e:
         logging.error('Failed calling users.getinfo')
         logging.error(e)
         raise
     except:
         logging.error('Unknown error while calling users.getinfo')
         exception = sys.exc_info()[0]
         logging.exception(exception)
         raise
         
     try:
         user, created = XnUser.get_or_insert_by_uid(xn.uid, username=user_info['name'])
     except BadValueError, e:
         logging.error('Failed to save user data: %s' % e)
         raise
     except:
         logging.error("Unexpected error")
         raise
     else:
         logging.debug('got user[created: %s]: %s' % (created,user.username))
 else:
     logging.debug('user exists in db')
     try:
         if user.friends:
             logging.debug('purge remaining friends data')
             user.friends = None
     except: