Пример #1
0
 def test_validate_email(self):
     self.assertTrue(util.validate_email("*****@*****.**"))
     self.assertTrue(util.validate_email("*****@*****.**"))
     self.assertTrue(util.validate_email("*****@*****.**"))
     self.assertFalse(util.validate_email("[email protected]"))
     self.assertFalse(util.validate_email("jake@lp."))
     self.assertFalse(util.validate_email("[email protected]"))
     self.assertFalse(util.validate_email("@lp.com"))
     self.assertFalse(util.validate_email("@."))
     self.assertFalse(util.validate_email("."))
     self.assertFalse(util.validate_email("@"))
Пример #2
0
   def newUnauthenticatedUser(self):  
       if (self.request('main_text')): return False
 
       firstName = self.request('f_name')
       lastName = self.request('l_name')
       email = self.request('email')
       password = self.request('password')
       phone = util.cleanUSPhone(self.request('sms_phone'))
       code = self.request('beta_code')
       redirectLink = self.request('redirect_link')
               
       if (self.appMode == 'beta' and not self.verifyBetaCode(code)):
           log.error("*** beta user attempted register w/ invalid code")
           return False        
       elif (len(firstName) == 0): 
           log.error("*** error on user create: no first name")
           return False
       elif (len(lastName) == 0): 
           log.error("*** error on user create: no last name")
           return False
       elif (len(email) == 0 or not util.validate_email(email)): 
           log.error("*** error on user create: invalid email")
           return False
       elif (len(password) == 0): 
           log.error("*** error on user create: no password")
           return False
       else:
           #create unauth data record and email user
           authGuid = uuid.uuid4()
           
           if (mUser.createUnauthenticatedUser(self.db, authGuid, email, password, firstName, lastName, phone, redirectLink=redirectLink)):
               return mMessaging.emailUnauthenticatedUser(email, authGuid)
           else:
               return False
Пример #3
0
    def addUser(self):
        firstName = self.request('f_name')
        lastName = self.request('l_name')
        email = self.request('email')
        password = self.request('password')
        userGroupId = util.try_f(int, self.request('role'))
        affiliation = self.request('affiliation')

        if (util.strNullOrEmpty(email) or not util.validate_email(email)):
            log.error("*** cms user submitted with invalid email")
            return False
        elif (util.strNullOrEmpty(password)):
            log.error("*** cms user submitted with no password")
            return False
        elif (not userGroupId):
            log.error("*** cms user submitted with no role")
            return False
        else:
            userId = mUser.createUser(self.db,
                                      email,
                                      password,
                                      firstName,
                                      lastName,
                                      affiliation=affiliation,
                                      isAdmin=(userGroupId == 1
                                               or userGroupId == 3))

            # do we want to attach ideas to cms users?
            mIdea.attachIdeasByEmail(self.db, email)

            mUser.assignUserToGroup(self.db, userId, userGroupId)

            return userId
Пример #4
0
    def login_twitter_create(self):
        email = self.request('email')
        firstName = self.request('f_name')
        lastName = self.request('l_name')
        phone = util.cleanUSPhone(self.request('sms_phone'))

        s = SessionHolder.get_session()
        access_token = s.tw_access_token
        #access_token = self.request('twitter_data')

        if (len(firstName) == 0):
            log.error("no first name")
            return False
        elif (len(lastName) == 0):
            log.error("no last name")
            return False
        elif (len(email) == 0 or not util.validate_email(email)):
            log.error("invalid email")
            return False
        else:
            #userId = user.createUser(self.db, email, password, firstName, lastName, phone)
            userId = mUser.createUser(self.db, email, access_token['oauth_token_secret'], firstName, lastName, phone)
            self.db.insert('twitter_user', user_id = userId, twitter_username = access_token['screen_name'], twitter_id = access_token['user_id'])
            self.session.user_id = userId
            self.session.invalidate()
            #following 3 lines commented out for oauth dev
            #idea.attachIdeasByEmail(self.db, email)
            #if (phone and len(phone) > 0):
            #    idea.attachIdeasByPhone(self.db, phone)

        return userId;
Пример #5
0
    def addUser(self):
        firstName = self.request('f_name')
        lastName = self.request('l_name')
        email = self.request('email')
        password = self.request('password')
        userGroupId = util.try_f(int, self.request('role'))
        affiliation = self.request('affiliation')

        if (util.strNullOrEmpty(email)or not util.validate_email(email)):
            log.error("*** cms user submitted with invalid email")
            return False
        elif (util.strNullOrEmpty(password)):
            log.error("*** cms user submitted with no password")
            return False
        elif (not userGroupId):
            log.error("*** cms user submitted with no role")
            return False
        else:
            userId = mUser.createUser(self.db, email, password, firstName, lastName, affiliation = affiliation, isAdmin = (userGroupId == 1 or userGroupId == 3))

            # do we want to attach ideas to cms users?
            mIdea.attachIdeasByEmail(self.db, email)

            mUser.assignUserToGroup(self.db, userId, userGroupId)

            return userId
