Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- This is the admin dashboard for SwitchCaseHub, and the purpose of this dashboard is for admins to easily manage users and projects
- """
- # Project Name: SwitchCaseHub Admin
- # Project Description: Handle users for SwitchCaseHub
- # File for handling view
- #import all necessary files
- import os
- import ast
- import json
- import requests
- import jwt
- from flask import Blueprint,request,url_for,current_app, render_template, session, redirect, url_for
- from flask_json import json_response
- from model import Contact
- from utils import validate_
- from extensions import db
- web_view = Blueprint('web_view', __name__)#create a blueprint structure of the flask class
- is_next_link = 1;
- msgs = [];
- def validate_jwt_identity_token(token):
- """This Function is used to verify jwt tokens that re used as a replacment for sessions,
- especially for the web """
- try:
- key = current_app.config['JWT_SESSIONS']
- decoded=jwt.decode(token, key, algorithms=['HS256'])
- print decoded
- if decoded['name'] and decoded['email'] and decoded['mobile'] and decoded['account_level']:
- return decoded['name'],decoded['email'],decoded['mobile'], decoded['account_level']
- except Exception,e:
- print e
- return False
- @web_view.route("/<string:token>")
- def home_page(token):
- print token
- #validate jwt tokens.... and get all the data needed
- tok = validate_jwt_identity_token(token)
- if tok != False:
- return render_template("master.html",user={"fullname" : tok[0],"token" : token})
- else:
- return redirect(url_for("web_view.login_page"))
- def load_contact_msgs(page=1):
- """this function is used to fetch contact pages from d db"""
- contact = Contact.query.order_by(Contact.id.desc()).paginate(page,10,error_out=False).items
- return contact
- @web_view.route("/mail/<string:token>")
- def contact__msg_page(token):
- print token
- #validate jwt tokens.... and get all the data needed
- tok = validate_jwt_identity_token(token)
- next_contact_page = is_next_link
- is_next = request.args.get('next') or None
- if tok != False:
- #get contact us messages and populate the file
- if is_next is not None:
- print "gtt"
- contact_msgs = load_contact_msgs(next_contact_page)
- for contact_msg in contact_msgs:
- contact_msg.message = contact_msg.message.replace("\n","<br>")
- msgs.append(contact_msg)
- print contact_msg.message
- return render_template("mail.html",user={"fullname" : tok[0],"token" : token}, messages = msgs, num_id = "")
- else:
- is_next = None;
- is_next_link = 1;
- contact_msgs = load_contact_msgs(next_contact_page)
- for contact_msg in contact_msgs:
- contact_msg.message = contact_msg.message.replace("\n","<br>")
- msgs.append(contact_msg)
- print contact_msg.message
- return render_template("mail.html",user={"fullname" : tok[0],"token" : token}, messages = msgs, num_id = is_next_link)
- else:
- return redirect(url_for("web_view.login_page",next_page="web_view.contact__msg_page"))
- @web_view.route("/login")
- def login_page():
- next_page = request.args.get('next_page') or "web_view.home_page"
- print next_page
- return render_template("signin.html",email = "", password = "", next_page = next_page)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement