Пример #1
0
def register(email, password):
    """
        Register a user
        returns True if sucessful
    """
    try:
        u = User(email=email, password=password)
        u.send_confirm_code()
        u.put()
        if u is not None:
            return True    
    except:
        pass
    raise Exception(GeoException.BAD_EMAIL_PASSWORD)
Пример #2
0
class UserProfileHelper(object):
    def get_by_id(self, userid, async=False):
        try:
            userid = long(userid)
        except:
            return None
        key = db.Key.from_path(User.kind(), userid, UserProfile.kind(),
                               'profile_%s' % userid)
        return UserProfile.get(key)
Пример #3
0
class UserSettingsHelper(object):
    def get_by_id(self, userid, async=False):
        try:
            userid = long(userid)
        except:
            return None
        key = db.Key.from_path(User.kind(), userid, UserSettings.kind(),
                               'settings_%s' % userid)
        return UserSettings.get(key)
Пример #4
0
 def authenticate(self):
     """Permite al usuario loguear con twitter"""
     twitterInfo = self.get_user_info()
     user = TwitterUser.objects.get_by_id(twitterInfo['id'])
     if user is not None:#el usuario ya existe, iniciamos sesion
         user = user.user
         self.authorize(user)
     else:#no existe, creamos un nuevo usuario
         user = User.register(password=make_random_string(length=6))
         self.authorize(user)
     return user
Пример #5
0
class UserCounterHelper(object):
    def get_by_id(self, userid, async=False):
        try:
            userid = long(userid)
        except:
            return None
        key = db.Key.from_path(User.kind(), userid, UserCounter.kind(),
                               'counters_%s' % userid)
        if async:
            return db.get_async(key)
        return UserCounter.get(key)
Пример #6
0
def _get_all_users(offset = 0):
    """
        Obtiene las urls de las sugerencias
    """
    keys = []
    q = User.all().filter('username !=', None)
    users = q.fetch(offset=offset, limit=500)
    keys.extend(users)
    if len(users) >= 500:
        users = q.fetch(offset=500, limit=500)
        keys.extend(users)
        offset += 500
    return [x.get_absolute_url() for x in keys]
Пример #7
0
 def authenticate(self):
     """Permite al usuario loguear con twitter"""
     twitterInfo = self.get_user_info()
     user = TwitterUser.objects.get_by_id(twitterInfo['id'])
     if user is not None:#el usuario ya existe, iniciamos sesion
         self.user = user.user
         auth = self.authorize()
         if not auth:
             raise AttributeError
     else:#no existe, creamos un nuevo usuario
         self.user = User.register(password=make_random_string(length=6), confirmed=True)
         self.user.settings.sync_avatar_with = 'twitter' #  por defecto, si el usuario es nuevo sincronizamos con facebook
         self.user.settings.put()
         self.authorize(user)
     return self.user
Пример #8
0
def login_google(request):
    """**Descripción**: Comprueba si ya te has dado de alta en la App con tu cuenta de Google
        para entrar automáticamente y sino pedirte permiso para hacerlo.
        Además en caso de éxito inicializa la sesión para dicho usuario.
        
       :return: En caso de exito llama a :py:func:`geouser.funcs.login_func` y redirige al panel. En caso contrario renderiza la plantilla de login.
    """
    from google.appengine.api import users
    from models_social import GoogleUser
    ugoogle = users.get_current_user()
    if ugoogle:
        if request.user.is_authenticated():
            guser = GoogleUser.objects.get_by_id(ugoogle.user_id())
            if not guser:
                guser = GoogleUser.register(user=request.user,
                                            uid=ugoogle.user_id(),
                                            email=ugoogle.email(),
                                            realname=ugoogle.nickname())
            else:
                guser.update(ugoogle.email(), realname=ugoogle.nickname())
        else:  #user is not registered, register it
            from models import User
            user = User.objects.get_by_email(ugoogle.email())
            if user:
                guser = GoogleUser.objects.get_by_id(ugoogle.user_id())
                if guser is None:
                    guser = GoogleUser.register(user=user,
                                                uid=ugoogle.user_id(),
                                                email=ugoogle.email(),
                                                realname=ugoogle.nickname())
                else:
                    guser.update(ugoogle.email(), realname=ugoogle.nickname())
            else:
                from georemindme.funcs import make_random_string
                user = User.register(email=ugoogle.email(),
                                     password=make_random_string(length=6),
                                     confirmed=True)
                guser = GoogleUser.register(user=user,
                                            uid=ugoogle.user_id(),
                                            email=ugoogle.email(),
                                            realname=ugoogle.nickname())
            from funcs import init_user_session
            init_user_session(request, user)
        #checks google account is confirmed, only load his account
        from funcs import get_next
        return HttpResponseRedirect(get_next(request))
    return HttpResponseRedirect(
        users.create_login_url(reverse('geouser.views.login_google')))
