view.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:Feature-Request-Python-Flask 作者: jmcgrath207 项目源码 文件源码
def Index():
    """Login portal for clients"""

    if current_user.is_authenticated:
            """If client is authenticated, return them back to their portal case view"""
            return render_template("Client_View.html",title='client_view',
                           Client_id=current_user.Client_id,api_key= current_user.api_key)
    form = LoginForm()
    if (request.method == 'POST') and (form.validate_on_submit()):
        Client_id = form.Client_id.data
        Password = form.Password.data
        user = User.query.filter_by(Client_id=Client_id).first()
        if not user and app.config['NO_PASSWORD'] == True:
            """Allow anyone to create their own account"""
            pass_hash = bcrypt_sha256.encrypt(Password, rounds=12)
            user = User(Client_id= Client_id,Password= pass_hash,api_key='')
            Sample_date = Client_View(client_id = Client_id,
                                         case_name= 'sample case',
                                         priority= '1',
                                         target_date = '10/7/2016',
                                         product_area = 'Engineering',
                                          status = 'In Progress',
                                         description= 'something'
                                         )
            db.session.add(user)
            db.session.commit()
            db.session.add(Sample_date)
            db.session.commit()
        """ If user is a vaild account, proceed with verifying \
        their credentials and provide them the API key"""
        if user:
            if bcrypt_sha256.verify(Password, user.Password) and user.Client_id == Client_id:
                signer = TimestampSigner(SECRET_KEY)
                API_KEY = ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(30)])
                user.api_key = signer.sign(API_KEY)
                user.current_login_ip = request.remote_addr
                db.session.commit()
                login_user(user)
                flash('You have successfully logged in')
                return render_template("Client_View.html",title='client_view',
                                   Client_id=Client_id,api_key= user.api_key)
        if form.errors:
            flash(form.errors, 'danger')
        flash('Incorrect Credentials, please enter the correct Client Id and Password')
        return render_template('Index.html', form=form)
    if form.errors:
        flash(form.errors, 'danger')
    return render_template('Index.html', form=form)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号