Ejemplo n.º 1
0
    def __update_record(self, params, conditions):
        '''
        updates verification table
        
        '''

        try:
            self.dbconn.execute_update(table_name='verification',
                                       params=params,
                                       operator='AND',
                                       conditions=conditions)
        except Exception, e:
            raise VerificationError('unable to write to email queue: %s' % e)
Ejemplo n.º 2
0
    def create_new_signup_verification(self,
                                       account_id,
                                       email,
                                       code,
                                       resend_code,
                                       expiration_delta=None):
        '''
        writes signup verification to verification table
        
        @param account_id: the account id assigned to the pending user
        @param email: the email used by the registering user
        @param code : String the unique string that will publicly identify the verification
        @param expiration_delta : python timedelta , denotes duration of validity of the verification
        
        
        @author: vincent agudelo
        
        
        '''
        verification_id = None

        new_verification_object = None
        params = {
            'email': email,
            'account_id': account_id,
            'code': code,
            'resend_code': resend_code,
            'category': 'SIGNUP'
        }

        if expiration_delta:
            params['date_expiry'] = (
                datetime.now() +
                expiration_delta).strftime('%Y-%m-%d %H:%M:%S')

        try:

            verification_id = self.__insert_to_database(params)

            new_verification_object = Verification()
            new_verification_object.verification_id = verification_id
            new_verification_object.email = email
            new_verification_object.verification_category = 'SIGNUP'
            new_verification_object.account_id = account_id
            new_verification_object.code = code
            new_verification_object.resend_code = resend_code

        except Exception, e:

            raise VerificationError(
                'could not create verification record: %s' % e)
Ejemplo n.º 3
0
def resend_forgot_password_by_code( code ):
    
    verification_object = Verification.get_forgot_password_verify_by_code( code=code )
    
    
    if verification_object :
        
        # step 1 update expiry
        verification_object.update_forgot_password_expiry()
        
        # step 2 add to email queue
        verification_object.add_forgot_password_email_to_queue()
    else :
        raise VerificationError('does not exist')
Ejemplo n.º 4
0
    def remove(self, verification_object):

        criteria = {'id': verification_object.verification_id}

        try:

            self.dbconn.execute_delete(table_name='verification',
                                       conditions=criteria,
                                       operator='AND')

        except Exception, e:

            raise VerificationError(
                'unable to delete verification id:%s ; %s' %
                (verification_object.verification_id, e))
    def increment_forgot_password_send(self, account_id):

        try:
            datetoday = date.today()
            key = self.forgot_password_send_ctr_key % (
                account_id, datetoday.strftime('%Y%m%d'))
            new_value = self.redis_conn.incr(key)
            if new_value == 1:
                # set expiration to 1 day
                self.redis_conn.expireat(
                    key, (datetoday + timedelta(days=1)).strftime("%s"))

        except:
            raise VerificationError('unable to increment password send')
        else:
            return new_value
Ejemplo n.º 6
0
    def create_new_change_email_verification(self, account_object, new_email,
                                             code, expiration_delta,
                                             resend_code):

        verification_object = None

        params = {
            'email':
            new_email,
            'account_id':
            account_object.account_id,
            'code':
            code,
            'resend_code':
            resend_code,
            'category':
            self.valid_categories['change_email'],
            'date_expiry':
            (datetime.now() + expiration_delta).strftime('%Y-%m-%d %H:%M:%S')
        }

        try:

            verification_id = self.__insert_to_database(params)

            if verification_id:

                verification_object = Verification()

                verification_object.verification_id = verification_id
                verification_object.email = params['email']
                verification_object.verification_category = params['category']
                verification_object.account_id = params['account_id']
                verification_object.code = params['code']
                verification_object.resend_code = params['resend_code']

        except Exception, e:

            raise VerificationError(
                'could not create verification record: %s' % e)
    def increment_resend_verifi_email(self, account_id):
        '''
        increments the resend counter for each user 
        this is for each day only
        '''

        try:
            datetoday = date.today()
            key = self.signup_resed_ctr_key % (account_id,
                                               datetoday.strftime('%Y%m%d'))
            new_value = self.redis_conn.incr(key)

            if new_value == 1:
                # this is the first time that this was created
                # set expiration
                self.redis_conn.expireat(
                    key, (datetoday + timedelta(days=1)).strftime("%s"))

        except Exception, e:
            raise VerificationError(
                'unable to increment resend counter for account id %s; ' %
                account_id)
Ejemplo n.º 8
0
    def get_verification(self,
                         verification_id=None,
                         code=None,
                         email=None,
                         mobile=None,
                         category=None,
                         account_id=None,
                         resend_code=None):
        '''
        retrieves verification information based on information in given object
        
        '''
        verification_object = None

        criteria = {}

        if verification_id:
            criteria['id'] = verification_id

        if code:
            criteria['code'] = code

        if account_id:
            criteria['account_id'] = account_id

        if category:
            criteria['category'] = category

        if mobile:
            criteria['mobile'] = mobile

        if email:
            criteria['email'] = email

        if resend_code:
            criteria['resend_code'] = resend_code

        if criteria:
            table_cols = [
                'id', 'email', 'account_id', 'code', 'mobile', 'category',
                'date_expiry', 'send_status', 'resend_code'
            ]

            try:
                result = self.dbconn.execute_select(table_name='verification',
                                                    conditions=criteria,
                                                    operator='AND',
                                                    table_cols=table_cols,
                                                    fetchall=False)

            except Exception, e:
                raise VerificationError('unable to retrieve verification: %s' %
                                        e)

            if result:

                verification_object = Verification()

                verification_object.verification_id = result['id']
                verification_object.email = result['email']
                verification_object.account_id = result['account_id']
                verification_object.code = result['code']
                verification_object.resend_code = result['resend_code']

                verification_object.mobile = result['mobile']
                verification_object.verification_category = result['category']

                # magically retured as datetime object
                verification_object.date_expiry = result['date_expiry']