Пример #9
0
 def authenticate(self,password=None):
     """el usuario se esta logeando usando facebook"""
     try:
         facebookInfo = self.get_user_info()
     except:
         return False
     fbuser = FacebookUser.objects.get_by_id(facebookInfo['id'])
     if fbuser is not None:#el usuario ya existe, iniciamos sesion
         self.user = fbuser.user
     else:#no existe, creamos un nuevo usuario
         self.user = User.objects.get_by_email(facebookInfo['email'])
         if self.user is None:
             self.user = User.register(email=facebookInfo['email'], confirmed=True, password=password if password is not None else make_random_string(length=6))
             self.user.profile.sync_avatar_with = 'facebook' #  por defecto, si el usuario es nuevo sincronizamos con facebook
             self.user.profile.put()
     if not self.authorize(self.user):
         raise OAUTHException()
     return self.user
Пример #10
0
 def authenticate(self, password=None):
     """el usuario se esta logeando usando facebook"""
     try:
         facebookInfo = self.get_user_info()
     except:
         return False
     fbuser = FacebookUser.objects.get_by_id(facebookInfo['id'])
     if fbuser is not None:  #el usuario ya existe, iniciamos sesion
         self.user = fbuser.user
     else:  #no existe, creamos un nuevo usuario
         self.user = User.objects.get_by_email(facebookInfo['email'])
         if self.user is None:
             self.user = User.register(
                 email=facebookInfo['email'],
                 confirmed=True,
                 password=password
                 if password is not None else make_random_string(length=6))
             self.user.profile.sync_avatar_with = 'facebook'  #  por defecto, si el usuario es nuevo sincronizamos con facebook
             self.user.profile.put()
     if not self.authorize(self.user):
         raise OAUTHException()
     return self.user
Пример #11
0
def login_google(request):
    """**Descripción**: Comprueba si ya te has dado de alta en la App con tu cuenta de Google
        para entrar automáticamente y sino pedirte permiso para hacerlo.
        Además en caso de éxito inicializa la sesión para dicho usuario.
        
       :return: En caso de exito llama a :py:func:`geouser.funcs.login_func` y redirige al panel. En caso contrario renderiza la plantilla de login.
    """
    from google.appengine.api import users
    from models_social import GoogleUser
    ugoogle = users.get_current_user()
    if ugoogle:
        if request.user.is_authenticated():
            guser = GoogleUser.objects.get_by_id(ugoogle.user_id())
            if not guser:
                guser = GoogleUser.register(user=request.user, uid=ugoogle.user_id(), email=ugoogle.email(), realname=ugoogle.nickname())
            else:
                guser.update(ugoogle.email(), realname=ugoogle.nickname())
        else:#user is not registered, register it
            from models import User
            user = User.objects.get_by_email(ugoogle.email())
            if user:
                guser = GoogleUser.objects.get_by_id(ugoogle.user_id())
                if guser is None:
                    guser = GoogleUser.register(user=user, uid=ugoogle.user_id(), email=ugoogle.email(), realname=ugoogle.nickname())
                else:
                    guser.update(ugoogle.email(), realname=ugoogle.nickname())
            else:
                from georemindme.funcs import make_random_string
                user = User.register(email=ugoogle.email(), password=make_random_string(length=6), confirmed=True)
                guser = GoogleUser.register(user=user, uid=ugoogle.user_id(), email=ugoogle.email(), realname=ugoogle.nickname())
            from funcs import init_user_session
            init_user_session(request, user)
        #checks google account is confirmed, only load his account
        from funcs import get_next
        return HttpResponseRedirect(get_next(request))
    return HttpResponseRedirect(users.create_login_url(reverse('geouser.views.login_google')))
Пример #12
0
 def users(self):
     """The list with all the users who where in this point
     
         :returns: :class:`georemindme.models.User`
     """
     return User.get(([u.user.key() for u in self.routeuserpoint_set]))
Пример #13
0
 def users(self):
     """The list with all the users who where in this point
     
         :returns: :class:`georemindme.models.User`
     """
     return User.get(([u.user.key() for u in self.routeuserpoint_set]))
