Exemplo n.º 1
0
    def update(self, id):
        c.page_user = get_entity_or_abort(model.User, id,
                                          instance_filter=False)
        require.user.edit(c.page_user)
        if self.form_result.get("password_change"):
            c.page_user.password = self.form_result.get("password_change")
        c.page_user.display_name = self.form_result.get("display_name")
        c.page_user.page_size = self.form_result.get("page_size")
        c.page_user.no_help = self.form_result.get("no_help")
        c.page_user.bio = self.form_result.get("bio")
        email = self.form_result.get("email").lower()
        email_changed = email != c.page_user.email
        c.page_user.email = email
        c.page_user.email_priority = self.form_result.get("email_priority")
        #if c.page_user.twitter:
        #    c.page_user.twitter.priority = \
        #        self.form_result.get("twitter_priority")
        #    model.meta.Session.add(c.page_user.twitter)
        locale = Locale(self.form_result.get("locale"))
        if locale and locale in i18n.LOCALES:
            c.page_user.locale = locale
        model.meta.Session.add(c.page_user)
        model.meta.Session.commit()
        if email_changed:
            libmail.send_activation_link(c.page_user)

        if c.page_user == c.user:
            event.emit(event.T_USER_EDIT, c.user)
        else:
            event.emit(event.T_USER_ADMIN_EDIT, c.page_user, admin=c.user)
        redirect(h.entity_url(c.page_user))
Exemplo n.º 2
0
    def create(self):
        require.user.create()
        if self.email_is_blacklisted(self.form_result['email']):
            return ret_abort(_("Sorry, but we don't accept registrations with "
                               "this email address."), category='error',
                             code=403)

        # SPAM protection recaptcha
        captacha_enabled = config.get('recaptcha.public_key', "")
        if captacha_enabled:
            recaptcha_response = h.recaptcha.submit()
            if not recaptcha_response.is_valid:
                c.recaptcha = h.recaptcha.displayhtml(
                    use_ssl=True,
                    error=recaptcha_response.error_code)
                redirect("/register")
        # SPAM protection hidden input
        input_css = self.form_result.get("input_css")
        input_js = self.form_result.get("input_js")
        if input_css or input_js:
            redirect("/")

        #create user
        user = model.User.create(self.form_result.get("user_name"),
                                 self.form_result.get("email").lower(),
                                 password=self.form_result.get("password"),
                                 locale=c.locale)
        model.meta.Session.commit()

        event.emit(event.T_USER_CREATE, user)
        libmail.send_activation_link(user)

        if c.instance:
            membership = user.instance_membership(c.instance)
            if membership is None:
                membership = model.Membership(user, c.instance,
                                              c.instance.default_group)
                model.meta.Session.expunge(membership)
                model.meta.Session.add(membership)
                model.meta.Session.commit()

        # authenticate the new registered member using the repoze.who
        # api. This is done here and not with an redirect to the login
        # to omit the generic welcome message
        who_api = get_api(request.environ)
        login = self.form_result.get("user_name").encode('utf-8')
        credentials = {
            'login': login,
            'password': self.form_result.get("password").encode('utf-8')}
        authenticated, headers = who_api.login(credentials)
        if authenticated:
            # redirect to dashboard with login message
            session['logged_in'] = True
            session.save()
            location = h.base_url('/user/%s/dashboard' % login)
            raise HTTPFound(location=location, headers=headers)
        else:
            raise Exception('We have added the user to the Database '
                            'but cannot authenticate him: '
                            '%s (%s)' % (credentials['login'], user))
Exemplo n.º 3
0
 def resend(self, id):
     c.page_user = get_entity_or_abort(model.User, id,
                                       instance_filter=False)
     require.user.edit(c.page_user)
     libmail.send_activation_link(c.page_user)
     h.flash(_("The activation link has been re-sent to your email "
               "address."), 'notice')
     redirect(h.entity_url(c.page_user, member='edit'))
Exemplo n.º 4
0
Arquivo: user.py Projeto: whausen/part
 def resend(self, id):
     c.page_user = get_entity_or_abort(model.User, id,
                                       instance_filter=False)
     require.user.edit(c.page_user)
     libmail.send_activation_link(c.page_user)
     path = request.params.get('came_from', None)
     ret_success(
         message=_("The activation link has been re-sent to your email "
                   "address."), category='success',
         entity=c.page_user, member='edit', force_path=path)
Exemplo n.º 5
0
 def _create(self, user_name, email, identity):
     """
     Create a user based on data gathered from OpenID
     """
     user = model.User.create(user_name, email, locale=c.locale, openid_identity=identity)
     if email is not None:
         if is_trusted_provider(identity):
             # trust provided email:
             user.activation_code = None
         else:
             libmail.send_activation_link(user)
     model.meta.Session.commit()
     event.emit(event.T_USER_CREATE, user)
     return user
