示例#1
0
文件: Utils.py 项目: IsabelBou/Lammy
def get_user_from_username(username: str, ctx, strict=True):
    lowered = username.lower()
    for member in ctx.guild.members:
        if (strict and
            (member.name.lower() == lowered or
             (member.nick and member.nick.lower() == lowered))) or (
                 not strict and
                 (lowered in member.name.lower() or
                  (member.nick and lowered in member.nick.lower()))):
            return User(name=member.name, mention=member.mention)
    return User(name=username, mention=username)
示例#2
0
文件: Utils.py 项目: IsabelBou/Lammy
def getRole(guild_roles, assignment_role):
    guild_roles = guild_roles or list()
    for role in guild_roles:
        if str(assignment_role).lower() in (str(role.mention).lower(),
                                            str(role.id).lower(),
                                            str(role.name).lower()):
            return role
    return User(str(assignment_role), str(assignment_role))
示例#3
0
def get_user_from_id(user_id):
    session = db_session.create_session()
    login_data = session.query(UserLoginData).get(user_id)
    members_data = session.query(UserMemberData).get(user_id)
    if login_data is None or members_data is None:
        return None

    user = User(login_data.login,
                login_data.email,
                members_data.team_name,
                members_data.grade,

                (members_data.member1_name,
                 members_data.member1_surname,
                 members_data.member1_school),

                (members_data.member2_name,
                 members_data.member2_surname,
                 members_data.member2_school),

                (members_data.member3_name,
                 members_data.member3_surname,
                 members_data.member3_school),

                (members_data.member4_name,
                 members_data.member4_surname,
                 members_data.member4_school))

    user.id = login_data.id
    user.hashed_password = login_data.hashed_password
    user.is_banned = bool(login_data.is_banned)
    user.is_approved = bool(login_data.is_approved)

    return user
示例#4
0
 def post(self):
     parser.add_argument('email', type=str)
     parser.add_argument('password', type=str)
     data = parser.parse_args()
     current_user = User.get_user_by_email(self, data['email'])
     if not current_user:
         return {'message': 'Usuário não encontrado'}
     if self.verify_password(data['password'], current_user.password):
         access_token = create_access_token(identity=data['email'])
         refresh_token = create_refresh_token(identity=data['email'])
         return {
             'message': 'Usuário logado com sucesso',
             'access_token': access_token,
             'refresh_token': refresh_token
         }
     else:
         return {'message': 'Senha inválida'}
示例#5
0
def authorized():
	# check to make sure the user authorized the request
	if not 'code' in request.args:
		flash('You did not authorize the request')
		return redirect(url_for('index'))
	# make a request for the access token credentials using code
	redirect_uri = url_for('authorized', _external=True)
	data={'code':request.args['code'], 'redirect_uri':redirect_uri
		,'grant_type':'authorization_code'}
	session = linkedin.get_auth_session(data=data, decoder=json.loads)
	r = session.get('people/~',params={'format': 'json'}).content
	userid=json.loads(r)['id']

	user = User.query.filter_by(uid=userid).first()
	if user == None:
		tmp=session.get('people/id='+userid+\
		':(first-name,last-name,headline,picture-url,positions)',params={'format': 'json'}).content
		tmpx=json.loads(tmp)
		username=tmpx['firstName']+" "+tmpx['lastName']
		headline=tmpx['headline']
		pic=tmpx['pictureUrl']
		company =parsecompany(tmpx['positions'])
		a=User(userid,username,pic,None,None,headline,company,None)
		db.session.add(a)
		db.session.commit()
		uu ={  	 'user_id'		:userid
				,'user_name'	:username
				,'template_id'	:None
				,'photo_url'	:pic
				,'email'		:None
				,'headline'		:headline
				,'company'		:company
				,'linkedin_add'	:None
			}
		data = { 'user': uu
				,'friends':{}
				,'exist':False
			}		
		print data
	else:
		data = getuserdata(user)
	return jsonify(data=data)
示例#6
0
#scraper.py

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from config import User
import time

driver = webdriver.Firefox()
driver.get("http://icloud.com")
user = User()
username = user.username
password = user.password
time.sleep(10)
element = driver.find_element_by_id('account_name_text_field')
element.send_keys(username)
示例#7
0
    def post(self):
        parser.add_argument('name', type=str)
        parser.add_argument('last_name', type=str)
        parser.add_argument('email', type=str)
        parser.add_argument('password', type=str)
        data = parser.parse_args()

        already_exists = User.get_user_by_email(self, data['email'])
        if already_exists:
            return {'message': 'Usuário já existe'}, 400

        new_user = User()
        new_user.public_id = 100
        new_user.name = data['name']
        new_user.last_name = data['last_name']
        new_user.email = data['email']
        new_user.password = pwd_context.encrypt(data['password'])
        new_user.admin = False

        try:
            User.save(new_user)
            return {'message': 'Usuário criado'}
        except Exception as e:
            print(str(e))
            return {'message': 'Ocorreu um erro'}, 500