コード例 #1
0
ファイル: views.py プロジェクト: zzznn/Flask-INnoVation
def follow(username):
    user = MongoClient().blog.User.find_one({'username': username})
    if user is None:
        flash('此用户不存在.')
        return redirect(url_for('.index'))
    very = False
    temp = MongoClient().blog.User.find_one({
        'username': current_user.username
    }).get('following')
    for i in range(temp.__len__()):
        if temp[i][0] == username:
            very = True
            break
    if very:
        flash('您已经关注过了他,不能重复关注.')
        return redirect(url_for('.user', username=username))
    followers = user.get('followers')
    time = datetime.utcnow()
    follow = [current_user.username, time]
    followers.append(follow)
    MongoClient().blog.User.update({'username': username},
                                   {'$set': {
                                       'followers': followers
                                   }})
    post2 = MongoClient().blog.User.find_one(
        {'username': current_user.username})
    following = post2.get('following')
    follow = [user.get('username'), time]
    following.append(follow)
    MongoClient().blog.User.update({'username': current_user.username},
                                   {'$set': {
                                       'following': following
                                   }})
    flash('您成功关注了 %s.' % username)
    return redirect(url_for('.user', username=username))
コード例 #2
0
def signin():
    if current_user is not None and current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm(request.form)
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None:
            form.email.errors.append('User does not exist')
            return render_template('signin.html', signinpage_form=form)
        if user.password != hash_password(form.password.data):
            return render_template('signin.html', signinpage_form=form)
        login_user(user, remember=form.remember_me.data)
        session['signed'] = True
        session['username'] = user.username
        if session.get('next'):
            next_page = session.get('next')
            session.pop('next')
            return redirect(next_page)
        else:
            return redirect(url_for('index'))
    else:
        session['next'] = request.args.get('next')
        return render_template('signin.html',
                               signinpage_form=LoginForm(),
                               page_title='this is Login route')
コード例 #3
0
ファイル: views.py プロジェクト: zzznn/Flask-INnoVation
def post(id):
    post = MongoClient().blog.Aritical.find({'_id': ObjectId(id)})
    form = CommentForm()
    if form.validate_on_submit():
        comments = post[0].get('comments')
        body = form.body.data
        comments.append([body, current_user.username, datetime.utcnow()])
        MongoClient().blog.Aritical.update({'_id': ObjectId(id)},
                                           {'$set': {
                                               'comments': comments
                                           }})
        flash('评论发布成功.')
        return redirect(url_for('.post', id=id, page=-1))
    page = request.args.get('page', 1, type=int)
    pagination = PaginateComments(page, id)
    comments = pagination.items
    comment = (post[0].get('username') != current_user.username)
    return render_template('post.html',
                           posts=post,
                           form=form,
                           i=0,
                           comments=comments,
                           pagination=pagination,
                           author=comment,
                           id=id)
コード例 #4
0
ファイル: views.py プロジェクト: zzznn/Flask-INnoVation
def edit_profile_admin(id):
    user = MongoClient().blog.User.find_one({'_id': ObjectId(id)})
    if user is None:
        return abort(404)
    user_temp = Temp(id=user.get('_id'),
                     username=user.get('username'),
                     email=user.get('email'),
                     password=user.get('password'),
                     activate=user.get('activate'),
                     role=user.get('role'),
                     name=user.get('name'),
                     location=user.get('location'),
                     about_me=user.get('about_me'),
                     last_since=user.get('last_since'),
                     member_since=user.get('member_since'))
    form = EditProfileAdminForm(user=user_temp)
    if form.validate_on_submit():
        MongoClient().blog.User.update({'email': user_temp.email},
                                       {'$set': {
                                           'name': form.name.data
                                       }})
        MongoClient().blog.User.update(
            {'email': user_temp.email},
            {'$set': {
                'username': form.username.data
            }})
        MongoClient().blog.User.update({'email': user_temp.email},
                                       {'$set': {
                                           'email': form.email.data
                                       }})
        MongoClient().blog.User.update(
            {'email': user_temp.email},
            {'$set': {
                'activate': form.activate.data
            }})
        MongoClient().blog.User.update({'email': user_temp.email},
                                       {'$set': {
                                           'role': form.role.data
                                       }})
        MongoClient().blog.User.update(
            {'email': user_temp.email},
            {'$set': {
                'location': form.location.data
            }})
        MongoClient().blog.User.update(
            {'email': user_temp.email},
            {'$set': {
                'about_me': form.about_me.data
            }})
        flash('The profile has been updated.')
        return redirect(url_for('.user', username=user_temp.username))
    form.email.data = user_temp.email
    form.username.data = user_temp.username
    form.activate.data = user_temp.activate
    form.role.data = user_temp.role.name
    form.name.data = user_temp.name
    form.location.data = user_temp.location
    form.about_me.data = user_temp.about_me
    return render_template('edit_profile.html', form=form, user=user_temp)
