コード例 #1
0
ファイル: __init__.py プロジェクト: Forkk/notifico
def dashboard(u):
    """
    Display an overview of all the user's projects with summary
    statistics.
    """
    u = User.by_username(u)
    if not u:
        # No such user exists.
        return abort(404)

    is_owner = (g.user and g.user.id == u.id)

    # Get all projects by decending creation date.
    projects = (
        u.projects
        .order_by(False)
        .order_by(Project.created.desc())
    )
    if not is_owner:
        # If this isn't the users own page, only
        # display public projects.
        projects = projects.filter_by(public=True)

    return render_template('dashboard.html',
        user=u,
        is_owner=is_owner,
        projects=projects,
        page_title='Notifico! - {u.username}\'s Projects'.format(
            u=u
        )
    )
コード例 #2
0
ファイル: __init__.py プロジェクト: rom1504/notifico
def dashboard(u):
    """
    Display an overview of all the user's projects with summary
    statistics.
    """
    u = User.by_username(u)
    if not u:
        # No such user exists.
        return abort(404)

    is_owner = (g.user and g.user.id == u.id)

    # Get all projects by decending creation date.
    projects = (u.projects.order_by(False).order_by(Project.created.desc()))
    if not is_owner:
        # If this isn't the users own page, only
        # display public projects.
        projects = projects.filter_by(public=True)

    return render_template(
        'dashboard.html',
        user=u,
        is_owner=is_owner,
        projects=projects,
        page_title='Notifico! - {u.username}\'s Projects'.format(u=u))
コード例 #3
0
ファイル: forms.py プロジェクト: CompanyOnTheWorld/notifico
    def validate_username(form, field):
        from notifico.views.account import _reserved

        username = field.data.strip().lower()
        if username in _reserved or User.username_exists(username):
            raise wtf.ValidationError(
                'Sorry, but that username is taken.'
            )
コード例 #4
0
ファイル: forms.py プロジェクト: rom1504/notifico
    def validate_username(form, field):
        user = User.by_username(field.data)
        if not user:
            raise wtf.ValidationError('No such user exists.')

        if reset.count_tokens(user) >= 5:
            raise wtf.ValidationError(
                'You may not reset your password more than 5 times'
                ' in one day.')
コード例 #5
0
ファイル: forms.py プロジェクト: CompanyOnTheWorld/notifico
    def validate_username(form, field):
        user = User.by_username(field.data)
        if not user:
            raise wtf.ValidationError('No such user exists.')

        if reset.count_tokens(user) >= 5:
            raise wtf.ValidationError(
                'You may not reset your password more than 5 times'
                ' in one day.'
            )
コード例 #6
0
ファイル: __init__.py プロジェクト: whitequark/notifico
def forgot_password():
    """
    If NOTIFICO_PASSWORD_RESET is enabled and Flask-Mail is configured,
    this view allows you to request a password reset email. It also
    handles accepting those tokens.
    """
    # Because this functionality depends on Flask-Mail and
    # celery being properly configured, we default to disabled.
    if not current_app.config.get('NOTIFICO_PASSWORD_RESET'):
        flash(
            'Password resets have been disabled by the administrator.',
            category='warning'
        )
        return redirect('.login')

    # How long should reset tokens last? We default
    # to 24 hours.
    token_expiry = current_app.config.get(
        'NOTIFICO_PASSWORD_RESET_EXPIRY',
        60 * 60 * 24
    )

    form = UserForgotForm()
    if form.validate_on_submit():
        user = User.by_username(form.username.data)
        new_token = reset.add_token(user, expire=token_expiry)

        # Send the email as a background job so we don't block
        # up the browser (and to use celery's built-in rate
        # limiting).
        background.send_mail.delay(
            'Notifico - Password Reset for {username}'.format(
                username=user.username
            ),
            # We're already using Jinja2, so we might as well use
            # it to render our email templates as well.
            html=render_template(
                'email_reset.html',
                user=user,
                reset_link=url_for(
                    '.reset_password',
                    token=new_token,
                    uid=user.id,
                    _external=True
                ),
                hours=token_expiry / 60 / 60
            ),
            recipients=[user.email],
            sender=current_app.config['NOTIFICO_MAIL_SENDER']
        )
        flash('A reset email has been sent.', category='success')
        return redirect(url_for('.login'))

    return render_template('forgot.html', form=form)
コード例 #7
0
ファイル: __init__.py プロジェクト: rom1504/notifico
def admin_user(username):
    do = request.args.get('do', None)
    u = User.by_username(username)
    if u is None:
        return abort(404)

    password_form = UserPasswordForm()

    if do == 'p' and password_form.validate_on_submit():
        u.set_password(password_form.password.data)
        db.session.commit()
        return redirect(url_for('.admin_user', username=username))

    return render_template('admin_user.html', u=u, password_form=password_form)
コード例 #8
0
ファイル: __init__.py プロジェクト: Forkk/notifico
def login():
    """
    Standard login form.
    """
    if g.user:
        return redirect(url_for('public.landing'))

    form = UserLoginForm()
    if form.validate_on_submit():
        u = User.by_username(form.username.data)
        session['_u'] = u.id
        session['_uu'] = u.username
        return redirect(url_for('projects.dashboard', u=u.username))

    return render_template('login.html', form=form)
コード例 #9
0
ファイル: __init__.py プロジェクト: Forkk/notifico
    def _wrapped(*args, **kwargs):
        u = User.by_username(kwargs.pop('u'))
        if not u:
            # No such user exists.
            return abort(404)

        p = Project.by_name_and_owner(kwargs.pop('p'), u)
        if not p:
            # Project doesn't exist (404 Not Found)
            return abort(404)

        kwargs['p'] = p
        kwargs['u'] = u

        return f(*args, **kwargs)
