Ejemplo n.º 1
0
class FeederCreateForm(BaseForm):
    fields = [
        #ConfigChoiceField("type", "Role", "FeederRole", attrs = REQUIRED)
        StringField("name", "Name"),
        EmailField("email", "Email"),
        StringField("pwd", "Password"),
        CountrySearchField('Country',
                           "Country",
                           "/admin/search/address",
                           "AddressSearchResult",
                           api_allow_new=False,
                           query_extra={'type': 'Country'},
                           classes='tagsearch input-xxlarge')
    ]

    @classmethod
    def on_success(cls, request, values):
        try:
            result = CreateUserProc(request, values)
        except DBMessage, e:
            result = {'success': False, 'errors': {}, 'values': values}
            if e.message == 'EMAIL_TAKEN':
                result['errors'] = {'email': "Email already taken"}
            else:
                result['message'] = e.message
            return result
        request.session.flash(
            GenericSuccessMessage(
                u"New user {name} ({email}) created".format(**values)),
            "generic_messages")
        return {
            'success': True,
            'redirect': request.fwd_url("admin_settings_feeder_create")
        }
Ejemplo n.º 2
0
 def on_success(self, request, values):
     try:
         UpdatePasswordProc(request, {'token':request.root.user.token, 'pwd':values['pwd']})
     except DBMessage:
         raise # HORROR HAPPENED
     request.session.flash(GenericSuccessMessage("Your password has been changed. You can now log in using your new password."), "generic_messages")
     request.fwd("website_index")
Ejemplo n.º 3
0
def set_review_status(context, request):
    status = request.params.get("status")
    collectorId = request.matchdict['collectorId']
    if status == 'DEACTIVATE':
        DeactivateCollectorProc(request, {'id': collectorId})
        refreshAllCacheds(request)
        request.session.flash(GenericSuccessMessage("Collector Deactivated, now the collector is not visible in frontend."), "generic_messages")
        return request.fwd_raw(request.referer)
    else:
        collector = GetCollectorDetailsProc(request, {'id': collectorId})
        if status == 'SUBMIT' and collector.canSubmitforReview(context.user):
            SetCollectorStatusProc(request, {'id': collectorId, 'status':"SUBMITTED"})
            request.session.flash(GenericSuccessMessage("This collector has now been submitted for review!"), "generic_messages")
        elif status == 'APPROVE' and collector.canReview(context.user):
            SetCollectorStatusProc(request, {'id': collectorId, 'status':"REVIEWED"})
            request.session.flash(GenericSuccessMessage("This collector has now been approved!"), "generic_messages")
        else:
            request.session.flash(GenericErrorMessage("Not allowed"), "generic_messages")
        refreshAllCacheds(request)
        return request.fwd_raw(request.referer)
Ejemplo n.º 4
0
 def on_success(cls, request, values):
     try:
         UpdatePasswordProc(request, {
             'token': request.context.user.token,
             'pwd': values['pwd']
         })
     except DBMessage:
         raise  # HORROR HAPPENED
     request.session.flash(GenericSuccessMessage(cls.successmsg),
                           "generic_messages")
     return {
         'success': True,
         'redirect': request.fwd_url("admin_index"),
         'message': cls.successmsg
     }
Ejemplo n.º 5
0
class PasswordforgotForm(BaseForm):
    id = 'pwdforgot'
    label = "Forgot password"
    action_label = "Submit"
    fields = [EmailField("email", "Email", REQUIRED)]

    @classmethod
    def on_success(cls, request, values):
        email = values['email']
        try:
            if request.json_body.get('isResend'):
                ResendRequestProc(request, {'email': email})
            else:
                PasswordRequestProc(request, {'email': email})
        except DBMessage, e:
            if e.message in [
                    'NO_USER', 'NO_USER_WITH_THIS_EMAIL',
                    'NO_OWNER_WITH_THIS_EMAIL'
            ]:
                errors = {"email": "Unknown email address."}
                return {'values': values, 'errors': errors}
            elif e.message == "TOKEN_SET_IN_LAST_24_HOURS":
                values['isResend'] = True
                return {
                    'values': values,
                    'errors': {
                        'email': "Email has been sent in last 24 hours!"
                    }
                }
            else:
                raise e
        request.session.flash(
            GenericSuccessMessage(
                "An email to reset your password has been sent to: {email}!".
                format(**values)), "generic_messages")
        return {"success": True, "redirect": request.fwd_url("admin_login")}
Ejemplo n.º 6
0
    def validate_form(self):
        values = variable_decode(self.request.params)
        schema_id = values.get('type')
        if not schema_id: raise HTTPNotImplemented()
        try:
            resp = self.validate_values(values)
        except Invalid, error:
            log.error(error.error_dict)
            self.result['values'][schema_id] = error.value or {}
            self.result['errors'][schema_id] = error.error_dict or {}
            self.request.response.status_int = 401
        else:
            ### if validate_values/on_success returns anything else than a redirect, it must be some validation error
            if resp.get('message'):
                if resp.get('success') == True:
                    self.request.session.flash(GenericSuccessMessage(resp.get('message')), 'generic_messages')
                elif resp.get('success') == False:
                    self.request.session.flash(GenericErrorMessage(resp.get('message')), 'generic_messages')
            if resp.get('redirect'):
                self.request.fwd_raw(resp.get('redirect'))

            self.result['values'][schema_id] = resp.get('values', values)
            self.result['errors'][schema_id] = resp.get('errors', {})
            self.request.response.status_int = 401
        self.result = self.add_globals(self.request, self.result)
        return self.result

    def validate_json(self, renderTemplates = {}):
        values = self.request.json_body
        schema_id = values['type']