Exemplo n.º 1
0
    def get_widgets(self, resource, context):
        widgets = [ReadOnlyWidget('cls_description'), HiddenWidget('referrer')]
        for name in self.get_fields():
            widget = self._get_widget(resource, context, name)
            widgets.append(widget)

        return widgets
Exemplo n.º 2
0
 def get_widgets(self, resource, context):
     widgets = super(RegisterForm, self).get_widgets(resource, context)
     if context.user:
         # E-mail becomes hard coded
         widgets = list(widgets)
         email = widgets[0]
         widgets[0] = ReadOnlyWidget(name=email.name,
                                     focus=True,
                                     title=email.title)
     return widgets
Exemplo n.º 3
0
class ConfirmSubscription(AutoForm):

    access = 'is_allowed_to_view'
    title = MSG(u"Subscribe")
    description = MSG(
        u'By confirming your subscription to this resource you will'
        u' receive an email every time this resource is modified.')

    schema = freeze({
        'key': String(mandatory=True),
        'email': Email(mandatory=True)
    })
    widgets = freeze([HiddenWidget('key'), ReadOnlyWidget('email')])
    actions = [Button(access=True, title=MSG(u'Confirm subscription'))]

    key_status = 'S'
    msg_already = MSG_USER_ALREADY_SUBSCRIBED

    def get_value(self, resource, context, name, datatype):
        if name in ('key', 'email'):
            return context.get_query_value(name)
        proxy = super(ConfirmSubscription, self)
        return proxy.get_value(resource, context, name, datatype)

    def get_username(self, resource, context, key):
        # 1. Get the user
        email = context.get_form_value('email')
        user = context.root.get_user_from_login(email)
        if user is None:
            return None, MSG(u'Bad email')

        # 2. Get the user key
        username = user.name
        user_key = resource.get_register_key(username, self.key_status)
        if user_key is None:
            return username, self.msg_already

        # 3. Check the key
        if user_key != key:
            return username, MSG_BAD_KEY

        # 4. Ok
        return username, None

    def get_namespace(self, resource, context):
        key = context.get_form_value('key')
        username, error = self.get_username(resource, context, key)
        if error:
            return context.come_back(error, goto='./')

        proxy = super(ConfirmSubscription, self)
        return proxy.get_namespace(resource, context)

    def action(self, resource, context, form):
        username, error = self.get_username(resource, context, form['key'])
        if error:
            context.message = error
            return

        # Ok
        resource.reset_register_key(username)
        resource.after_register(username)
        return context.come_back(MSG_USER_SUBSCRIBED, goto='./')
Exemplo n.º 4
0
class User_ConfirmRegistration(AutoForm):

    access = True
    title = MSG(u'Choose your password')
    description = MSG(u'To activate your account, please type a password.')

    schema = freeze({
        'key': String(mandatory=True),
        'username': String,
        'newpass': ChoosePassword_Datatype(mandatory=True),
        'newpass2': String(mandatory=True)
    })
    widgets = freeze([
        HiddenWidget('key'),
        ReadOnlyWidget('username', title=MSG(u'Username')),
        ChoosePassword_Widget('newpass', userid='username'),
        PasswordWidget('newpass2', title=MSG(u'Repeat password'))
    ])

    def get_value(self, resource, context, name, datatype):
        if name == 'key':
            return resource.get_property('user_state').get_parameter('key')
        if name == 'username':
            return resource.get_login_name()

        proxy = super(User_ConfirmRegistration, self)
        return proxy.get_value(resource, context, name, datatype)

    def get_namespace(self, resource, context):
        # Check register key
        username = context.get_form_value('username', default='')

        key = resource.get_property('user_state').get_parameter('key')
        if key is None:
            goto = '/;login?username=%s' % username
            return context.come_back(messages.MSG_REGISTERED, goto=goto)
        elif context.get_form_value('key') != key:
            goto = '/;login?username=%s' % username
            return context.come_back(messages.MSG_BAD_KEY, goto=goto)

        proxy = super(User_ConfirmRegistration, self)
        return proxy.get_namespace(resource, context)

    def _get_form(self, resource, context):
        proxy = super(User_ConfirmRegistration, self)
        form = proxy._get_form(resource, context)
        if form['username'] == form['newpass']:
            raise FormError, messages.MSG_PASSWORD_EQUAL_TO_USERNAME
        return form

    def action(self, resource, context, form):
        # Check register key
        key = resource.get_property('user_state').get_parameter('key')
        if not key:
            context.message = MSG(u'User is not pending')
            return

        if form['key'] != key:
            context.message = messages.MSG_BAD_KEY
            return

        # Check passwords
        password = form['newpass']
        password2 = form['newpass2']
        if password != password2:
            context.message = messages.MSG_PASSWORD_MISMATCH
            return

        # Set user
        resource.set_value('password', password)
        resource.del_property('user_state')
        # Set cookie
        resource._login(password, context)

        # Send email
        to_addr = resource.get_value('email')
        send_email('register-send-confirmation',
                   context,
                   to_addr,
                   user=resource)

        # Ok
        message = INFO(u'Operation successful! Welcome.')
        return context.come_back(message, goto='./')