示例#1
0
 def post(self):
     name = self.request.get('name')
     email = self.request.get('email')
     password = self.request.get('password')
     
     existing_google_user = CAUser.all().filter("google_user !=", None).fetch(10000)
     exists = False
     
     for user in existing_google_user:
         if user.google_user.email() == email:
             exists = True
             break
     
     if not exists:
         existing_user = CANativeUser.all().filter("email =", email).fetch(10000)
         
         if not existing_user:
             user = CANativeUser(name=name, email=email, password=password)
             user.put()
             
             ca_user = CAUser(native_user=user, type=2)
             ca_user.put()
         
             self.redirect('/login')
         else:
             template_values = {
                 'session_status': False,
                 'top_scorers': get_top_scorers(),
                 'top_users': get_top_users_global_ranking(),
                 'last_jackpot': get_last_jackpot(),
                 'error': 'Ya existe un usuario registrado con este correo electrónico. Inténtalo de nuevo'
             }
             
             render_template(self, 'register.html', template_values)
     else:
         template_values = {
             'session_status': False,
             'top_scorers': get_top_scorers(),
             'top_users': get_top_users_global_ranking(),
             'last_jackpot': get_last_jackpot(),
             'error': 'Ya existe un usuario registrado con este correo electrónico. Inténtalo de nuevo'
         }
         
         render_template(self, 'register.html', template_values)
示例#2
0
    def post(self):
        session = get_current_session()
        
        if session.is_active():
            session.terminate()
            
        accept = self.request.get('accept')
        google = self.request.get('google')
        
        """
        Login con autenticacion nativa
        """
        if accept:
            logging.debug('Login with native credentials')
            
            email = self.request.get('email')
            password = self.request.get('password')
            
            if email and password:
                logging.debug('Checking credentials')
                
                user = CANativeUser.all().filter("email =", email).fetch(1)
    
                if user:
                    if user[0].password == password:
                        logging.debug('Username and password correct. Login successfull')
                        
                        ca_user = CAUser.all().filter("native_user", user[0]).fetch(1)
                        
                        if ca_user:
                            logging.debug('User registered with Native account. Login successfull')
                            ca_user = ca_user[0] 
                        else:
                            ca_user = CAUser(google_user=user[0], type=0)
                            ca_user.put()

                        save_session_info(ca_user)
                        
#                        template_values = {
#                            'session_status': True,
#                            'user': session['active_user'],
#                            'top_scorers': get_top_scorers(),
#                            'top_users': get_top_users_global_ranking(),
#                            'last_jackpot': get_last_jackpot()
#                        }
                        
#                        render_template(self, 'create_step1.html', template_values)
                        
                        sandra_key = Key('ag5zfnR1cXVpbmllbGFjYXIOCxIGQ0FVc2VyGJqdAQw')
                        christian_key = Key('ag5zfnR1cXVpbmllbGFjYXINCxIGQ0FVc2VyGNR1DA')
                        mariel_key = Key('ag5zfnR1cXVpbmllbGFjYXIOCxIGQ0FVc2VyGIG0AQw')
                        francisco_key = Key('ag5zfnR1cXVpbmllbGFjYXIOCxIGQ0FVc2VyGIbUAQw')
                        
                        ca_user_key = ca_user.key() 
                        
                        if ca_user_key == sandra_key or ca_user_key == christian_key or ca_user_key == mariel_key or ca_user_key == francisco_key:
                            self.redirect('/create/step1')
                        else:
                            self.redirect('/list/groups/ranking')
                    else:
                        logging.debug('Incorrect password. . Login failed')
                        
                        template_values = {
                            'error': 'Clave incorrecta. Intente de nuevo'
                        }
    
                        render_template(self, 'login.html', template_values)
                else:
                    logging.debug('Incorrect username. Login failed')
                    
                    template_values = {
                        'error': 'Usuario incorrecto. Intente de nuevo'
                    }
    
                    render_template(self, 'login.html', template_values)
            else:
                logging.debug('Username o password missing. Login failed')
                    
                template_values = {
                    'error': 'Usuario o clave faltantes. Intente de nuevo'
                }
                
                render_template(self, 'login.html', template_values)
        else:
            """
            Login con autenticacion de google o facebook
            """
            if google:
                logging.debug('GOOGLE')
                logging.debug('Login with Google')
                self.redirect(users.create_login_url('/auth/google'))
            else:
                logging.debug('FACEBOOK')
                logging.debug('Login with Facebook')
                self.redirect("/auth/facebook")