Ejemplo n.º 1
0
def user_t():
    code = request.args.get('code')
    print(code)
    config = fenixedu.FenixEduConfiguration(
        '288540197912648', 'http://127.0.0.1:5000/user',
        'pLVnCmMd0XL72gufsbkG76bMX+wF33C49X9FqkkPw/QE+mCyXUzLARSbpcmFqCUmEIycTfjkDtSYhe2nO1a+9w==',
        'https://fenix.tecnico.ulisboa.pt/')
    client = fenixedu.FenixEduClient(config)

    user = client.get_user_by_code(code)
    person = client.get_person(user)

    #print(user.access_token)
    print(person['username'])
    print(person['name'])
    #session['access_token'] = user.access_token
    #session['username'] = data['username']

    #return redirect(url_for('index'))
    #if not person['username']) in users_sys:

    #return render_template("user1.html", UserID=person['username'])
    #userID = person['username'], Username = person['name'])
    #Secundário atribuidor de ID Ajudante
    if (1):
        for x in range(1):
            aux = random.randint(1, 101)
    return render_template("user1.html", UserID=aux)
Ejemplo n.º 2
0
def callback():
    config = fenixedu.FenixEduConfiguration.fromConfigFile('fenixedu.ini')
    client = fenixedu.FenixEduClient(config)
    base_url = 'https://fenix.tecnico.ulisboa.pt/'
    app.secret_key = 'SfPsJpv6wJTod6avb03fIjOKrzAMqH2H8gCyWklysIXU46CblYpcIdTZ6QNZLoAv1FX4JWgqGM2ed3Gp9jMoGw=='
    client_id = '1414440104755257'

    tokencode = request.args.get('code')

    fenixuser = client.get_user_by_code(tokencode)
    person = client.get_person(fenixuser)

    username = person['username']

    token = fenixuser.access_token
    session['access_token'] = token
    session['username'] = username

    #escreve username-token na memcache REDIS, expirando depois de 10 minutos
    redis_client.set(username, token, 600)

    if (not checkToken(session['access_token'], session['username'])):
        authorization_url = 'https://fenix.tecnico.ulisboa.pt/oauth/userdialog?client_id=1414440104755257&redirect_uri=https://asint-227116.appspot.com/callback'
        return redirect(authorization_url)

    resp = make_response(redirect(url_for('index')))
    resp.set_cookie('username', username,
                    secure=True)  #accessible in javascript
    return resp
Ejemplo n.º 3
0
def login():
    config = fenixedu.FenixEduConfiguration(
        '288540197912648', 'http://127.0.0.1:5000/user',
        'pLVnCmMd0XL72gufsbkG76bMX+wF33C49X9FqkkPw/QE+mCyXUzLARSbpcmFqCUmEIycTfjkDtSYhe2nO1a+9w==',
        'https://fenix.tecnico.ulisboa.pt/')
    client = fenixedu.FenixEduClient(config)
    url = client.get_authentication_url()
    return url
Ejemplo n.º 4
0
 def call(self):
     try:
         config = fenixedu.FenixEduConfiguration.fromConfigFile(
             self.fenix_config_file)
         client = fenixedu.FenixEduClient(config)
         return client
     except Exception as e:
         logger.error(e)
Ejemplo n.º 5
0
    def __init__(self):
        config = fenixedu.FenixEduConfiguration.fromConfigFile('fenixedu.ini')

        self.client = fenixedu.FenixEduClient(config)
        self.year = datetime.now().hour

        url = self.client.get_authentication_url()

        webbrowser.open_new(url)

        code = input(
            "please insert the code that is presented to you on the browser:")
        self.user = self.client.get_user_by_code(code)
Ejemplo n.º 6
0
def index():
    config = fenixedu.FenixEduConfiguration.fromConfigFile('setup.ini')
    client = fenixedu.FenixEduClient(config)
    code = request.args["code"]
    user = client.get_user_by_code(code)
    person = client.get_person(user)
    username = person['username']
    token = user.access_token
    radious = obj_userDB.update_user(username)
    return render_template("mainPage.html",
                           user_id=username,
                           token=token,
                           radious=radious)