Exemplo n.º 6
0
Arquivo: user.py Projeto: whausen/part
    def update(self, id):
        c.page_user = get_entity_or_abort(model.User, id,
                                          instance_filter=False)
        require.user.edit(c.page_user)
        if self.form_result.get("password_change"):
            c.page_user.password = self.form_result.get("password_change")
        c.page_user.display_name = self.form_result.get("display_name")
        c.page_user.page_size = self.form_result.get("page_size")
        c.page_user.no_help = self.form_result.get("no_help")
        c.page_user.bio = self.form_result.get("bio")
        c.page_user.proposal_sort_order = self.form_result.get(
            "proposal_sort_order")
        if c.page_user.proposal_sort_order == "":
            c.page_user.proposal_sort_order = None
        get_gender = self.form_result.get("gender")
        if get_gender in ('f', 'm', 'u'):
            c.page_user.gender = get_gender
        email = self.form_result.get("email")
        old_email = c.page_user.email
        old_activated = c.page_user.is_email_activated()
        email_changed = email != old_email
        c.page_user.email = email
        c.page_user.email_priority = self.form_result.get("email_priority")
        #if c.page_user.twitter:
        #    c.page_user.twitter.priority = \
        #        self.form_result.get("twitter_priority")
        #    model.meta.Session.add(c.page_user.twitter)
        locale = Locale(self.form_result.get("locale"))
        if locale and locale in i18n.LOCALES:
            c.page_user.locale = locale
        model.meta.Session.add(c.page_user)
        model.meta.Session.commit()
        if email_changed:
            # Logging email address changes in order to ensure accountability
            log.info('User %s changed email address from %s%s to %s' % (
                c.page_user.user_name,
                old_email,
                ' (validated)' if old_activated else '',
                email))
            libmail.send_activation_link(c.page_user)

        if c.page_user == c.user:
            event.emit(event.T_USER_EDIT, c.user)
        else:
            event.emit(event.T_USER_ADMIN_EDIT, c.page_user, admin=c.user)
        redirect(h.entity_url(c.page_user))
Exemplo n.º 7
0
 def _create(self, user_name, email, identity):
     """
     Create a user based on data gathered from OpenID
     """
     user = model.User.create(user_name,
                              email,
                              locale=c.locale,
                              openid_identity=identity)
     if email is not None:
         if is_trusted_provider(identity):
             # trust provided email:
             user.activation_code = None
         else:
             libmail.send_activation_link(user)
     model.meta.Session.commit()
     event.emit(event.T_USER_CREATE, user)
     return user
Exemplo n.º 8
0
    def create(self):
        require.user.create()
        # SPAM protection recaptcha
        captacha_enabled = config.get('recaptcha.public_key', "")
        if captacha_enabled:
            recaptcha_response = h.recaptcha.submit()
            if not recaptcha_response.is_valid:
                c.recaptcha = h.recaptcha.displayhtml(
                    error=recaptcha_response.error_code)
                redirect("/register")
        # SPAM protection hidden input
        input_css = self.form_result.get("input_css")
        input_js = self.form_result.get("input_js")
        if input_css or input_js:
            redirect("/")

        #create user
        user = model.User.create(self.form_result.get("user_name"),
                                 self.form_result.get("email").lower(),
                                 password=self.form_result.get("password"),
                                 locale=c.locale)
        model.meta.Session.commit()

        event.emit(event.T_USER_CREATE, user)
        libmail.send_activation_link(user)

        if c.instance:
            membership = model.Membership(user, c.instance,
                                          c.instance.default_group)
            model.meta.Session.expunge(membership)
            model.meta.Session.add(membership)
            model.meta.Session.commit()

        # info message
        h.flash(
            _("You have successfully registered as user %s.") % user.name,
            'success')
        redirect("/perform_login?%s" % urllib.urlencode(
            {
                'login': self.form_result.get("user_name").encode('utf-8'),
                'password': self.form_result.get("password").encode('utf-8')
            }))
Exemplo n.º 9
0
    def create(self):
        require.user.create()
        # SPAM protection recaptcha
        captacha_enabled = config.get('recaptcha.public_key', "")
        if captacha_enabled:
            recaptcha_response = h.recaptcha.submit()
            if not recaptcha_response.is_valid:
                c.recaptcha = h.recaptcha.displayhtml(error=recaptcha_response.error_code) 
                redirect("/register")
        # SPAM protection hidden input
        input_css = self.form_result.get("input_css")
        input_js = self.form_result.get("input_js")
        if input_css or input_js:
            redirect("/")

        #create user
        user = model.User.create(self.form_result.get("user_name"),
                                 self.form_result.get("email").lower(),
                                 password=self.form_result.get("password"),
                                 locale=c.locale)
        model.meta.Session.commit()

        event.emit(event.T_USER_CREATE, user)
        libmail.send_activation_link(user)

        if c.instance:
            membership = model.Membership(user, c.instance,
                                          c.instance.default_group)
            model.meta.Session.expunge(membership)
            model.meta.Session.add(membership)
            model.meta.Session.commit()

        # info message
        h.flash(_("You have successfully registered as user %s.") % user.name,
                'success')
        redirect("/perform_login?%s" % urllib.urlencode({
                 'login': self.form_result.get("user_name").encode('utf-8'),
                 'password': self.form_result.get("password").encode('utf-8')
                }))