Exemple #1
0
    def update(self):
        request = self.request

        principal = authenticated_userid(request)
        user = User.getByURI(principal)
        if user is None:
            self.token = token = request.params.get('token')
            if token:
                self.userid = tokenService.get(token)
                if self.userid is None:
                    return HTTPFound(location='/reset-password.html')

                user = User.getById(self.userid)

        if user is None:
            return HTTPFound(location='/reset-password.html')

        if 'form-change' in request.POST:
            password = request.POST.get('change-password')
            confirm = request.POST.get('confirm-password')
            if not password:
                return

            if password != confirm:
                self.message = \
                    'Password and Confirm password has to be identical.'

            if self.userid is not None:
                tokenService.remove(self.token)

            user.password = ptah.pwd_tool.encode(password)
            if not user.validated:
                user.validated = datetime.now()

            headers = {}
            if not principal:
                headers = remember(request, user.__uri__)

            return HTTPFound(
                location='/dashboard.html?message=Password has been changed',
                headers = headers)

        token = request.params.get('token')
        if not token and user is None:
            return HTTPFound(location='/dashboard.html')
Exemple #2
0
def SignupView(request):
    PLOUD = ptah.get_settings('ploud', request.registry)
    allowed = PLOUD['registration']
    if not allowed:
        return HTTPFound(location = '/waitinglist.html')

    principal = authenticated_userid(request)
    if principal:
        return HTTPFound(location = '/dashboard.html')

    errors, data = validate_signup(request)
    if errors:
        return HTTPFound(location='/index.html')

    email = data['signup-email']
    site_name = data['signup-site-name']
    site_language = data['signup-site-language']
    password = ''.join(
        random.choice(ALLOWED_SITE_NAME_CHARS) for i in range(8))

    user = User(email, ptah.pwd_tool.encode(password), 98)
    token = user.token
    Session = ptah.get_session()
    Session.add(user)
    Session.flush()

    uri = user.__uri__

    FE = ptah.get_settings('frontend', request.registry)

    if FE['validation']:
        send_activation(email, token)
    else:
        user.type = 0
        user.token = None
        user.validated = datetime.datetime.now()

    try:
        utils.provision_site(user, 'plone41', site_name, language=site_language)
    except Exception, exc:
        transaction.abort()
        errors = {'signup-site-name': str(exc)}
        log.exception('Site provision problem')
        return HTTPFound(location='/index.html')
Exemple #3
0
def initialize(ev):
    pconfig = ev.config

    # mount application to '/' location wit custom ApplicationRoot
    factory = ptah.cms.ApplicationFactory(
        PloudApplicationRoot, "/", "root", "Ptah CMS", ApplicationPolicy, default_root=True
    )
    pconfig.set_root_factory(factory)

    # give managers all permissions
    acl = [(Allow, Everyone, ptah.cms.View)]
    for login in PTAH_CONFIG.managers:
        user = User.get(login)
        if user is not None:
            acl.append((Allow, user.uri, ALL_PERMISSIONS))

            # theme gallery
            GALLERY_ACL.allow(user.uri, ALL_PERMISSIONS)

    ApplicationPolicy.__acl__ = acl