# home
# dashboard
from flask import Blueprint, render_template, Flask, flash, redirect, request, session, abort
from flask_assets import Environment, Bundle
from pymongo import MongoClient
from pymongo.collation import Collation
import os

app = Flask(__name__)

# Bank settings 
client = MongoClient('mongodb://root:r00t123@ds259001.mlab.com/weed',59001)
db = client.weed


adm = Blueprint('adm', __name__,template_folder='template')

@adm.route('/likes/', methods=['GET'])
def like():
	if session.get('logged_in'):
		url = request.args.get('url')
		de = request.args.get('de')
		para = request.args.get('para')

		like = db['Images']
		imgFogo=like.find_one({'url' : request.args.get('url')})
		alteracao = imgFogo.updateOne({'likes': de}, {'likes': para})
		return "deu certo"
	else:
		return "wtf"

@adm.route('/api/login/', methods=['GET'])
def do_admin_login():
	users = db['users']
	try:    
		login_user=users.find_one({'name' : request.args.get('username')})
		if request.args.get('password') == login_user['password']:
			session['logged_in'] = True
			#→ Response 200... ok
			return "Eae man"
		else:
			return abort(403)
   		#→ Response 403... Forbidden
	except:
		return abort(403)
