def send_remind_code(self): ''' Envia un correo con un codigo para iniciar la recuperacion de contraseña ''' self.remind_code = make_random_string(length=24) from datetime import datetime self.date_remind = datetime.now() self.put() from geouser.mails import send_remind_pass_mail send_remind_pass_mail(self.email, self.remind_code, language=self.get_language())#send mail
def send_confirm_code(self, commit = True): ''' Envia un correo de confirmacion de direccion de correo ''' if not self.is_confirmed(): self.confirm_code = make_random_string(length=24) if commit: self.put() from geouser.mails import send_confirm_mail send_confirm_mail(self.email, self.confirm_code, language=self.get_language()) # send mail
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
def send_confirm_code(self, commit = True): ''' Envia un correo de confirmacion de direccion de correo ''' if self.email == '' or self.email is None: return None if not self.is_confirmed(): if self.confirm_code is None or self.confirm_code == '': from georemindme.funcs import make_random_string self.confirm_code = make_random_string(length=24) if commit: self.put() from geouser.mails import send_confirm_mail send_confirm_mail(self.email, self.confirm_code, language=self.get_language()) # send mail
def send_remind_code(self): ''' Envia un correo con un codigo para iniciar la recuperacion de contraseña ''' if self.email == '' or self.email is None: return None from georemindme.funcs import make_random_string from datetime import datetime self.remind_code = make_random_string(length=24) self.date_remind = datetime.now() self.put() from geouser.mails import send_remind_pass_mail send_remind_pass_mail(self.email, self.remind_code, language=self.get_language()) #send mail
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
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')))
def send_confirm_code(self, commit=True): ''' Envia un correo de confirmacion de direccion de correo ''' if self.email == '' or self.email is None: return None if not self.is_confirmed(): if self.confirm_code is None or self.confirm_code == '': from georemindme.funcs import make_random_string self.confirm_code = make_random_string(length=24) if commit: self.put() from geouser.mails import send_confirm_mail send_confirm_mail(self.email, self.confirm_code, language=self.get_language()) # send mail
def login_google(request): ugoogle = users.get_current_user() if ugoogle: guser = GoogleUser.objects.get_by_id(ugoogle.user_id()) if not guser:#user is not registered, register it user = User.objects.get_by_email(ugoogle.email()) if user: guser = GoogleUser.register(user=user, uid=ugoogle.user_id(), email=ugoogle.email(), realname=ugoogle.nickname()) else: user = User.register(email=ugoogle.email(), password=make_random_string(length=6)) guser = GoogleUser.register(user=user, uid=ugoogle.user_id(), email=ugoogle.email(), realname=ugoogle.nickname()) init_user_session(request, user) else:#checks google account is confirmed, only load his account guser.update(ugoogle.email(), realname=ugoogle.nickname()) init_user_session(request, guser.user) return HttpResponseRedirect(get_next(request)) #not google user return HttpResponseRedirect(users.create_login_url(reverse('geouser.views.login_google')))
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
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')))
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