示例#1
0
文件: models.py 项目: meZee/pyaspora
    def notify_event(self, commit=True):
        """
        Let the user know that there are new things for them to view, according
        to their notification preferences.
        """
        if not self.activated:
            return  # notifications disabled until activated

        if not self.notification_hours:
            return  # notifications disabled

        if self.last_notified and self.last_notified > \
                datetime.now() - timedelta(hours=self.notification_hours):
            return  # too soon

        send_template(self.email, 'user_event_email.tpl', {})

        self.last_notified = datetime.now()
        db.session.add(self)
        if commit:
            db.session.commit()
示例#2
0
文件: views.py 项目: jaywink/pyaspora
def create():
    """
    Create a new User (sign-up).
    """
    if not _can_create_account():
        abort(403, 'Disabled by site administrator')

    user = logged_in_user()
    if user:
        data = {}
        add_logged_in_user_to_data(data, user)
        abort(400, 'Already logged in', data)

    name = post_param('name', template='users_create_form.tpl')
    password = post_param('password', template='users_create_form.tpl')
    email = post_param('email', template='users_create_form.tpl')

    my_user = models.User()
    my_user.email = email
    my_user.contact.realname = name
    my_user.generate_keypair(password)
    db.session.commit()

    send_template(my_user.email, 'user_activate_email.tpl', {
        'link': url_for(
            '.activate',
            user_id=my_user.id,
            key_hash=_hash_for_pk(my_user),
            _external=True
        )
    })

    data = {}
    add_logged_in_user_to_data(data, None)

    return render_response('users_created.tpl', data)
示例#3
0
def create():
    """
    Create a new User (sign-up).
    """
    if not current_app.config.get('ALLOW_CREATION', False):
        abort(403, 'Disabled by site administrator')

    user = logged_in_user()
    if user:
        data = {}
        add_logged_in_user_to_data(data, user)
        abort(400, 'Already logged in', data)

    name = post_param('name', template='users_create_form.tpl')
    password = post_param('password', template='users_create_form.tpl')
    email = post_param('email', template='users_create_form.tpl')

    my_user = models.User()
    my_user.email = email
    my_user.contact.realname = name
    my_user.generate_keypair(password)
    db.session.commit()

    send_template(my_user.email, 'user_activate_email.tpl', {
        'link': url_for(
            '.activate',
            user_id=my_user.id,
            key_hash=_hash_for_pk(my_user),
            _external=True
        )
    })

    data = {}
    add_logged_in_user_to_data(data, None)

    return render_response('users_created.tpl', data)