Пример #6
0
    def newUnauthenticatedUser(self):
        if (self.request('main_text')): return False

        firstName = self.request('f_name')
        lastName = self.request('l_name')
        email = self.request('email')
        password = self.request('password')
        phone = util.cleanUSPhone(self.request('sms_phone'))
        code = self.request('beta_code')

        if (self.appMode == 'beta' and not self.verifyBetaCode(code)):
            log.error("*** beta user attempted register w/ invalid code")
            return False
        elif (len(firstName) == 0):
            log.error("*** error on user create: no first name")
            return False
        elif (len(lastName) == 0):
            log.error("*** error on user create: no last name")
            return False
        elif (len(email) == 0 or not util.validate_email(email)):
            log.error("*** error on user create: invalid email")
            return False
        elif (len(password) == 0):
            log.error("*** error on user create: no password")
            return False
        else:
            #create unauth data record and email user
            authGuid = uuid.uuid4()

            if (mUser.createUnauthenticatedUser(self.db, authGuid, email,
                                                password, firstName, lastName,
                                                phone)):
                return mMessaging.emailUnauthenticatedUser(email, authGuid)
            else:
                return False
Пример #7
0
    def newUser(self):
        firstName = self.request('f_name')
        lastName = self.request('l_name')
        email = self.request('email')
        password = self.request('password')
        phone = util.cleanUSPhone(self.request('sms_phone'))
        code = self.request('beta_code')

        if (self.appMode == 'beta' and not self.verifyBetaCode(code)):
            log.error("*** beta user attempted register w/ invalid code")
            return False
        elif (len(firstName) == 0):
            log.error("*** error on user create: no first name")
            return False
        elif (len(lastName) == 0):
            log.error("*** error on user create: no last name")
            return False
        elif (len(email) == 0 or not util.validate_email(email)):
            log.error("*** error on user create: invalid email")
            return False
        elif (len(password) == 0):
            log.error("*** error on user create: no password")
            return False
        else:
            userId = mUser.createUser(self.db, email, password, firstName,
                                      lastName, phone)

            if (userId):
                # log in user
                self.session.user_id = userId
                self.session.invalidate()
                # set cbu_key for blog access
                web.setcookie('cbu_key',
                              util.obfuscate(userId),
                              domain=".changeby.us")

                if (self.appMode == 'beta'):
                    self.expireBetaCode(code, userId)

                mIdea.attachIdeasByEmail(self.db, email)

                if (phone and len(phone) > 0):
                    mIdea.attachIdeasByPhone(self.db, phone)

                return userId
            else:
                return False
Пример #8
0
    def newUser(self):
        firstName = self.request('f_name')
        lastName = self.request('l_name')
        email = self.request('email')
        password = self.request('password')
        phone = util.cleanUSPhone(self.request('sms_phone'))
        code = self.request('beta_code')        
                
        if (self.appMode == 'beta' and not self.verifyBetaCode(code)):
            log.error("*** beta user attempted register w/ invalid code")
            return False        
        elif (len(firstName) == 0): 
            log.error("*** error on user create: no first name")
            return False
        elif (len(lastName) == 0): 
            log.error("*** error on user create: no last name")
            return False
        elif (len(email) == 0 or not util.validate_email(email)): 
            log.error("*** error on user create: invalid email")
            return False
        elif (len(password) == 0): 
            log.error("*** error on user create: no password")
            return False
        else:
            userId = mUser.createUser(self.db, email, password, firstName, lastName, phone)
            
            if (userId):
                # log in user
                self.session.user_id = userId
                self.session.invalidate()
                # set cbu_key for blog access
                web.setcookie('cbu_key', util.obfuscate(userId), domain = ".changeby.us")

            
                if (self.appMode == 'beta'):
                    self.expireBetaCode(code, userId)
                
                mIdea.attachIdeasByEmail(self.db, email)
                
                if (phone and len(phone) > 0):
                    mIdea.attachIdeasByPhone(self.db, phone)
            
                return userId
            else:
                return False
Пример #9
0
    def login_twitter_create(self):
        email = self.request('email')
        firstName = self.request('f_name')
        lastName = self.request('l_name')
        phone = util.cleanUSPhone(self.request('sms_phone'))

        s = SessionHolder.get_session()
        access_token = s.tw_access_token
        #access_token = self.request('twitter_data')

        if (len(firstName) == 0):
            log.error("no first name")
            return False
        elif (len(lastName) == 0):
            log.error("no last name")
            return False
        elif (len(email) == 0 or not util.validate_email(email)):
            log.error("invalid email")
            return False
        else:
            #userId = user.createUser(self.db, email, password, firstName, lastName, phone)
            userId = mUser.createUser(self.db, email,
                                      access_token['oauth_token_secret'],
                                      firstName, lastName, phone)
            self.db.insert('twitter_user',
                           user_id=userId,
                           twitter_username=access_token['screen_name'],
                           twitter_id=access_token['user_id'])
            self.session.user_id = userId
            self.session.invalidate()
            #following 3 lines commented out for oauth dev
            #idea.attachIdeasByEmail(self.db, email)
            #if (phone and len(phone) > 0):
            #    idea.attachIdeasByPhone(self.db, phone)

        return userId