Beispiel #1
0
    def activate(self, email, code):
        reg = Registration.get_inactive(email, code)
        if not reg:
            flash(_('Registration not found or already activated'))
            return redirect(self.mount_point)

        u = app_model.User(user_name=reg.user_name,
                           display_name=reg.user_name,
                           email_address=reg.email_address,
                           password=reg.password)

        hooks = config['hooks'].get('registration.before_activation', [])
        for func in hooks:
            func(reg, u)

        DBSession.add(u)

        reg.user = u
        reg.password = '******'
        reg.activated = datetime.now()

        hooks = config['hooks'].get('registration.after_activation', [])
        for func in hooks:
            func(reg, u)

        flash(_('Account succesfully activated'))
        return redirect('/')
 def out_of_uow_flush(self, entity):
     try:
         DBSession.flush()
     except DuplicateKeyError:
         DBSession.clear()
         raise DalIntegrityError
     return entity
 def out_of_uow_flush(self, entity=None):
     DBSession.add(entity)
     try:
         DBSession.flush()
     except IntegrityError:
         transaction.doom()
         raise DalIntegrityError
     return entity
Beispiel #4
0
 def validate_python(self, value, state):
     super(UniqueEmailValidator, self).validate_python(value, state)
     if re.match("^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$", value):
         reg = DBSession.query(app_model.User).filter_by(email_address=value).first()
         user = DBSession.query(app_model.User).filter_by(email_address=value).first()
         if reg or user:
             raise Invalid(_('Email address has already been taken'), value, state)
     else:
         raise Invalid(_('Invalid email'), value, state)
Beispiel #5
0
 def validate_python(self, value, state):
     super(UniqueUserValidator, self).validate_python(value, state)
     if re.match("^[a-zA-Z0-9_-]*[a-zA-Z_-][a-zA-Z0-9_-]*$", value):
         reg = DBSession.query(app_model.User).filter_by(user_name=value).first()
         user = DBSession.query(app_model.User).filter_by(user_name=value).first()
         if reg or user:
             raise Invalid(_('username already in use.'), value, state)
     else:
         raise Invalid(_('Invalid username'), value, state)
Beispiel #6
0
 def new(self, **kw):
     new_reg = Registration()
     new_reg.email_address = kw['email_address']
     new_reg.user_name = kw['user_name']
     new_reg.password = kw['password']
     new_reg.code = Registration.generate_code(kw['email_address'])
     DBSession.add(new_reg)
     DBSession.flush()
     return new_reg
Beispiel #7
0
    def submit(self, *args, **kw):
        hooks = config['hooks'].get('registration.before_registration', [])
        for func in hooks:
            func(kw)

        new_reg = Registration()
        new_reg.email_address = kw['email_address']
        new_reg.user_name = kw['user_name']
        new_reg.password = kw['password']
        new_reg.code = Registration.generate_code(kw['email_address'])
        DBSession.add(new_reg)
        DBSession.flush()

        hooks = config['hooks'].get('registration.after_registration', [])
        for func in hooks:
            func(new_reg, kw)

        return redirect(url(self.mount_point + '/complete',
                            params=dict(code=new_reg.code, email=new_reg.email_address)))
Beispiel #8
0
 def generate_code(cls, email):
     code_space = string.ascii_letters + string.digits
     def _generate_code_impl():
         base = ''.join(random.sample(code_space, 8))
         base += email
         base += str(time.time())
         return hashlib.sha1(base).hexdigest()
     code = _generate_code_impl()
     while DBSession.query(cls).filter_by(code=code).first():
         code = _generate_code_impl()
     return code
 def generate_code(cls, email):
     code_space = string.ascii_letters + string.digits
     def _generate_code_impl():
         base = ''.join(random.sample(code_space, 8))
         base += email
         base += str(time.time())
         return hashlib.sha1(base.encode('utf-8')).hexdigest()
     code = _generate_code_impl()
     while DBSession.query(cls).filter_by(code=code).first():
         code = _generate_code_impl()
     return code
Beispiel #10
0
 def get_inactive(cls, email_address, code):
     return DBSession.query(Registration).filter_by(activated=None)\
                                         .filter_by(code=code)\
                                         .filter_by(email_address=email_address).first()
Beispiel #11
0
 def clear_expired(cls):
     expired = DBSession.query(cls).filter_by(activated=None)\
                                   .filter(Registration.time<datetime.now()-timedelta(7)).delete()
    def new(self, **kw):
        new_reg = Registration(**kw)

        new_reg.code = Registration.generate_code(kw['email_address'])
        DBSession.flush()
        return new_reg
Beispiel #13
0
 def by_email(self, email):
     return DBSession.query(Registration).filter_by(email_address=email).first()
Beispiel #14
0
 def get_inactive(cls, code):
     return DBSession.query(Registration).filter_by(activated=None)\
                                         .filter_by(code=code).first()
Beispiel #15
0
 def clear_expired(cls):
     for expired_reg in DBSession.query(cls).filter_by(activated=None)\
                                   .filter(Registration.time<datetime.now()-timedelta(days=2)):
         DBSession.delete(expired_reg)
Beispiel #16
0
 def pending_activation(self):
     return DBSession.query(Registration).filter(Registration.activated==None)