コード例 #1
0
ファイル: views.py プロジェクト: radiosilence/wire
def user_updates(username):
    u = User(redis=g.r)
    try:
        u.load_by_username(username)
    except UserNotFoundError:
        abort(404)

    if u.username in g.user.contacts:
        state = 'contact'
    else:
        state = 'nocontact'

    return render_template('timeline.html',
        timeline=u.posted.updates,
        user=u,
        state=state,
        title='%s' % username,
        disable_input=True)
コード例 #2
0
def user_updates(username):
    u = User(redis=g.r)
    try:
        u.load_by_username(username)
    except UserNotFoundError:
        abort(404)

    if u.username in g.user.contacts:
        state = 'contact'
    else:
        state = 'nocontact'

    return render_template('timeline.html',
                           timeline=u.posted.updates,
                           user=u,
                           state=state,
                           title='%s' % username,
                           disable_input=True)
コード例 #3
0
ファイル: utils.py プロジェクト: radiosilence/wire
    def attempt(self, username, password):
        from wire.models import User

        r = self.redis
        h = Hasher()
        if not r.exists('username:%s' % username):
            raise AuthError()

        key = r.get('username:%s' % username)
        data = json.loads(r.get('user:%s' % key))
        try:
            h.check(password, data['password'])
        except HashMismatch:
            raise AuthError()
        self.user = User(data=data, redis=r, key=key)
コード例 #4
0
ファイル: __init__.py プロジェクト: radiosilence/wire
def before_request():
    g.logged_in = False
    g.r = redis.Redis(host=current_app.config['REDIS_HOST'],
                      port=current_app.config['REDIS_PORT'],
                      db=current_app.config['REDIS_DB'])

    g.auth = Auth(g.r)
    g.user = User(redis=g.r)
    g.GMAPS_KEY = current_app.config['GMAPS_KEY']
    try:
        if session['logged_in']:
            g.logged_in = True
            g.user.load(session['logged_in'])
            g.inbox = Inbox(user=g.user, redis=g.r)
            g.unread_count = g.inbox.unread_count()
    except KeyError:
        pass
    except UserNotFoundError:
        from views import logout
        logout()
コード例 #5
0
def edit_user(new=False):
    if not new:
        try:
            g.user.username
        except AttributeError:
            abort(401)

    if new:
        u = User(redis=g.r)
    else:
        u = g.user
    if request.method == 'POST':
        u.update(request.form, new=new)

        try:
            avatar = request.files.get('avatar')
            if avatar:
                try:
                    u.avatar = upload_avatar(avatar)
                    flash("Upload successful.", 'success')
                except UploadNotAllowed:
                    flash("Upload not allowed.", 'error')
            u.save()
            if new:
                flash(
                    '"User "%s" created successfully. \
                    You may now log in.' % u.username, 'success')
                return redirect(url_for('frontend.intro'))
            else:
                flash('Profile updated.', 'success')
                return redirect(url_for('frontend.edit_user'))
        except UserValidationError:
            for error in u.validation_errors:
                flash(error, 'error')

    return render_template('forms/user.html', new=new, user=u)
コード例 #6
0
ファイル: views.py プロジェクト: radiosilence/wire
def edit_user(new=False):
    if not new:
        try:
            g.user.username
        except AttributeError:
            abort(401)

    if new:
        u = User(redis=g.r)
    else:
        u = g.user
    if request.method == 'POST':
        u.update(request.form, new=new)

        try:
            avatar = request.files.get('avatar')
            if avatar:
                try:
                    u.avatar = upload_avatar(avatar)
                    flash("Upload successful.", 'success')
                except UploadNotAllowed:
                    flash("Upload not allowed.", 'error')
            u.save()
            if new:
                flash('"User "%s" created successfully. \
                    You may now log in.' % u.username, 'success')
                return redirect(url_for('frontend.intro'))
            else:
                flash('Profile updated.', 'success')
                return redirect(url_for('frontend.edit_user'))
        except UserValidationError:
            for error in u.validation_errors:
                flash(error, 'error')

    return render_template('forms/user.html',
        new=new,
        user=u
    )