コード例 #5
0
ファイル: main.py プロジェクト: amiramen/InviteUs
def facebook_authorized(resp):
    next_url = flask_login.request.args.get('next') or url_for('root')
    if resp is None:
        # The user likely denied the request
        flask_login.flash(u'There was a problem logging in.')
        return flask_login.redirect(next_url)
    flask_login.session['oauth_token'] = (resp['access_token'], '')
    user_data = facebook.get('/me').data
    user = User.query.filter(User.email == user_data['email']).first()
    if user is None:
        new_user = User(email=user_data['email'],
                        first_name=user_data['first_name'],
                        last_name=user_data['last_name'])
        db_session.add(new_user)
        db_session.commit()
        flask_login.login_user(new_user)
    else:
        flask_login.login_user(user)
    return flask_login.redirect(next_url)
コード例 #6
0
def account_createtable():
    form = CreateTableForm(request.form)
    if form.validate():
        tableid = DB.add_table(form.tablenumber.data, current_user.get_id())
        new_url = BH.shorten_url(config.base_url + "newrequest/" + tableid)
        DB.update_table(tableid, new_url)
        return redirect(url_for('account'))

    return render_template("account.html",
                           createtableform=form,
                           tables=DB.get_tables(current_user.get_id()))
コード例 #7
0
ファイル: views.py プロジェクト: zzznn/Flask-INnoVation
def unfollow(username):
    user = MongoClient().blog.User.find_one({'username': username})
    if user is None:
        flash('此用户不存在.')
        return redirect(url_for('.index'))
    very = False
    temp = MongoClient().blog.User.find_one({
        'username': current_user.username
    }).get('following')
    for i in range(temp.__len__()):
        if temp[i][0] == username:
            very = True
            break
    if not very:
        flash('您没有关注这个用户.')
        return redirect(url_for('.user', username=username))
    followers = user.get('followers')
    for i in range(followers.__len__()):
        if followers[i][0] == current_user.username:
            followers.remove(followers[i])
            break
    MongoClient().blog.User.update({'username': username},
                                   {'$set': {
                                       'followers': followers
                                   }})
    post2 = MongoClient().blog.User.find_one(
        {'username': current_user.username})
    following = post2.get('following')
    for i in range(following.__len__()):
        if following[i][0] == username:
            following.remove(following[i])
            break
    MongoClient().blog.User.update({'username': current_user.username},
                                   {'$set': {
                                       'following': following
                                   }})
    flash('您取消关注了 %s.' % username)
    return redirect(url_for('.user', username=username))
コード例 #8
0
def login():
    form = LoginForm(request.form)
    if form.validate():
        stored_user = DB.get_user(form.loginemail.data)
        if stored_user and PH.validate_password(form.loginpassword.data,
                                                stored_user['salt'],
                                                stored_user['hashed']):
            user = User(form.loginemail.data)
            login_user(user, remember=True)
            return redirect(url_for('account'))
        form.loginemail.errors.append("Email or password invalid")
    return render_template("home.html",
                           loginform=form,
                           registrationform=RegistrationForm())
コード例 #9
0
def signin():
    if current_user is not None and current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm(request.form)
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None:
            form.email.errors.append('User does not exist')
            return render_template('signin.html', signinpage_form=form)
        if user.password != hash_password(form.password.data):
            return render_template('signin.html', signinpage_form=form)
        login_user(user, remember=form.remember_me.data)
        session['signed'] = True
        session['username'] = user.username
        if session.get('next'):
            next_page = session.get('next')
            session.pop('next')
            return redirect(next_page)
        else:
            return redirect(url_for('index'))
    else:
        session['next'] = request.args.get('next')
        return render_template('signin.html', signinpage_form=LoginForm(),
                               page_title='this is Login route')
コード例 #10
0
ファイル: views.py プロジェクト: zzznn/Flask-INnoVation
def following(username):
    user = MongoClient().blog.User.find_one({'username': username})
    if user is None:
        flash('此用户不存在.')
        return redirect(url_for('.index'))
    page = request.args.get('page', 1, type=int)
    pagination = PaginateFollowing(page=page, username=username)
    follows = pagination.item
    return render_template('followers.html',
                           user=user,
                           title='关注的人',
                           title1='',
                           title2='关注的人',
                           endpoint='.following',
                           pagination=pagination,
                           follows=follows)