Ejemplo n.º 7
0
Archivo: main.py Proyecto: mabr3/ASINT
def main_user():
    #  Needed again
    config = fenixedu.FenixEduConfiguration.fromConfigFile('fenixedu.ini')
    client = fenixedu.FenixEduClient(config)
    try:
        code = request.args['code']
    except KeyError:
        abort(400)

    user_ = client.get_user_by_code(code)
    person = client.get_person(user_)
    displayName = person['displayName']
    username = person['username']

    i = find_index(UsersOn, 'username', username)
    if i == -1:
        UsersOn.append({
            "username": username,
            "name": displayName,
            "user": user_,
            "range": 30,
            "a_token": user_.access_token,
            "count": 1,
            "building": None,
            "campus": None,
            "location": None
        })
    else:
        # Primeiro fazer o checkout da sessão que estava activa
        collection = db['logs']
        collection.update_one(
            {
                "type": "move",
                "checkout": "0",
                "user": username
            }, {"$set": {
                "checkout": str(datetime.datetime.now())
            }})
        # Atualizar o user no UsersOn
        UsersOn[i]['user'] = user_
        UsersOn[i]['a_token'] = user_.access_token
        UsersOn[i]['count'] += 1

    session['code'] = code
    session['username'] = username
    session['name'] = displayName
    session['logged_in'] = True
    session['a_token'] = user_.access_token

    return redirect(url_for('MainpageDone'))
Ejemplo n.º 8
0
from builds import Building
from user import User
import range
from importCampee import ImportCampee
import pickle
import utils
from message import Message
from flask_cors import CORS
import fenixedu
import bmemcached
import os
import pymysql
from datetime import datetime

config = fenixedu.FenixEduConfiguration.fromConfigFile('fenixedu.ini')
client = fenixedu.FenixEduClient(config)

base_url = 'https://fenix.tecnico.ulisboa.pt/'

db_user = os.environ.get('CLOUD_SQL_USERNAME')
db_password = os.environ.get('CLOUD_SQL_PASSWORD')
db_name = os.environ.get('CLOUD_SQL_DATABASE_NAME')
db_connection_name = os.environ.get('CLOUD_SQL_CONNECTION_NAME')

app = Flask(__name__)
app.config['SESSION_COOKIE_SECURE'] = True
app.config['REMEMBER_COOKIE_SECURE'] = True
CORS(app)

redis_client = bmemcached.Client(
    'memcached-18466.c3.eu-west-1-1.ec2.cloud.redislabs.com:18466', 'mc-KBY4m',
Ejemplo n.º 9
0
Archivo: main.py Proyecto: mabr3/ASINT
def login_fenix():
    #  Fenix
    config = fenixedu.FenixEduConfiguration.fromConfigFile('fenixedu.ini')
    client = fenixedu.FenixEduClient(config)
    url = client.get_authentication_url()
    return redirect(url, code=302)
Ejemplo n.º 10
0
# Utils
from datetime import datetime
import csv
import os
from django.core import serializers

# Custom modules
from . import constants
from . import utils
from . import forms
from . import name_service

import fenixedu

config = fenixedu.FenixEduConfiguration.fromConfigFile()
fenixAPI = fenixedu.FenixEduClient(config)

##################
# Public views
##################

# Entry point
def index(request):
	url = fenixAPI.get_authentication_url()
	code = request.GET.get('code', None)

	if code is not None and not request.user.is_authenticated():
		utils.authenticate_by_fenixedu_code(request, fenixAPI, code)

	context = {'auth_url' : url, 'is_department_member' : 'is_department_member' in request.session,
			'is_scientific_council_member' : 'is_scientific_council_member' in request.session}
Ejemplo n.º 11
0
def login():
    config = fenixedu.FenixEduConfiguration.fromConfigFile('setup.ini')
    client = fenixedu.FenixEduClient(config)
    url = client.get_authentication_url()
    return redirect(url)