Пример #14
0
    def get_by_id(self, userid, query_id=None, querier=None):
        '''
        Obtiene la lista de ultimos timeline del usuario

            :param userid: id del usuario (user.id)
            :type userid: :class:`string`
            :param page: numero de pagina a mostrar
            :type param: int
            :param query_id: identificador de busqueda
            :type query_id: int
            :returns: lista de tuplas de la forma [query_id, [(id, username, avatar)]]
        '''
        try:
            userid = long(userid)
        except:
            return None
        from geovote.models import Vote, Comment
        from geoalert.models import Suggestion
        from geolist.models import List
        from models_acc import UserTimeline, UserTimelineSuggest
        query = UserTimeline.all().filter(
            'user ='******'-created')
        if query_id is not None:  # recuperamos los cursores anteriores
            query = query.with_cursor(start_cursor=query_id)
        timelines = query.fetch(10)
        query_id = query.cursor()
        from georemindme.funcs import prefetch_refprops
        timelines = prefetch_refprops(timelines, UserTimeline.user,
                                      UserTimeline.instance)
        instances = _load_ref_instances(timelines)
        if querier is None:
            return [
                query_id,
                [{
                    'id':
                    timeline.id,
                    'created':
                    timeline.created,
                    'modified':
                    timeline.modified,
                    'msg':
                    timeline.msg,
                    'username':
                    timeline.user.username,
                    'msg_id':
                    timeline.msg_id,
                    'instance':
                    instances.get(
                        UserTimeline.instance.get_value_for_datastore(
                            timeline), timeline.instance),
                    'list':
                    instances.get(
                        UserTimelineSuggest.list_id.get_value_for_datastore(
                            timeline), timeline.list_id) if isinstance(
                                timeline, UserTimelineSuggest) else None,
                    'has_voted':
                    Vote.objects.user_has_voted(
                        db.Key.from_path(User.kind(), userid),
                        timeline.instance.key())
                    if timeline.instance is not None else None,
                    'vote_counter':
                    Vote.objects.get_vote_counter(timeline.instance.key())
                    if timeline.instance is not None else None,
                    'comments':
                    Comment.objects.get_by_instance(timeline.instance),
                    'is_private':
                    False
                } for timeline in timelines]
            ]
        elif querier.is_authenticated() and querier.are_friends(
                db.Key.from_path(User.kind(), userid)):
            return [
                query_id,
                [{
                    'id':
                    timeline.id,
                    'created':
                    timeline.created,
                    'modified':
                    timeline.modified,
                    'msg':
                    timeline.msg,
                    'username':
                    timeline.user.username,
                    'msg_id':
                    timeline.msg_id,
                    'instance':
                    instances.get(
                        UserTimeline.instance.get_value_for_datastore(
                            timeline), timeline.instance),
                    'list':
                    instances.get(
                        UserTimelineSuggest.list_id.get_value_for_datastore(
                            timeline), timeline.list_id) if isinstance(
                                timeline, UserTimelineSuggest) else None,
                    'has_voted':
                    Vote.objects.user_has_voted(querier,
                                                timeline.instance.key())
                    if timeline.instance is not None else None,
                    'vote_counter':
                    Vote.objects.get_vote_counter(timeline.instance.key())
                    if timeline.instance is not None else None,
                    'comments':
                    Comment.objects.get_by_instance(timeline.instance,
                                                    querier=querier),
                    'user_follower':
                    timeline.instance.has_follower(querier)
                    if isinstance(timeline.instance, Suggestion)
                    and querier.is_authenticated() else None,
                    'is_private':
                    False,
                } for timeline in timelines
                 if timeline._is_shared() or timeline._is_public()]
            ]
        return [
            query_id,
            [{
                'id':
                timeline.id,
                'created':
                timeline.created,
                'modified':
                timeline.modified,
                'msg':
                timeline.msg,
                'username':
                timeline.user.username,
                'msg_id':
                timeline.msg_id,
                'instance':
                instances.get(
                    UserTimeline.instance.get_value_for_datastore(timeline),
                    timeline.instance),
                'list':
                instances.get(
                    UserTimelineSuggest.list_id.get_value_for_datastore(
                        timeline), timeline.list_id) if isinstance(
                            timeline, UserTimelineSuggest) else None,
                'has_voted':
                Vote.objects.user_has_voted(querier, timeline.instance.key())
                if timeline.instance is not None
                and querier.is_authenticated() else None,
                'vote_counter':
                Vote.objects.get_vote_counter(timeline.instance.key())
                if timeline.instance is not None else None,
                'comments':
                Comment.objects.get_by_instance(timeline.instance,
                                                querier=querier),
                'user_follower':
                timeline.instance.has_follower(querier)
                if isinstance(timeline.instance, Suggestion)
                and querier.is_authenticated() else None,
                'is_private':
                False,
            } for timeline in timelines if timeline._is_public()]
        ]
