def reset_database(app): with app.app_context(): from database.models.general.customer import Customer from database.models.general.user import User from database.models.cloud.cloud_provider import CloudProvider from database.models.cloud.cloud_account import CloudAccount from uuid import uuid4 with open("data/initial_data.json") as fr: initial_data = json.loads(fr.read()) db.drop_all() db.create_all() for dcustomer in initial_data["customers"]: uid = str(uuid4()) customer = Customer(uid=uid,\ name=dcustomer["name"]) db.session.add(customer) db.session.commit() # This saves the last inserted customer_uid customer_uid = customer.uid for dcloud_provider in initial_data["cloud_providers"]: uid = str(uuid4()) cloud_provider = CloudProvider(uid=uid,\ name=dcloud_provider["name"], \ abbreviation=dcloud_provider["abbreviation"]) db.session.add(cloud_provider) db.session.commit() # This saves the last inserted cloud_provider_uid cloud_provider_uid = cloud_provider.uid for dcloud_account in initial_data["cloud_accounts"]: uid = str(uuid4()) # This takes customer_uid and cloud_provider_uid recently inserted cloud_account = CloudAccount(uid=uid, \ name=dcloud_account["name"], \ customer_uid=customer_uid, \ cloud_provider_uid=cloud_provider_uid) db.session.add(cloud_account) db.session.commit() hashing = Hashing() hashing_salt = initial_data["hashing_salt"] for dcloud_account in initial_data["users"]: hashed_password = hashing.hash_value(dcloud_account["password"], salt=hashing_salt) user = User(username=dcloud_account["username"], \ password=hashed_password, \ name=dcloud_account["name"]) db.session.add(user) db.session.commit()
class ImageSaver(): def __init__(self): self.hashing = Hashing() self.extensions = set(['png', 'jpg', 'jpeg']) def save_image(self, image, token, label=""): ''' Recieves an image from form, a user token and a label Returns a http response ''' if not self.check_extensions(image.filename): return Response("Not an exentsion supported", status=400) create_directory(path.join(app.config['UPLOAD_FOLDER'], label)) hashed_path = self.hashed_path(image, token, label) image.save(hashed_path) return Response("Created", status=201) def hashed_path(self, image, token, label=""): ''' Recieves an image object and a token Returns hashed path of object ''' filename = secure_filename(image.filename) hashed_name= self.hashing.hash_value(filename.split('.')[0], salt=token) \ +'.'+ filename.split('.')[1] return path.join(app.config['UPLOAD_FOLDER'], label, hashed_name) def check_extensions(self, filename): ''' Recieves a filename Returns if file has extension permited ''' return '.' in filename and \ filename.rsplit('.', 1)[1].lower() in self.extensions def delete_image(self, image_path): ''' Recieves a path of a file already hashed Returns True if file had deleted ''' if path.exists(image_path): remove(image_path) return True return False
def login(): if request.method == 'POST': details = request.form hashing = Hashing(app) username = details['username'] passwordhash = hashing.hash_value(details['password'], salt='rhino3d') cur = mysql.connection.cursor() query = "SELECT employeeid FROM dcip_employees WHERE employeeid = %s AND password = %s" param = (username, passwordhash) cur.execute(query, param) userdata = cur.fetchall() employeeid = '' for row in userdata: employeeid = row[0] if (len(employeeid) > 0): session['employeeid'] = employeeid return redirect(url_for('leaderboard')) else: return redirect(url_for('login')) else: return render_template('index.html', title='DCKAP Community Insider Program')
'For more info': "Visit support docs" }, 'ResourceDoesNotExist': { 'message': "A resource with that ID no longer exists.", 'status': 410, 'extra': "Any extra information you want.", }, } app = Flask(__name__) api = Api(app, errors=errors) salt = config.password #Set salt/key password = '******' hashing = Hashing(app) h = hashing.hash_value('password', salt) #Generate hash #Home page @app.route('/') def home(): #List of Countries coun = [ 'Morocco', 'Paraguay', 'Palau', 'Zimbabwe', 'El Salvador', 'Portugal', 'France', 'Japan', 'Mauritania', 'Sweden', 'Trinidad and Tobago', 'Uzbekistan', 'United Kingdom of Great Britain and Northern Ireland', 'Sri Lanka', 'Mauritius', 'Libya', 'Belarus', 'Saint Vincent and the Grenadines', 'Yemen', 'Uganda', 'Faroe Islands', 'Bhutan', 'Panama', 'Honduras', 'Bosnia and Herzegovina', 'Greenland', 'Azerbaijan', 'South Georgia and the South Sandwich Islands',
render_template, flash, Markup, send_file from flask_hashing import Hashing from werkzeug import secure_filename app = Flask(__name__) # create the application instance :) app.config.from_object(__name__) # load config from this file , flaskr.py hashing = Hashing(app) app.config['TRAP_BAD_REQUEST_ERRORS'] = True # Load default config and override config from an environment variable app.config.update(dict( DATABASE=os.path.join(app.root_path, 'flaskr.db'), SECRET_KEY='#####', USERNAME='******', #SUPERADMIN name PASSWORD= hashing.hash_value('####',salt='####'), #SUPERADMIN password ALLOWED_EXTENSIONS = set(['jpg', 'jpeg', 'png', 'pdf']), #Allowed extensions to store UPLOAD_FOLDER = '/var/www/html/family-sharer/static/home', IMAGE_ROOT = '/static/home/' )) app.config.from_envvar('FLASKR_SETTINGS', silent=True) os.chdir(app.config['UPLOAD_FOLDER']) ## Database function ## def connect_db(): """Connects to the specific database.""" rv = sqlite3.connect(app.config['DATABASE']) rv.row_factory = sqlite3.Row