示例#1
0
def SMDS_authentication( logfile="/tmp/SMDS_login.log" ):
    """
    Authenticate with the Syndicate metadata service
    """
    logger.init( open(logfile, "a") )
    
    def SMDS_auth_aux(username, password):
      
      api = MDAPI()
      
      user = None
      try:
         user = auth_user_from_email( api, username )
      except Exception, e:
         logger.error( "User '%s' could not be authenticated (exception = %s)" % (username, e) )
         return False
      
      
      rc = False
      auth_struct = {'AuthMethod': 'password', 'Username': user['username'], 'AuthString': password}
      
      try:
         rc = auth_password_check( api, auth_struct, user, None )
      except Exception, e:
         logger.error( "User '%s' failed to authenticate" % username)
示例#2
0
def SMDS_authentication(logfile="/tmp/SMDS_login.log"):
    """
    Authenticate with the Syndicate metadata service
    """
    logger.init(open(logfile, "a"))

    def SMDS_auth_aux(username, password):

        api = MDAPI()

        user = None
        try:
            user = auth_user_from_email(api, username)
        except Exception, e:
            logger.error(
                "User '%s' could not be authenticated (exception = %s)" %
                (username, e))
            return False

        rc = False
        auth_struct = {
            'AuthMethod': 'password',
            'Username': user['username'],
            'AuthString': password
        }

        try:
            rc = auth_password_check(api, auth_struct, user, None)
        except Exception, e:
            logger.error("User '%s' failed to authenticate" % username)
示例#3
0
   def login(self, next=DEFAULT, onvalidation=DEFAULT, onaccept=DEFAULT, log=DEFAULT):
      """
      Handle a login request, and redirect.
      """
      request = current.request
      response = current.response
      session = current.session
      
      username_field = self.settings.login_userfield
      password_field = self.settings.password_field
      
      if next == DEFAULT:
         next = request.get_vars._next \
            or request.post_vars._next \
            or self.settings.login_next
                
      if onvalidation == DEFAULT:
         onvalidation = self.settings.login_onvalidation
      if onaccept == DEFAULT:
         onaccept = self.settings.login_onaccept
      if log == DEFAULT:
         log = self.messages.login_log
      
      user = None
      accepted_form = False
      
      if self.settings.login_form == self:
         # this object was responsible for logging in
         form =FORM(                                                                          \
                     TABLE(                                                                   \
                        TR(TD('Username:'******'Password:'******'login',
                         onvalidation=onvalidation,
                         hideerror=self.settings.hideerror):
            
            # sanitize inputs
            
            accepted_form = True
            
            # check for username in db
            username = form.vars[username_field]
            user = None
            try:
               user = Users( self.api, {'username': username} )[0]
            except:
               pass
               
            if user:
               # user in db, check if registration pending or disabled
               temp_user = user
               if temp_user['enabled'] == False:
                  # user is not yet enabled
                  response.flash = self.messages.login_disabled
                  return form
                  
               # check password
               try:
                  rc = auth_password_check( self.api, {'Username':user['username'], 'AuthMethod':'password', 'AuthString':form.vars[password_field]}, user, None )
               except:
                  if log:
                     logger.error("SMDS_Auth: User '%s' authentication failed (invalid credentials)" % user['username'] )
                     logger.flush()
                     
                  user = None   # invalid credentials
               
            if not user:
               if log:
                  logger.error("SMDS_Auth: User could not be looked up" )
                  logger.flush()
                  
               # invalid login
               session.flash = self.messages.invalid_login
               redirect(self.url(args=request.args,vars=request.get_vars))

      if user:
         user_public = user.public()
         user_stored = Storage(user_public)

         if log:
            logger.info("SMDS_Auth: User '%s' logged in" % user_public['username'])

         # process authenticated users
         # user wants to be logged in for longer
         session.auth = Storage(
               user = user_stored,
               last_visit = request.now,
               expiration = self.settings.long_expiration,
               remember = request.vars.has_key("remember"),
               hmac_key = web2py_uuid()
               )

         self.user = user_public
         logger.info("SMDS_Auth: user_id = %s" % self.user_id)
         logger.flush()
         
         session.flash = self.messages.logged_in

      # how to continue
      if self.settings.login_form == self:
         if accepted_form:
            callback(onaccept,form)
            if isinstance(next, (list, tuple)):
               # fix issue with 2.6
               next = next[0]
            if next and not next[0] == '/' and next[:4] != 'http':
               next = self.url(next.replace('[id]', str(form.vars.id)))
            
            redirect(next)
         
         return form
      elif user:
         callback(onaccept,None)
      
      redirect(next)
示例#4
0
      """
      api = MDAPI()
      
      user = None
      try:
         user = auth_user_from_email( api, username )
      except Exception, e:
         logger.error( "User '%s' could not be authenticated (exception = %s)" % (username, e) )
         return False
      
      
      rc = False
      auth_struct = {'AuthMethod': 'password', 'Username': user['username'], 'AuthString': password}
      
      try:
         rc = auth_password_check( api, auth_struct, user, None )
      except Exception, e:
         logger.error( "User '%s' failed to authenticate" % username)

      if rc and user:
         user_public = user.public()
         user_stored = Storage(user_public)

         if log:
            logger.info("SMDS_Auth: User '%s' logged in" % user_public['username'])

         # process authenticated users
         # user wants to be logged in for longer
         session.auth = Storage(
               user = user_stored,
               last_visit = request.now,
示例#5
0
    def login(self,
              next=DEFAULT,
              onvalidation=DEFAULT,
              onaccept=DEFAULT,
              log=DEFAULT):
        """
      Handle a login request, and redirect.
      """
        request = current.request
        response = current.response
        session = current.session

        username_field = self.settings.login_userfield
        password_field = self.settings.password_field

        if next == DEFAULT:
            next = request.get_vars._next \
               or request.post_vars._next \
               or self.settings.login_next

        if onvalidation == DEFAULT:
            onvalidation = self.settings.login_onvalidation
        if onaccept == DEFAULT:
            onaccept = self.settings.login_onaccept
        if log == DEFAULT:
            log = self.messages.login_log

        user = None
        accepted_form = False

        if self.settings.login_form == self:
            # this object was responsible for logging in
            form =FORM(                                                                          \
                        TABLE(                                                                   \
                           TR(TD('Username:'******'Password:'******'login',
                            onvalidation=onvalidation,
                            hideerror=self.settings.hideerror):

                # sanitize inputs

                accepted_form = True

                # check for username in db
                username = form.vars[username_field]
                user = None
                try:
                    user = Users(self.api, {'username': username})[0]
                except:
                    pass

                if user:
                    # user in db, check if registration pending or disabled
                    temp_user = user
                    if temp_user['enabled'] == False:
                        # user is not yet enabled
                        response.flash = self.messages.login_disabled
                        return form

                    # check password
                    try:
                        rc = auth_password_check(
                            self.api, {
                                'Username': user['username'],
                                'AuthMethod': 'password',
                                'AuthString': form.vars[password_field]
                            }, user, None)
                    except:
                        if log:
                            logger.error(
                                "SMDS_Auth: User '%s' authentication failed (invalid credentials)"
                                % user['username'])
                            logger.flush()

                        user = None  # invalid credentials

                if not user:
                    if log:
                        logger.error("SMDS_Auth: User could not be looked up")
                        logger.flush()

                    # invalid login
                    session.flash = self.messages.invalid_login
                    redirect(self.url(args=request.args,
                                      vars=request.get_vars))

        if user:
            user_public = user.public()
            user_stored = Storage(user_public)

            if log:
                logger.info("SMDS_Auth: User '%s' logged in" %
                            user_public['username'])

            # process authenticated users
            # user wants to be logged in for longer
            session.auth = Storage(user=user_stored,
                                   last_visit=request.now,
                                   expiration=self.settings.long_expiration,
                                   remember=request.vars.has_key("remember"),
                                   hmac_key=web2py_uuid())

            self.user = user_public
            logger.info("SMDS_Auth: user_id = %s" % self.user_id)
            logger.flush()

            session.flash = self.messages.logged_in

        # how to continue
        if self.settings.login_form == self:
            if accepted_form:
                callback(onaccept, form)
                if isinstance(next, (list, tuple)):
                    # fix issue with 2.6
                    next = next[0]
                if next and not next[0] == '/' and next[:4] != 'http':
                    next = self.url(next.replace('[id]', str(form.vars.id)))

                redirect(next)

            return form
        elif user:
            callback(onaccept, None)

        redirect(next)
示例#6
0
            user = auth_user_from_email(api, username)
        except Exception, e:
            logger.error(
                "User '%s' could not be authenticated (exception = %s)" %
                (username, e))
            return False

        rc = False
        auth_struct = {
            'AuthMethod': 'password',
            'Username': user['username'],
            'AuthString': password
        }

        try:
            rc = auth_password_check(api, auth_struct, user, None)
        except Exception, e:
            logger.error("User '%s' failed to authenticate" % username)

        if rc and user:
            user_public = user.public()
            user_stored = Storage(user_public)

            if log:
                logger.info("SMDS_Auth: User '%s' logged in" %
                            user_public['username'])

            # process authenticated users
            # user wants to be logged in for longer
            session.auth = Storage(user=user_stored,
                                   last_visit=request.now,