Пример #15
0
    def get_by_id(self, userid, query_id = None, querier=None):
        '''
        Obtiene la lista de ultimos timeline del usuario

            :param userid: id del usuario (user.id)
            :type userid: :class:`string`
            :param page: numero de pagina a mostrar
            :type param: int
            :param query_id: identificador de busqueda
            :type query_id: int
            :returns: lista de tuplas de la forma [query_id, [(id, username, avatar)]]
        '''
        try:
            userid = long(userid)
        except:
            return None
        from geovote.models import Vote, Comment
        from geoalert.models import Suggestion
        from geolist.models import List
        from models_acc import UserTimeline, UserTimelineSuggest
        query = UserTimeline.all().filter('user ='******'-created')
        if query_id is not None:  # recuperamos los cursores anteriores
            query = query.with_cursor(start_cursor=query_id)
        timelines = query.fetch(10)
        query_id = query.cursor()
        from georemindme.funcs import prefetch_refprops
        timelines = prefetch_refprops(timelines, UserTimeline.user, UserTimeline.instance)
        instances = _load_ref_instances(timelines)
        if querier is None:
                return [query_id, [{'id': timeline.id, 'created': timeline.created, 
                        'modified': timeline.modified,
                        'msg': timeline.msg, 'username':timeline.user.username, 
                        'msg_id': timeline.msg_id,
                        'instance': instances.get(UserTimeline.instance.get_value_for_datastore(timeline), timeline.instance),
                        'list': instances.get(UserTimelineSuggest.list_id.get_value_for_datastore(timeline), timeline.list_id) 
                                    if isinstance(timeline, UserTimelineSuggest) else None,
                        'has_voted':  Vote.objects.user_has_voted(db.Key.from_path(User.kind(), userid), timeline.instance.key()) if timeline.instance is not None else None,
                        'vote_counter': Vote.objects.get_vote_counter(timeline.instance.key()) if timeline.instance is not None else None,
                        'comments': Comment.objects.get_by_instance(timeline.instance),
                        'is_private': False
                        } 
                       for timeline in timelines]]
        elif querier.is_authenticated() and querier.are_friends(db.Key.from_path(User.kind(), userid)):
            return [query_id, [{'id': timeline.id, 'created': timeline.created, 
                        'modified': timeline.modified,
                        'msg': timeline.msg, 'username':timeline.user.username, 
                        'msg_id': timeline.msg_id,
                        'instance': instances.get(UserTimeline.instance.get_value_for_datastore(timeline), timeline.instance),
                        'list': instances.get(UserTimelineSuggest.list_id.get_value_for_datastore(timeline), timeline.list_id) 
                                    if isinstance(timeline, UserTimelineSuggest) else None,
                        'has_voted':  Vote.objects.user_has_voted(querier, timeline.instance.key()) if timeline.instance is not None else None,
                        'vote_counter': Vote.objects.get_vote_counter(timeline.instance.key()) if timeline.instance is not None else None,
                        'comments': Comment.objects.get_by_instance(timeline.instance, querier=querier),
                        'user_follower': timeline.instance.has_follower(querier) if isinstance(timeline.instance, Suggestion) and querier.is_authenticated() else None,
                        'is_private': False,
                        }
                        for timeline in timelines if timeline._is_shared() or timeline._is_public()]]
        return [query_id, [{'id': timeline.id, 'created': timeline.created, 
                        'modified': timeline.modified,
                        'msg': timeline.msg, 'username':timeline.user.username, 
                        'msg_id': timeline.msg_id,
                        'instance': instances.get(UserTimeline.instance.get_value_for_datastore(timeline), timeline.instance),
                        'list': instances.get(UserTimelineSuggest.list_id.get_value_for_datastore(timeline), timeline.list_id) 
                                    if isinstance(timeline, UserTimelineSuggest) else None,
                        'has_voted':  Vote.objects.user_has_voted(querier, timeline.instance.key()) if timeline.instance is not None and querier.is_authenticated()else None,
                        'vote_counter': Vote.objects.get_vote_counter(timeline.instance.key()) if timeline.instance is not None else None,
                        'comments': Comment.objects.get_by_instance(timeline.instance, querier=querier),
                        'user_follower': timeline.instance.has_follower(querier) if isinstance(timeline.instance, Suggestion) and querier.is_authenticated() else None,
                        'is_private': False,
                        }
                       for timeline in timelines if timeline._is_public()]]