コード例 #11
0
ファイル: views.py プロジェクト: zzznn/Flask-INnoVation
def edit(id):
    post = MongoClient().blog.Aritical.find_one({'_id': ObjectId(id)})
    if current_user.id != post.get('user_id') and \
            not current_user.can(Permission.ADMINISTER):
        abort(403)
    form = EditPostForm()
    if form.validate_on_submit():
        MongoClient().blog.Aritical.update({'_id': ObjectId(id)}, {
            '$set': {
                'body': form.body.data,
                'body_html': body_html(form.body.data)
            }
        })
        flash('修改成功')
        return redirect(url_for('.post', id=post.get('_id')))
    form.body.data = post.get('body')
    return render_template('edit_post.html', form=form)
コード例 #12
0
ファイル: views.py プロジェクト: zzznn/Flask-INnoVation
def delete(id):
    user = MongoClient().blog.Aritical.find({'_id': ObjectId(id)})
    if not current_user.username == user[0].get(
            'username') and not current_user.is_administrator():
        abort(304)
    timedata = request.args.get('data')
    comments = user[0].get('comments')
    for i in range(comments.__len__()):
        time = str(comments[i][2])
        if time == timedata:
            del comments[i]
            break
    MongoClient().blog.Aritical.update({'_id': ObjectId(id)},
                                       {'$set': {
                                           'comments': comments
                                       }})
    return redirect(url_for('.post', id=id))
コード例 #13
0
ファイル: views.py プロジェクト: zzznn/Flask-INnoVation
def index():
    form = PostForm()
    if current_user.can(Permission.WRITE_ARTICLES) and \
            form.validate_on_submit():
        Post(body=form.body.data).new_article()
        return redirect(url_for('.index'))
    page = request.args.get('page', 1, type=int)
    show_followed = False
    if current_user.is_authenticated:
        show_followed = bool(request.cookies.get('show_followed', ''))
    if show_followed:
        pagination = Paginate(page, 1)
    else:
        pagination = Paginate(page, 0)
    posts = pagination.item
    return render_template('index.html',
                           form=form,
                           posts=posts,
                           pagination=pagination,
                           show_followed=show_followed)
コード例 #14
0
ファイル: tools.py プロジェクト: LordBH/Cupcake
def get_rooms(user):
    from models.models import ActivatedUsers, session

    q = ActivatedUsers.query.filter_by(user_id=user).first()

    if q is None:
        from flask_login import redirect, url_for

        del session['user_active']
        return redirect(url_for('main.index_page'))

    if q.rooms is not None:

        arr = q.rooms.split('/')

        s = []

        for x in arr:
            if x:
                s.append(x)

        session['rooms'] = s
コード例 #15
0
def signout():
    session.pop('username')
    session.pop('signed')
    logout_user()
    return redirect(url_for('index'))
コード例 #16
0
def account_deletetable():
    tableid = request.args.get("tableid")
    DB.delete_table(tableid)
    return redirect(url_for('account'))
コード例 #17
0
ファイル: logout.py プロジェクト: andrewjli/MakeItHappen
def logout():
    if current_user.is_authenticated():
        logout_user()
    return redirect('/')
コード例 #18
0
def dashboard_resolve():
    request_id = request.args.get("request_id")
    DB.delete_request(request_id)
    return redirect(url_for('dashboard'))
コード例 #19
0
ファイル: views.py プロジェクト: zzznn/Flask-INnoVation
def show_followed():
    resp = make_response(redirect(url_for('.index')))
    resp.set_cookie('show_followed', '1', max_age=30 * 24 * 60 * 60)
    return resp
コード例 #20
0
def logout():
    logout_user()
    return redirect(url_for("home"))
コード例 #21
0
ファイル: manage.py プロジェクト: wu-wenxiang/abbyBlog
def before_request():
    if not (current_user.is_authenticated and current_user.admin):
        return redirect(url_for('home.signin'))
コード例 #22
0
ファイル: auth.py プロジェクト: elerion/atrium
def unauthorized():
    return redirect(url_for('login', next=request.path))
コード例 #23
0
ファイル: logout.py プロジェクト: andrewjli/MakeItHappen
def logout():
    if current_user.is_authenticated():
        logout_user()
    return redirect('/')
コード例 #24
0
def signout():
    session.pop('username')
    session.pop('signed')
    logout_user()
    return redirect(url_for('index'))