コード例 #10
0
ファイル: __init__.py プロジェクト: rom1504/notifico
    def _wrapped(*args, **kwargs):
        u = User.by_username(kwargs.pop('u'))
        if not u:
            # No such user exists.
            return abort(404)

        p = Project.by_name_and_owner(kwargs.pop('p'), u)
        if not p:
            # Project doesn't exist (404 Not Found)
            return abort(404)

        kwargs['p'] = p
        kwargs['u'] = u

        return f(*args, **kwargs)
コード例 #11
0
ファイル: __init__.py プロジェクト: whitequark/notifico
def login():
    """
    Standard login form.
    """
    if g.user:
        return redirect(url_for('public.landing'))

    form = UserLoginForm()
    if form.validate_on_submit():
        u = User.by_username(form.username.data)
        session['_u'] = u.id
        session['_uu'] = u.username
        return redirect(url_for('projects.dashboard', u=u.username))

    return render_template('login.html', form=form)
コード例 #12
0
ファイル: __init__.py プロジェクト: ammaraskar/notifico
def overview(u):
    """
    Display an overview of all the user's projects with summary
    statistics.
    """
    u = User.by_username(u)
    if not u:
        # No such user exists.
        return abort(404)

    is_owner = (g.user and g.user.id == u.id)

    return render_template('overview.html',
        user=u,
        is_owner=is_owner
    )
コード例 #13
0
ファイル: __init__.py プロジェクト: ammaraskar/notifico
def login():
    """
    Standard login form.
    """
    if g.user:
        flash('You must logout before logging in.', 'error')
        return redirect(url_for('public.landing'))

    form = UserLoginForm()
    if form.validate_on_submit():
        u = User.by_username(form.username.data)
        session['_u'] = u.id
        session['_uu'] = u.username
        flash('Welcome back!', 'success')
        return redirect(url_for('public.landing'))

    return render_template('login.html', form=form)
コード例 #14
0
ファイル: __init__.py プロジェクト: Forkk/notifico
def admin_user(username):
    do = request.args.get('do', None)
    u = User.by_username(username)
    if u is None:
        return abort(404)

    password_form = UserPasswordForm()

    if do == 'p' and password_form.validate_on_submit():
        u.set_password(password_form.password.data)
        g.db.session.commit()
        return redirect(url_for('.admin_user', username=username))

    return render_template(
        'admin_user.html',
        u=u,
        password_form=password_form
    )
コード例 #15
0
ファイル: __init__.py プロジェクト: whitequark/notifico
def register():
    """
    If new user registrations are enabled, provides a registration form
    and validation.
    """
    if g.user:
        return redirect(url_for('public.landing'))

    # Make sure this instance is allowing new users.
    if not current_app.config.get('NOTIFICO_NEW_USERS', True):
        return redirect(url_for('public.landing'))

    form = UserRegisterForm()
    if form.validate_on_submit():
        # Checks out, go ahead and create our new user.
        u = User.new(form.username.data, form.email.data, form.password.data)
        db.session.add(u)
        db.session.commit()
        # ... and send them back to the login screen.
        return redirect(url_for('.login'))

    return render_template('register.html', form=form)
コード例 #16
0
ファイル: __init__.py プロジェクト: Forkk/notifico
def register():
    """
    If new user registrations are enabled, provides a registration form
    and validation.
    """
    if g.user:
        return redirect(url_for('public.landing'))

    # Make sure this instance is allowing new users.
    if not current_app.config.get('PUBLIC_NEW_USERS', True):
        return redirect(url_for('public.landing'))

    form = UserRegisterForm()
    if form.validate_on_submit():
        # Checks out, go ahead and create our new user.
        u = User.new(form.username.data, form.email.data, form.password.data)
        g.db.session.add(u)
        g.db.session.commit()
        # ... and send them back to the login screen.
        return redirect(url_for('.login'))

    return render_template('register.html', form=form)
コード例 #17
0
ファイル: __init__.py プロジェクト: ammaraskar/notifico
 def validate_password(form, field):
     if not User.login(g.user.username, field.data):
         raise wtf.ValidationError('Password is incorrect.')
コード例 #18
0
ファイル: __init__.py プロジェクト: ammaraskar/notifico
 def validate_password(form, field):
     if not User.login(form.username.data, field.data):
         raise wtf.ValidationError('Incorrect username and/or password.')
コード例 #19
0
ファイル: __init__.py プロジェクト: ammaraskar/notifico
 def validate_username(form, field):
     username = field.data.strip().lower()
     if username in _reserved or User.username_exists(username):
         raise wtf.ValidationError(
             'Sorry, but that username is taken.'
         )
コード例 #20
0
ファイル: __init__.py プロジェクト: rom1504/notifico
 def validate_password(form, field):
     if not User.login(g.user.username, field.data):
         raise wtf.ValidationError('Your password is incorrect.')
コード例 #21
0
ファイル: forms.py プロジェクト: rom1504/notifico
    def validate_username(form, field):
        from notifico.views.account import _reserved

        username = field.data.strip().lower()
        if username in _reserved or User.username_exists(username):
            raise wtf.ValidationError('Sorry, but that username is taken.')
コード例 #22
0
ファイル: forms.py プロジェクト: rom1504/notifico
 def validate_password(form, field):
     if not User.login(form.username.data, field.data):
         raise wtf.ValidationError('Incorrect username and/or password.')